]> git.baikalelectronics.ru Git - kernel.git/commitdiff
drm/mgag200: Fail on I2C initialization errors
authorThomas Zimmermann <tzimmermann@suse.de>
Mon, 16 May 2022 13:43:38 +0000 (15:43 +0200)
committerThomas Zimmermann <tzimmermann@suse.de>
Tue, 17 May 2022 18:23:28 +0000 (20:23 +0200)
Initialization of the I2C adapter was allowed to fail. The mgag200
driver would have continued without DDC support. Had this happened in
practice, it would have led to segmentation faults in the connector
code. Resolve this problem by failing driver initialization on I2C-
related errors.

v2:
* initialize 'ret' before drm_err() (kernel test robot)

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-3-tzimmermann@suse.de
drivers/gpu/drm/mgag200/mgag200_i2c.c
drivers/gpu/drm/mgag200/mgag200_mode.c

index ac8e34eef5138b036b5248f48bcad828719d0bad..31e2c641a7814f2e0bafa8e0a17106d9e0d899fa 100644 (file)
@@ -120,7 +120,7 @@ struct mga_i2c_chan *mgag200_i2c_create(struct drm_device *dev)
 
        i2c = kzalloc(sizeof(struct mga_i2c_chan), GFP_KERNEL);
        if (!i2c)
-               return NULL;
+               return ERR_PTR(-ENOMEM);
 
        i2c->data = data;
        i2c->clock = clock;
@@ -142,11 +142,14 @@ struct mga_i2c_chan *mgag200_i2c_create(struct drm_device *dev)
        i2c->bit.getscl         = mga_gpio_getscl;
 
        ret = i2c_bit_add_bus(&i2c->adapter);
-       if (ret) {
-               kfree(i2c);
-               i2c = NULL;
-       }
+       if (ret)
+               goto err_kfree;
+
        return i2c;
+
+err_kfree:
+       kfree(i2c);
+       return ERR_PTR(ret);
 }
 
 void mgag200_i2c_destroy(struct mga_i2c_chan *i2c)
index 762b9657ae8d354c63fd8080415445101bc2607c..b227891d01ec711e475ffd1046c77a7eb7f62056 100644 (file)
@@ -849,8 +849,11 @@ static int mgag200_vga_connector_init(struct mga_device *mdev)
        int ret;
 
        i2c = mgag200_i2c_create(dev);
-       if (!i2c)
-               drm_warn(dev, "failed to add DDC bus\n");
+       if (IS_ERR(i2c)) {
+               ret = PTR_ERR(i2c)
+               drm_err(dev, "failed to add DDC bus: %d\n", ret);
+               return ret;
+       }
 
        ret = drm_connector_init_with_ddc(dev, connector,
                                          &mga_vga_connector_funcs,