[PATCH] drm/panel/raspberrypi-touchscreen: Fix error handling in rpi_touchscreen_init()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



A problem about modprobe panel-raspberrypi-touchscreen is triggered with
the following log given:

 [  542.980748] Error: Driver 'rpi-ts-dsi' is already registered, aborting...

And with this log printed, the panel_raspberrypi_touchscreen is listed by
lsmod, rmmod on it can trigger the WARN of "Unexpected driver unregister".

The reason is that the return value of mipi_dsi_driver_register() and
i2c_add_driver() is not checked in rpi_touchscreen_init(), if
i2c_add_driver() failed, the rpi_touchscreen_dsi_driver is never
unregistered, and next time when install this module, the
mipi_dsi_driver_register() is failed but rpi_touchscreen_init() returns 0,
leading to the panel_raspberrypi_touchscreen listed by lsmod.

Call graph of modprobe panel-raspberrypi-touchscreen at the first time:
 rpi_touchscreen_init()
   mipi_dsi_driver_register() # register rpi_touchscreen_dsi_driver
   i2c_add_driver()
     driver_register()
       bus_add_driver()
         priv = kzalloc(...) # OOM happened
 # return without unregister rpi_touchscreen_dsi_driver

Call graph of retrying modprobe panel-raspberrypi-touchscreen:
 rpi_touchscreen_init()
   mipi_dsi_driver_register() # Error message printed, register failed!
   i2c_add_driver() # succeed and return

Fix by checking the return value of both functions and unregister
rpi_touchscreen_dsi_driver if i2c_add_driver() failed.

Fixes: 2f733d6194bd ("drm/panel: Add support for the Raspberry Pi 7" Touchscreen.")
Signed-off-by: Yuan Can <yuancan@xxxxxxxxxx>
---
 .../gpu/drm/panel/panel-raspberrypi-touchscreen.c   | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c b/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c
index 79f852465a84..9f3d0fedc3f2 100644
--- a/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c
+++ b/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c
@@ -497,8 +497,17 @@ static struct i2c_driver rpi_touchscreen_driver = {
 
 static int __init rpi_touchscreen_init(void)
 {
-	mipi_dsi_driver_register(&rpi_touchscreen_dsi_driver);
-	return i2c_add_driver(&rpi_touchscreen_driver);
+	int ret;
+
+	ret = mipi_dsi_driver_register(&rpi_touchscreen_dsi_driver);
+	if (ret)
+		return ret;
+
+	ret = i2c_add_driver(&rpi_touchscreen_driver);
+	if (ret)
+		mipi_dsi_driver_unregister(&rpi_touchscreen_dsi_driver);
+
+	return ret;
 }
 module_init(rpi_touchscreen_init);
 
-- 
2.17.1




[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux