[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20241226193637.241049-8-niharchaithanya@gmail.com>
Date: Fri, 27 Dec 2024 01:06:31 +0530
From: Nihar Chaithanya <niharchaithanya@...il.com>
To: dpenkler@...il.com,
gregkh@...uxfoundation.org
Cc: dan.carpenter@...aro.org,
skhan@...uxfoundation.org,
linux-staging@...ts.linux.dev,
linux-kernel@...r.kernel.org,
Nihar Chaithanya <niharchaithanya@...il.com>
Subject: [PATCH v4 07/15] staging: gpib: fmh: Handle gpib_register_driver() errors
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, pci and gpib registering
functions if subsequent gpib_register_driver() fail and return the
error value.
Signed-off-by: Nihar Chaithanya <niharchaithanya@...il.com>
---
drivers/staging/gpib/fmh_gpib/fmh_gpib.c | 43 +++++++++++++++++-------
1 file changed, 31 insertions(+), 12 deletions(-)
diff --git a/drivers/staging/gpib/fmh_gpib/fmh_gpib.c b/drivers/staging/gpib/fmh_gpib/fmh_gpib.c
index 62791db1c34a..30676f139a61 100644
--- a/drivers/staging/gpib/fmh_gpib/fmh_gpib.c
+++ b/drivers/staging/gpib/fmh_gpib/fmh_gpib.c
@@ -1690,24 +1690,43 @@ static int __init fmh_gpib_init_module(void)
int result;
result = platform_driver_register(&fmh_gpib_platform_driver);
- if (result) {
- pr_err("fmh_gpib: platform_driver_register failed!\n");
+ if (result)
return result;
- }
result = pci_register_driver(&fmh_gpib_pci_driver);
- if (result) {
- pr_err("fmh_gpib: pci_driver_register failed!\n");
- return result;
- }
+ if (result)
+ goto err_pci_driver;
+
+ result = gpib_register_driver(&fmh_gpib_unaccel_interface, THIS_MODULE);
+ if (result)
+ goto err_unaccel;
- gpib_register_driver(&fmh_gpib_unaccel_interface, THIS_MODULE);
- gpib_register_driver(&fmh_gpib_interface, THIS_MODULE);
- gpib_register_driver(&fmh_gpib_pci_unaccel_interface, THIS_MODULE);
- gpib_register_driver(&fmh_gpib_pci_interface, THIS_MODULE);
+ result = gpib_register_driver(&fmh_gpib_interface, THIS_MODULE);
+ if (result)
+ goto err_interface;
+
+ result = gpib_register_driver(&fmh_gpib_pci_unaccel_interface, THIS_MODULE);
+ if (result)
+ goto err_pci_unaccel;
+
+ result = gpib_register_driver(&fmh_gpib_pci_interface, THIS_MODULE);
+ if (result)
+ goto err_pci;
- pr_info("fmh_gpib\n");
return 0;
+
+err_pci:
+ gpib_unregister_driver(&fmh_gpib_pci_unaccel_interface);
+err_pci_unaccel:
+ gpib_unregister_driver(&fmh_gpib_interface);
+err_interface:
+ gpib_unregister_driver(&fmh_gpib_unaccel_interface);
+err_unaccel:
+ pci_unregister_driver(&fmh_gpib_pci_driver);
+err_pci_driver:
+ platform_driver_unregister(&fmh_gpib_platform_driver);
+
+ return result;
}
static void __exit fmh_gpib_exit_module(void)
--
2.34.1
Powered by blists - more mailing lists