drm/ast: Allocate instance of struct ast_i2c_chan with managed helpers
authorThomas Zimmermann <tzimmermann@suse.de>
Mon, 25 Mar 2024 20:06:49 +0000 (21:06 +0100)
committerThomas Zimmermann <tzimmermann@suse.de>
Tue, 2 Apr 2024 08:40:46 +0000 (10:40 +0200)
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
drivers/gpu/drm/ast/ast_i2c.c

index c3046223a49194de09a834e8b0b9d6a09698899f..dc28a5cbb1c2a60d4d199a4cabb9bf10c0bfacb8 100644 (file)
@@ -107,7 +107,6 @@ static void ast_i2c_release(struct drm_device *dev, void *res)
        struct ast_i2c_chan *i2c = res;
 
        i2c_del_adapter(&i2c->adapter);
-       kfree(i2c);
 }
 
 struct ast_i2c_chan *ast_i2c_create(struct drm_device *dev)
@@ -115,7 +114,7 @@ struct ast_i2c_chan *ast_i2c_create(struct drm_device *dev)
        struct ast_i2c_chan *i2c;
        int ret;
 
-       i2c = kzalloc(sizeof(struct ast_i2c_chan), GFP_KERNEL);
+       i2c = drmm_kzalloc(dev->dev, sizeof(*i2c), GFP_KERNEL);
        if (!i2c)
                return ERR_PTR(-ENOMEM);
 
@@ -137,7 +136,7 @@ struct ast_i2c_chan *ast_i2c_create(struct drm_device *dev)
        ret = i2c_bit_add_bus(&i2c->adapter);
        if (ret) {
                drm_err(dev, "Failed to register bit i2c\n");
-               goto out_kfree;
+               return ERR_PTR(ret);
        }
 
        ret = drmm_add_action_or_reset(dev, ast_i2c_release, i2c);
@@ -145,8 +144,4 @@ struct ast_i2c_chan *ast_i2c_create(struct drm_device *dev)
                return ERR_PTR(ret);
 
        return i2c;
-
-out_kfree:
-       kfree(i2c);
-       return ERR_PTR(ret);
 }