drm: bridge: adv7511: Add check for mipi_dsi_driver_register
authorJiasheng Jiang <jiasheng@iscas.ac.cn>
Thu, 2 Jun 2022 10:34:01 +0000 (18:34 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 17 Aug 2022 12:23:23 +0000 (14:23 +0200)
[ Upstream commit 831463667b5f4f1e5bce9c3b94e9e794d2bc8923 ]

As mipi_dsi_driver_register could return error if fails,
it should be better to check the return value and return error
if fails.
Moreover, if i2c_add_driver fails,  mipi_dsi_driver_register
should be reverted.

Fixes: 1e4d58cd7f88 ("drm/bridge: adv7533: Create a MIPI DSI device")
Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20220602103401.2980938-1-jiasheng@iscas.ac.cn
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/gpu/drm/bridge/adv7511/adv7511_drv.c

index 1aadc6e94fde1adf91de5e19fc8b615044c47991..7e3f6633f255dd666f50606fa59320b5dfe37ff7 100644 (file)
@@ -1379,10 +1379,21 @@ static struct i2c_driver adv7511_driver = {
 
 static int __init adv7511_init(void)
 {
-       if (IS_ENABLED(CONFIG_DRM_MIPI_DSI))
-               mipi_dsi_driver_register(&adv7533_dsi_driver);
+       int ret;
+
+       if (IS_ENABLED(CONFIG_DRM_MIPI_DSI)) {
+               ret = mipi_dsi_driver_register(&adv7533_dsi_driver);
+               if (ret)
+                       return ret;
+       }
 
-       return i2c_add_driver(&adv7511_driver);
+       ret = i2c_add_driver(&adv7511_driver);
+       if (ret) {
+               if (IS_ENABLED(CONFIG_DRM_MIPI_DSI))
+                       mipi_dsi_driver_unregister(&adv7533_dsi_driver);
+       }
+
+       return ret;
 }
 module_init(adv7511_init);