Skip to content

Commit e14ab30

Browse files
committed
drm/ast: Allocate instance of struct ast_i2c_chan with managed helpers
Replace kzalloc() with drmm_kzalloc() and thereby put the release of the I2C instance into a separate action. Avoids explicit error roll- back in ast_i2c_chan_create(). No functional changes. Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de> Reviewed-by: Sui Jingfeng <sui.jingfeng@linux.dev> Reviewed-by: Jocelyn Falempe <jfalempe@redhat.com> Link: https://patchwork.freedesktop.org/patch/msgid/20240325200855.21150-5-tzimmermann@suse.de
1 parent c0af492 commit e14ab30

1 file changed

Lines changed: 2 additions & 7 deletions

File tree

drivers/gpu/drm/ast/ast_i2c.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,14 @@ static void ast_i2c_release(struct drm_device *dev, void *res)
107107
struct ast_i2c_chan *i2c = res;
108108

109109
i2c_del_adapter(&i2c->adapter);
110-
kfree(i2c);
111110
}
112111

113112
struct ast_i2c_chan *ast_i2c_create(struct drm_device *dev)
114113
{
115114
struct ast_i2c_chan *i2c;
116115
int ret;
117116

118-
i2c = kzalloc(sizeof(struct ast_i2c_chan), GFP_KERNEL);
117+
i2c = drmm_kzalloc(dev->dev, sizeof(*i2c), GFP_KERNEL);
119118
if (!i2c)
120119
return ERR_PTR(-ENOMEM);
121120

@@ -137,16 +136,12 @@ struct ast_i2c_chan *ast_i2c_create(struct drm_device *dev)
137136
ret = i2c_bit_add_bus(&i2c->adapter);
138137
if (ret) {
139138
drm_err(dev, "Failed to register bit i2c\n");
140-
goto out_kfree;
139+
return ERR_PTR(ret);
141140
}
142141

143142
ret = drmm_add_action_or_reset(dev, ast_i2c_release, i2c);
144143
if (ret)
145144
return ERR_PTR(ret);
146145

147146
return i2c;
148-
149-
out_kfree:
150-
kfree(i2c);
151-
return ERR_PTR(ret);
152147
}

0 commit comments

Comments
 (0)