The function gpib_register_driver() can fail, resulting in a semi-registered module and does not return an error value if it fails. Return the error value if the first gpib_register_driver() fails and if the second gpib_register_driver() fails unregister the first gpib_register_driver() and return the error value. Signed-off-by: Nihar Chaithanya <niharchaithanya@xxxxxxxxx> --- drivers/staging/gpib/hp_82341/hp_82341.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/staging/gpib/hp_82341/hp_82341.c b/drivers/staging/gpib/hp_82341/hp_82341.c index 8ad1c885a9fb..daf5f6e02bd5 100644 --- a/drivers/staging/gpib/hp_82341/hp_82341.c +++ b/drivers/staging/gpib/hp_82341/hp_82341.c @@ -807,9 +807,17 @@ MODULE_DEVICE_TABLE(pnp, hp_82341_pnp_table); static int __init hp_82341_init_module(void) { - gpib_register_driver(&hp_82341_unaccel_interface, THIS_MODULE); - gpib_register_driver(&hp_82341_interface, THIS_MODULE); - return 0; + int ret = 0; + + ret = gpib_register_driver(&hp_82341_unaccel_interface, THIS_MODULE); + if (ret) + return ret; + + ret = gpib_register_driver(&hp_82341_interface, THIS_MODULE); + if (ret) + gpib_unregister_driver(&hp_82341_unaccel_interface); + + return ret; } static void __exit hp_82341_exit_module(void) -- 2.34.1