The function gpib_register_driver() can fail, resulting in a semi-registered module and does not return an error value if it fails. Unregister the previous gpib registering functions if subsequent gpib_register_driver() fail and return the error value. Signed-off-by: Nihar Chaithanya <niharchaithanya@xxxxxxxxx> --- drivers/staging/gpib/pc2/pc2_gpib.c | 30 +++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/drivers/staging/gpib/pc2/pc2_gpib.c b/drivers/staging/gpib/pc2/pc2_gpib.c index 7b3b34f47341..1d42ced67b2c 100644 --- a/drivers/staging/gpib/pc2/pc2_gpib.c +++ b/drivers/staging/gpib/pc2/pc2_gpib.c @@ -635,12 +635,34 @@ void pc2_2a_detach(gpib_board_t *board) static int __init pc2_init_module(void) { - gpib_register_driver(&pc2_interface, THIS_MODULE); - gpib_register_driver(&pc2a_interface, THIS_MODULE); - gpib_register_driver(&pc2a_cb7210_interface, THIS_MODULE); - gpib_register_driver(&pc2_2a_interface, THIS_MODULE); + int ret; + + ret = gpib_register_driver(&pc2_interface, THIS_MODULE); + if (ret) + return ret; + + ret = gpib_register_driver(&pc2a_interface, THIS_MODULE); + if (ret) + goto err_pc2a; + + ret = gpib_register_driver(&pc2a_cb7210_interface, THIS_MODULE); + if (ret) + goto err_cb7210; + + ret = gpib_register_driver(&pc2_2a_interface, THIS_MODULE); + if (ret) + goto err_pc2_2a; return 0; + +err_pc2_2a: + gpib_unregister_driver(&pc2a_cb7210_interface); +err_cb7210: + gpib_unregister_driver(&pc2a_interface); +err_pc2a: + gpib_unregister_driver(&pc2_interface); + + return ret; } static void __exit pc2_exit_module(void) -- 2.34.1