diff options
author | Thomas Zimmermann <tzimmermann@suse.de> | 2022-05-16 15:43:40 +0200 |
---|---|---|
committer | Thomas Zimmermann <tzimmermann@suse.de> | 2022-05-17 20:23:48 +0200 |
commit | b279df242972ae816a75cf1cc732af836f999100 (patch) | |
tree | a12afd8574bc5fd78d2970abf378e14b2e89893b /drivers/gpu/drm/mgag200/mgag200_i2c.c | |
parent | drm/mgag200: Implement connector's get_modes with helper (diff) | |
download | linux-b279df242972ae816a75cf1cc732af836f999100.tar.xz linux-b279df242972ae816a75cf1cc732af836f999100.zip |
drm/mgag200: Switch I2C code to managed cleanup
Store the I2C state within struct mga_device and switch I2C to
managed release. Simplifies the related code and lets us remove
mga_connector_destroy().
Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: Jocelyn Falempe <jfalempe@redhat.com>
Tested-by: Jocelyn Falempe <jfalempe@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20220516134343.6085-5-tzimmermann@suse.de
Diffstat (limited to 'drivers/gpu/drm/mgag200/mgag200_i2c.c')
-rw-r--r-- | drivers/gpu/drm/mgag200/mgag200_i2c.c | 33 |
1 files changed, 11 insertions, 22 deletions
diff --git a/drivers/gpu/drm/mgag200/mgag200_i2c.c b/drivers/gpu/drm/mgag200/mgag200_i2c.c index 31e2c641a781..f57b33917152 100644 --- a/drivers/gpu/drm/mgag200/mgag200_i2c.c +++ b/drivers/gpu/drm/mgag200/mgag200_i2c.c @@ -86,10 +86,16 @@ static int mga_gpio_getscl(void *data) return (mga_i2c_read_gpio(mdev) & i2c->clock) ? 1 : 0; } -struct mga_i2c_chan *mgag200_i2c_create(struct drm_device *dev) +static void mgag200_i2c_release(void *res) { - struct mga_device *mdev = to_mga_device(dev); - struct mga_i2c_chan *i2c; + struct mga_i2c_chan *i2c = res; + + i2c_del_adapter(&i2c->adapter); +} + +int mgag200_i2c_init(struct mga_device *mdev, struct mga_i2c_chan *i2c) +{ + struct drm_device *dev = &mdev->base; int ret; int data, clock; @@ -118,10 +124,6 @@ struct mga_i2c_chan *mgag200_i2c_create(struct drm_device *dev) break; } - i2c = kzalloc(sizeof(struct mga_i2c_chan), GFP_KERNEL); - if (!i2c) - return ERR_PTR(-ENOMEM); - i2c->data = data; i2c->clock = clock; i2c->adapter.owner = THIS_MODULE; @@ -143,20 +145,7 @@ struct mga_i2c_chan *mgag200_i2c_create(struct drm_device *dev) ret = i2c_bit_add_bus(&i2c->adapter); if (ret) - goto err_kfree; + return ret; - return i2c; - -err_kfree: - kfree(i2c); - return ERR_PTR(ret); -} - -void mgag200_i2c_destroy(struct mga_i2c_chan *i2c) -{ - if (!i2c) - return; - i2c_del_adapter(&i2c->adapter); - kfree(i2c); + return devm_add_action_or_reset(dev->dev, mgag200_i2c_release, i2c); } - |