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 platform driver and gpib registering functions if subsequent gpib_register_driver() fail and return the error value. Add pr_err() statements indicating the fail and the error value. Signed-off-by: Nihar Chaithanya <niharchaithanya@xxxxxxxxx> --- drivers/staging/gpib/eastwood/fluke_gpib.c | 32 ++++++++++++++++++---- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/drivers/staging/gpib/eastwood/fluke_gpib.c b/drivers/staging/gpib/eastwood/fluke_gpib.c index 3f938ab0c84d..875b3adcb584 100644 --- a/drivers/staging/gpib/eastwood/fluke_gpib.c +++ b/drivers/staging/gpib/eastwood/fluke_gpib.c @@ -1155,16 +1155,38 @@ static int __init fluke_init_module(void) result = platform_driver_register(&fluke_gpib_platform_driver); if (result) { - pr_err("fluke_gpib: platform_driver_register failed!\n"); + pr_err("fluke_gpib: platform_driver_register failed: error = %d\n", result); return result; } - gpib_register_driver(&fluke_unaccel_interface, THIS_MODULE); - gpib_register_driver(&fluke_hybrid_interface, THIS_MODULE); - gpib_register_driver(&fluke_interface, THIS_MODULE); + result = gpib_register_driver(&fluke_unaccel_interface, THIS_MODULE); + if (result) { + pr_err("fluke_gpib: gpib_register_driver failed: error = %d\n", result); + goto err_unaccel; + } + + result = gpib_register_driver(&fluke_hybrid_interface, THIS_MODULE); + if (result) { + pr_err("fluke_gpib: gpib_register_driver failed: error = %d\n", result); + goto err_hybrid; + } + + result = gpib_register_driver(&fluke_interface, THIS_MODULE); + if (result) { + pr_err("fluke_gpib: gpib_register_driver failed: error = %d\n", result); + goto err_interface; + } - pr_info("fluke_gpib\n"); return 0; + +err_interface: + gpib_unregister_driver(&fluke_hybrid_interface); +err_hybrid: + gpib_unregister_driver(&fluke_unaccel_interface); +err_unaccel: + platform_driver_unregister(&fluke_gpib_platform_driver); + + return result; } static void __exit fluke_exit_module(void) -- 2.34.1