The error value from the init_ni_gpib_cs() function is not returned and the previous registering functions are not unregistered. The function gpib_register_driver() can fail and similar to pcmcia_register_driver() function failing, the previous registering functions are not unregistered. Unregister the gpib and pci register functions if the subsequent gpib or pcmcia register functions fail and return the error value. Signed-off-by: Nihar Chaithanya <niharchaithanya@xxxxxxxxx> --- drivers/staging/gpib/tnt4882/tnt4882_gpib.c | 87 +++++++++++++++++---- 1 file changed, 71 insertions(+), 16 deletions(-) diff --git a/drivers/staging/gpib/tnt4882/tnt4882_gpib.c b/drivers/staging/gpib/tnt4882/tnt4882_gpib.c index e49a952fa0d8..573544e86598 100644 --- a/drivers/staging/gpib/tnt4882/tnt4882_gpib.c +++ b/drivers/staging/gpib/tnt4882/tnt4882_gpib.c @@ -1523,30 +1523,85 @@ static int __init tnt4882_init_module(void) int result; result = pci_register_driver(&tnt4882_pci_driver); - if (result) { - pr_err("tnt4882: pci_driver_register failed!\n"); + if (result) return result; - } - gpib_register_driver(&ni_isa_interface, THIS_MODULE); - gpib_register_driver(&ni_isa_accel_interface, THIS_MODULE); - gpib_register_driver(&ni_nat4882_isa_interface, THIS_MODULE); - gpib_register_driver(&ni_nat4882_isa_accel_interface, THIS_MODULE); - gpib_register_driver(&ni_nec_isa_interface, THIS_MODULE); - gpib_register_driver(&ni_nec_isa_accel_interface, THIS_MODULE); - gpib_register_driver(&ni_pci_interface, THIS_MODULE); - gpib_register_driver(&ni_pci_accel_interface, THIS_MODULE); + result = gpib_register_driver(&ni_isa_interface, THIS_MODULE); + if (result) + goto err_isa; + + result = gpib_register_driver(&ni_isa_accel_interface, THIS_MODULE); + if (result) + goto err_isa_accel; + + result = gpib_register_driver(&ni_nat4882_isa_interface, THIS_MODULE); + if (result) + goto err_nat4882_isa; + + result = gpib_register_driver(&ni_nat4882_isa_accel_interface, THIS_MODULE); + if (result) + goto err_nat4882_isa_accel; + + result = gpib_register_driver(&ni_nec_isa_interface, THIS_MODULE); + if (result) + goto err_nec_isa; + + result = gpib_register_driver(&ni_nec_isa_accel_interface, THIS_MODULE); + if (result) + goto err_nec_isa_accel; + + result = gpib_register_driver(&ni_pci_interface, THIS_MODULE); + if (result) + goto err_pci; + + result = gpib_register_driver(&ni_pci_accel_interface, THIS_MODULE); + if (result) + goto err_pci_accel; + #ifdef GPIB_PCMCIA - gpib_register_driver(&ni_pcmcia_interface, THIS_MODULE); - gpib_register_driver(&ni_pcmcia_accel_interface, THIS_MODULE); - if (init_ni_gpib_cs() < 0) - return -1; + result = gpib_register_driver(&ni_pcmcia_interface, THIS_MODULE); + if (result) + goto err_pcmcia; + + result = gpib_register_driver(&ni_pcmcia_accel_interface, THIS_MODULE); + if (result) + goto err_pcmcia_accel; + + result = init_ni_gpib_cs(); + if (result) + goto err_pcmcia_driver; #endif mite_init(); mite_list_devices(); - return 0; + +#ifdef GPIB_PCMCIA +err_pcmcia_driver: + gpib_unregister_driver(&ni_pcmcia_accel_interface); +err_pcmcia_accel: + gpib_unregister_driver(&ni_pcmcia_interface); +err_pcmcia: +#endif + gpib_unregister_driver(&ni_pci_accel_interface); +err_pci_accel: + gpib_unregister_driver(&ni_pci_interface); +err_pci: + gpib_unregister_driver(&ni_nec_isa_accel_interface); +err_nec_isa_accel: + gpib_unregister_driver(&ni_nec_isa_interface); +err_nec_isa: + gpib_unregister_driver(&ni_nat4882_isa_accel_interface); +err_nat4882_isa_accel: + gpib_unregister_driver(&ni_nat4882_isa_interface); +err_nat4882_isa: + gpib_unregister_driver(&ni_isa_accel_interface); +err_isa_accel: + gpib_unregister_driver(&ni_isa_interface); +err_isa: + pci_unregister_driver(&tnt4882_pci_driver); + + return result; } static void __exit tnt4882_exit_module(void) -- 2.34.1