[PATCH v4 05/15] staging: gpib: cec: Handle gpib_register_driver() errors
From: Nihar Chaithanya
Date: Thu Dec 26 2024 - 14:51:05 EST
The function gpib_register_driver() can fail and result in a
semi-registered module and does not return an error value if it
fails.
Unregister the pci registering function in case gpib_register_driver()
fails and return the error value.
Signed-off-by: Nihar Chaithanya <niharchaithanya@xxxxxxxxx>
---
drivers/staging/gpib/cec/cec_gpib.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/drivers/staging/gpib/cec/cec_gpib.c b/drivers/staging/gpib/cec/cec_gpib.c
index 3dc933deb401..ffa366c30ac5 100644
--- a/drivers/staging/gpib/cec/cec_gpib.c
+++ b/drivers/staging/gpib/cec/cec_gpib.c
@@ -361,17 +361,17 @@ static struct pci_driver cec_pci_driver = {
static int __init cec_init_module(void)
{
- int result;
+ int result = 0;
result = pci_register_driver(&cec_pci_driver);
- if (result) {
- pr_err("cec_gpib: pci_driver_register failed!\n");
+ if (result)
return result;
- }
- gpib_register_driver(&cec_pci_interface, THIS_MODULE);
+ result = gpib_register_driver(&cec_pci_interface, THIS_MODULE);
+ if (result)
+ pci_unregister_driver(&cec_pci_driver);
- return 0;
+ return result;
}
static void cec_exit_module(void)
--
2.34.1