All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nihar Chaithanya <niharchaithanya@gmail.com>
To: dpenkler@gmail.com, gregkh@linuxfoundation.org
Cc: dan.carpenter@linaro.org, skhan@linuxfoundation.org,
	linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org,
	Nihar Chaithanya <niharchaithanya@gmail.com>
Subject: [PATCH v4 06/15] staging: gpib: fluke: Handle gpib_register_driver() errors
Date: Fri, 27 Dec 2024 01:06:30 +0530	[thread overview]
Message-ID: <20241226193637.241049-7-niharchaithanya@gmail.com> (raw)
In-Reply-To: <20241226193637.241049-1-niharchaithanya@gmail.com>

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 and gpib registering
functions if subsequent gpib_register_driver() fail and return the
error value.

Signed-off-by: Nihar Chaithanya <niharchaithanya@gmail.com>
---
 drivers/staging/gpib/eastwood/fluke_gpib.c | 28 ++++++++++++++++------
 1 file changed, 21 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/gpib/eastwood/fluke_gpib.c b/drivers/staging/gpib/eastwood/fluke_gpib.c
index 3f938ab0c84d..2efc0226ec2b 100644
--- a/drivers/staging/gpib/eastwood/fluke_gpib.c
+++ b/drivers/staging/gpib/eastwood/fluke_gpib.c
@@ -1154,17 +1154,31 @@ static int __init fluke_init_module(void)
 	int result;
 
 	result = platform_driver_register(&fluke_gpib_platform_driver);
-	if (result) {
-		pr_err("fluke_gpib: platform_driver_register failed!\n");
+	if (result)
 		return result;
-	}
 
-	gpib_register_driver(&fluke_unaccel_interface, THIS_MODULE);
-	gpib_register_driver(&fluke_hybrid_interface, THIS_MODULE);
-	gpib_register_driver(&fluke_interface, THIS_MODULE);
+	result = gpib_register_driver(&fluke_unaccel_interface, THIS_MODULE);
+	if (result)
+		goto err_unaccel;
+
+	result = gpib_register_driver(&fluke_hybrid_interface, THIS_MODULE);
+	if (result)
+		goto err_hybrid;
+
+	result = gpib_register_driver(&fluke_interface, THIS_MODULE);
+	if (result)
+		goto err_interface;
 
-	pr_info("fluke_gpib\n");
 	return 0;
+
+err_interface:
+	gpib_unregister_driver(&fluke_hybrid_interface);
+err_hybrid:
+	gpib_unregister_driver(&fluke_unaccel_interface);
+err_unaccel:
+	platform_driver_unregister(&fluke_gpib_platform_driver);
+
+	return result;
 }
 
 static void __exit fluke_exit_module(void)
-- 
2.34.1


  parent reply	other threads:[~2024-12-26 19:49 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-26 19:36 [PATCH v4 00/15] staging: gpib: Handle gpib_register_driver() errors Nihar Chaithanya
2024-12-26 19:36 ` [PATCH v4 01/15] staging: gpib: Modify gpib_register_driver() to return error if it fails Nihar Chaithanya
2024-12-26 20:41   ` Shuah Khan
2024-12-27 12:19     ` Nihar Chaithanya
2024-12-26 19:36 ` [PATCH v4 02/15] staging: gpib: agilent_82350b: Handle gpib_register_driver() errors Nihar Chaithanya
2024-12-26 20:43   ` Shuah Khan
2024-12-26 19:36 ` [PATCH v4 03/15] staging: gpib: agilent_82357a: " Nihar Chaithanya
2024-12-26 21:10   ` Shuah Khan
2024-12-26 19:36 ` [PATCH v4 04/15] staging: gpib: cb7210: " Nihar Chaithanya
2024-12-26 19:36 ` [PATCH v4 05/15] staging: gpib: cec: " Nihar Chaithanya
2024-12-26 19:36 ` Nihar Chaithanya [this message]
2024-12-26 19:36 ` [PATCH v4 07/15] staging: gpib: fmh: " Nihar Chaithanya
2024-12-26 23:32   ` kernel test robot
2024-12-27  2:51   ` kernel test robot
2024-12-26 19:36 ` [PATCH v4 08/15] staging: gpib: gpio: Return error value from gpib_register_driver() Nihar Chaithanya
2024-12-26 19:36 ` [PATCH v4 09/15] staging: gpib: hp_82335: " Nihar Chaithanya
2024-12-26 19:36 ` [PATCH v4 10/15] staging: gpib: hp_82341: Handle gpib_register_driver() errors Nihar Chaithanya
2024-12-26 19:36 ` [PATCH v4 11/15] staging: gpib: ines: " Nihar Chaithanya
2024-12-26 19:36 ` [PATCH v4 12/15] staging: gpib: lpvo_usb: Return error value from gpib_register_driver() Nihar Chaithanya
2024-12-26 19:36 ` [PATCH v4 13/15] staging: gpib: ni_usb: Handle gpib_register_driver() errors Nihar Chaithanya
2024-12-26 19:36 ` [PATCH v4 14/15] staging: gpib: pc2: " Nihar Chaithanya
2024-12-26 19:36 ` [PATCH v4 15/15] staging: gpib: tnt4882: " Nihar Chaithanya

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241226193637.241049-7-niharchaithanya@gmail.com \
    --to=niharchaithanya@gmail.com \
    --cc=dan.carpenter@linaro.org \
    --cc=dpenkler@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=skhan@linuxfoundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.