Skip to content

Commit

Permalink
drm/bridge: megachips: Fix error handling in i2c_register_driver()
Browse files Browse the repository at this point in the history
[ Upstream commit 4ecff95 ]

A problem about insmod megachips-stdpxxxx-ge-b850v3-fw.ko failed is
triggered with the following log given:

[ 4497.981497] Error: Driver 'stdp4028-ge-b850v3-fw' is already registered, aborting...
insmod: ERROR: could not insert module megachips-stdpxxxx-ge-b850v3-fw.ko: Device or resource busy

The reason is that stdpxxxx_ge_b850v3_init() returns i2c_add_driver()
directly without checking its return value, if i2c_add_driver() failed,
it returns without calling i2c_del_driver() on the previous i2c driver,
resulting the megachips-stdpxxxx-ge-b850v3-fw can never be installed
later.
A simple call graph is shown as below:

 stdpxxxx_ge_b850v3_init()
   i2c_add_driver(&stdp4028_ge_b850v3_fw_driver)
   i2c_add_driver(&stdp2690_ge_b850v3_fw_driver)
     i2c_register_driver()
       driver_register()
         bus_add_driver()
           priv = kzalloc(...) # OOM happened
   # return without delete stdp4028_ge_b850v3_fw_driver

Fix by calling i2c_del_driver() on stdp4028_ge_b850v3_fw_driver when
i2c_add_driver() returns error.

Fixes: fcfa0dd ("drm/bridge: Drivers for megachips-stdpxxxx-ge-b850v3-fw (LVDS-DP++)")
Signed-off-by: Yuan Can <[email protected]>
Reviewed-by: Andrzej Hajda <[email protected]>
Tested-by: Ian Ray <[email protected]>
Signed-off-by: Robert Foss <[email protected]>
Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
Signed-off-by: Sasha Levin <[email protected]>
  • Loading branch information
Yuan Can authored and gregkh committed Mar 11, 2023
1 parent 181fb5e commit 5b9bcb3
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,11 @@ static int __init stdpxxxx_ge_b850v3_init(void)
if (ret)
return ret;

return i2c_add_driver(&stdp2690_ge_b850v3_fw_driver);
ret = i2c_add_driver(&stdp2690_ge_b850v3_fw_driver);
if (ret)
i2c_del_driver(&stdp4028_ge_b850v3_fw_driver);

return ret;
}
module_init(stdpxxxx_ge_b850v3_init);

Expand Down

0 comments on commit 5b9bcb3

Please sign in to comment.