[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20241226193637.241049-15-niharchaithanya@gmail.com>
Date: Fri, 27 Dec 2024 01:06:38 +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 14/15] staging: gpib: pc2: 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 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/pc2/pc2_gpib.c | 30 +++++++++++++++++++++++++----
1 file changed, 26 insertions(+), 4 deletions(-)
diff --git a/drivers/staging/gpib/pc2/pc2_gpib.c b/drivers/staging/gpib/pc2/pc2_gpib.c
index 7b3b34f47341..1d42ced67b2c 100644
--- a/drivers/staging/gpib/pc2/pc2_gpib.c
+++ b/drivers/staging/gpib/pc2/pc2_gpib.c
@@ -635,12 +635,34 @@ void pc2_2a_detach(gpib_board_t *board)
static int __init pc2_init_module(void)
{
- gpib_register_driver(&pc2_interface, THIS_MODULE);
- gpib_register_driver(&pc2a_interface, THIS_MODULE);
- gpib_register_driver(&pc2a_cb7210_interface, THIS_MODULE);
- gpib_register_driver(&pc2_2a_interface, THIS_MODULE);
+ int ret;
+
+ ret = gpib_register_driver(&pc2_interface, THIS_MODULE);
+ if (ret)
+ return ret;
+
+ ret = gpib_register_driver(&pc2a_interface, THIS_MODULE);
+ if (ret)
+ goto err_pc2a;
+
+ ret = gpib_register_driver(&pc2a_cb7210_interface, THIS_MODULE);
+ if (ret)
+ goto err_cb7210;
+
+ ret = gpib_register_driver(&pc2_2a_interface, THIS_MODULE);
+ if (ret)
+ goto err_pc2_2a;
return 0;
+
+err_pc2_2a:
+ gpib_unregister_driver(&pc2a_cb7210_interface);
+err_cb7210:
+ gpib_unregister_driver(&pc2a_interface);
+err_pc2a:
+ gpib_unregister_driver(&pc2_interface);
+
+ return ret;
}
static void __exit pc2_exit_module(void)
--
2.34.1
Powered by blists - more mailing lists