]> www.infradead.org Git - users/willy/linux.git/commitdiff
staging: gpib: agilent_82350b: Handle gpib_register_driver() errors
authorNihar Chaithanya <niharchaithanya@gmail.com>
Mon, 30 Dec 2024 18:56:22 +0000 (00:26 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 7 Jan 2025 14:38:55 +0000 (15:38 +0100)
The function gpib_register_driver() can fail which can result in
semi-registered module.

In case gpib_register_driver() fails unregister the previous
gpib and pci registering functions, return the error value.
Add pr_err() when registering driver fails also indicate the error
value.

Signed-off-by: Nihar Chaithanya <niharchaithanya@gmail.com>
Link: https://lore.kernel.org/r/20241230185633.175690-3-niharchaithanya@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/gpib/agilent_82350b/agilent_82350b.c

index 53006d0cc79c5dd2200d2e7bcd48b978b88a5740..e9c1f0100b2a60e2758bc7515d2205c2befd9806 100644 (file)
@@ -910,13 +910,30 @@ static int __init agilent_82350b_init_module(void)
 
        result = pci_register_driver(&agilent_82350b_pci_driver);
        if (result) {
-               pr_err("agilent_82350b: pci_driver_register failed!\n");
+               pr_err("agilent_82350b: pci_register_driver failed: error = %d\n", result);
                return result;
        }
 
-       gpib_register_driver(&agilent_82350b_unaccel_interface, THIS_MODULE);
-       gpib_register_driver(&agilent_82350b_interface, THIS_MODULE);
+       result = gpib_register_driver(&agilent_82350b_unaccel_interface, THIS_MODULE);
+       if (result) {
+               pr_err("agilent_82350b: gpib_register_driver failed: error = %d\n", result);
+               goto err_unaccel;
+       }
+
+       result = gpib_register_driver(&agilent_82350b_interface, THIS_MODULE);
+       if (result) {
+               pr_err("agilent_82350b: gpib_register_driver failed: error = %d\n", result);
+               goto err_interface;
+       }
+
        return 0;
+
+err_interface:
+       gpib_unregister_driver(&agilent_82350b_unaccel_interface);
+err_unaccel:
+       pci_unregister_driver(&agilent_82350b_pci_driver);
+
+       return result;
 }
 
 static void __exit agilent_82350b_exit_module(void)