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 v5 15/15] staging: gpib: tnt4882: Handle gpib_register_driver() errors
Date: Sat, 28 Dec 2024 11:38:03 +0530 [thread overview]
Message-ID: <20241228060800.107653-16-niharchaithanya@gmail.com> (raw)
In-Reply-To: <20241228060800.107653-1-niharchaithanya@gmail.com>
The error value from the init_ni_gpib_cs() function is not
returned and the previous registering functions are not unregistered.
The function gpib_register_driver() can fail and similar to
pcmcia_register_driver() function failing, the previous registering
functions are not unregistered.
Unregister the gpib and pci register functions if the subsequent
gpib or pcmcia register functions fail and return the error value.
Signed-off-by: Nihar Chaithanya <niharchaithanya@gmail.com>
---
drivers/staging/gpib/tnt4882/tnt4882_gpib.c | 87 ++++++++++++++++++---
1 file changed, 74 insertions(+), 13 deletions(-)
diff --git a/drivers/staging/gpib/tnt4882/tnt4882_gpib.c b/drivers/staging/gpib/tnt4882/tnt4882_gpib.c
index e49a952fa0d8..eab7fd121f0c 100644
--- a/drivers/staging/gpib/tnt4882/tnt4882_gpib.c
+++ b/drivers/staging/gpib/tnt4882/tnt4882_gpib.c
@@ -1524,29 +1524,90 @@ static int __init tnt4882_init_module(void)
result = pci_register_driver(&tnt4882_pci_driver);
if (result) {
- pr_err("tnt4882: pci_driver_register failed!\n");
+ pr_err("tnt4882_gpib: pci_driver_register failed: error = %d\n", result);
return result;
}
- gpib_register_driver(&ni_isa_interface, THIS_MODULE);
- gpib_register_driver(&ni_isa_accel_interface, THIS_MODULE);
- gpib_register_driver(&ni_nat4882_isa_interface, THIS_MODULE);
- gpib_register_driver(&ni_nat4882_isa_accel_interface, THIS_MODULE);
- gpib_register_driver(&ni_nec_isa_interface, THIS_MODULE);
- gpib_register_driver(&ni_nec_isa_accel_interface, THIS_MODULE);
- gpib_register_driver(&ni_pci_interface, THIS_MODULE);
- gpib_register_driver(&ni_pci_accel_interface, THIS_MODULE);
+ result = gpib_register_driver(&ni_isa_interface, THIS_MODULE);
+ if (result)
+ goto err_isa;
+
+ result = gpib_register_driver(&ni_isa_accel_interface, THIS_MODULE);
+ if (result)
+ goto err_isa_accel;
+
+ result = gpib_register_driver(&ni_nat4882_isa_interface, THIS_MODULE);
+ if (result)
+ goto err_nat4882_isa;
+
+ result = gpib_register_driver(&ni_nat4882_isa_accel_interface, THIS_MODULE);
+ if (result)
+ goto err_nat4882_isa_accel;
+
+ result = gpib_register_driver(&ni_nec_isa_interface, THIS_MODULE);
+ if (result)
+ goto err_nec_isa;
+
+ result = gpib_register_driver(&ni_nec_isa_accel_interface, THIS_MODULE);
+ if (result)
+ goto err_nec_isa_accel;
+
+ result = gpib_register_driver(&ni_pci_interface, THIS_MODULE);
+ if (result)
+ goto err_pci;
+
+ result = gpib_register_driver(&ni_pci_accel_interface, THIS_MODULE);
+ if (result)
+ goto err_pci_accel;
+
#ifdef GPIB_PCMCIA
- gpib_register_driver(&ni_pcmcia_interface, THIS_MODULE);
- gpib_register_driver(&ni_pcmcia_accel_interface, THIS_MODULE);
- if (init_ni_gpib_cs() < 0)
- return -1;
+ result = gpib_register_driver(&ni_pcmcia_interface, THIS_MODULE);
+ if (result)
+ goto err_pcmcia;
+
+ result = gpib_register_driver(&ni_pcmcia_accel_interface, THIS_MODULE);
+ if (result)
+ goto err_pcmcia_accel;
+
+ result = init_ni_gpib_cs();
+ if (result)
+ goto err_pcmcia_driver;
#endif
mite_init();
mite_list_devices();
+ pr_info("tnt4882_gpib: module init is complete\n");
return 0;
+
+#ifdef GPIB_PCMCIA
+err_pcmcia_driver:
+ pr_err("tnt4882_gpib: pcmcia_register_driver failed: error = %d\n", result);
+ gpib_unregister_driver(&ni_pcmcia_accel_interface);
+err_pcmcia_accel:
+ gpib_unregister_driver(&ni_pcmcia_interface);
+err_pcmcia:
+#endif
+ gpib_unregister_driver(&ni_pci_accel_interface);
+err_pci_accel:
+ gpib_unregister_driver(&ni_pci_interface);
+err_pci:
+ gpib_unregister_driver(&ni_nec_isa_accel_interface);
+err_nec_isa_accel:
+ gpib_unregister_driver(&ni_nec_isa_interface);
+err_nec_isa:
+ gpib_unregister_driver(&ni_nat4882_isa_accel_interface);
+err_nat4882_isa_accel:
+ gpib_unregister_driver(&ni_nat4882_isa_interface);
+err_nat4882_isa:
+ gpib_unregister_driver(&ni_isa_accel_interface);
+err_isa_accel:
+ gpib_unregister_driver(&ni_isa_interface);
+err_isa:
+ pci_unregister_driver(&tnt4882_pci_driver);
+
+ pr_err("tnt4882_gpib: gpib_register_driver failed\n");
+ return result;
}
static void __exit tnt4882_exit_module(void)
--
2.34.1
prev parent reply other threads:[~2024-12-28 6:26 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-28 6:07 [PATCH v5 00/15] staging: gpib: Handle gpib_register_driver() errors Nihar Chaithanya
2024-12-28 6:07 ` [PATCH v5 01/15] staging: gpib: Modify gpib_register_driver() to return error if it fails Nihar Chaithanya
2024-12-29 10:30 ` Greg KH
2024-12-28 6:07 ` [PATCH v5 02/15] staging: gpib: agilent_82350b: Handle gpib_register_driver() errors Nihar Chaithanya
2024-12-29 10:29 ` Greg KH
2024-12-28 6:07 ` [PATCH v5 03/15] staging: gpib: agilent_82357a: " Nihar Chaithanya
2024-12-28 6:07 ` [PATCH v5 04/15] staging: gpib: cb7210: " Nihar Chaithanya
2024-12-28 6:07 ` [PATCH v5 05/15] staging: gpib: cec: " Nihar Chaithanya
2024-12-28 6:07 ` [PATCH v5 06/15] staging: gpib: fluke: " Nihar Chaithanya
2024-12-28 6:07 ` [PATCH v5 07/15] staging: gpib: fmh: " Nihar Chaithanya
2024-12-28 9:24 ` kernel test robot
2024-12-28 6:07 ` [PATCH v5 08/15] staging: gpib: gpio: Return error value from gpib_register_driver() Nihar Chaithanya
2024-12-28 6:07 ` [PATCH v5 09/15] staging: gpib: hp_82335: " Nihar Chaithanya
2024-12-28 6:07 ` [PATCH v5 10/15] staging: gpib: hp_82341: Handle gpib_register_driver() errors Nihar Chaithanya
2024-12-28 6:07 ` [PATCH v5 11/15] staging: gpib: ines: " Nihar Chaithanya
2024-12-29 10:28 ` Greg KH
2024-12-29 10:46 ` Nihar Chaithanya
2024-12-28 6:08 ` [PATCH v5 12/15] staging: gpib: lpvo_usb: Return error value from gpib_register_driver() Nihar Chaithanya
2024-12-28 6:08 ` [PATCH v5 13/15] staging: gpib: ni_usb: Handle gpib_register_driver() errors Nihar Chaithanya
2024-12-28 6:08 ` [PATCH v5 14/15] staging: gpib: pc2: " Nihar Chaithanya
2024-12-28 6:08 ` Nihar Chaithanya [this message]
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=20241228060800.107653-16-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox