From: Shahar Avidar <ikobh7@gmail.com>
To: gregkh@linuxfoundation.org, hverkuil-cisco@xs4all.nl,
andriy.shevchenko@linux.intel.com, robh@kernel.org,
felixkimbu1@gmail.com
Cc: linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: [PATCH v2 5/6] staging: pi433: Remove duplicated code using the "goto" error recovery scheme.
Date: Tue, 2 Apr 2024 14:14:13 +0300 [thread overview]
Message-ID: <20240402111414.871089-6-ikobh7@gmail.com> (raw)
In-Reply-To: <20240402111414.871089-1-ikobh7@gmail.com>
pi433_init had "unregister_chrdev" called twice.
Remove it using goto statements.
Signed-off-by: Shahar Avidar <ikobh7@gmail.com>
---
v2->v1:
Followed by Dan Carpenter's <dan.carpenter@linaro.org> comments:
- Remove empty "fail" goto tag.
- Reorder pi433 init & exit calls so they have reverse order.
- Add "unreg_spi_drv" goto tag.
- Check "debugfs_create_dir" return value.
- Update "if" statments for consistency.
drivers/staging/pi433/pi433_if.c | 33 +++++++++++++++++++-------------
1 file changed, 20 insertions(+), 13 deletions(-)
diff --git a/drivers/staging/pi433/pi433_if.c b/drivers/staging/pi433/pi433_if.c
index 62ce75b07bf0..47e0c51ffe2e 100644
--- a/drivers/staging/pi433/pi433_if.c
+++ b/drivers/staging/pi433/pi433_if.c
@@ -1399,25 +1399,32 @@ static int __init pi433_init(void)
* Last, register the driver which manages those device numbers.
*/
status = alloc_chrdev_region(&pi433_devt, 0, N_PI433_MINORS, "pi433");
- if (status < 0)
+ if (status)
return status;
status = class_register(&pi433_class);
- if (status) {
- unregister_chrdev(MAJOR(pi433_devt),
- pi433_spi_driver.driver.name);
- return status;
- }
-
- root_dir = debugfs_create_dir(KBUILD_MODNAME, NULL);
+ if (status)
+ goto unreg_chrdev;
status = spi_register_driver(&pi433_spi_driver);
- if (status < 0) {
- class_unregister(&pi433_class);
- unregister_chrdev(MAJOR(pi433_devt),
- pi433_spi_driver.driver.name);
+ if (status)
+ goto unreg_class;
+
+ root_dir = debugfs_create_dir(KBUILD_MODNAME, NULL);
+ if (IS_ERR(root_dir)) {
+ status = PTR_ERR(root_dir);
+ goto unreg_spi_drv;
}
+ return 0;
+
+unreg_spi_drv:
+ spi_unregister_driver(&pi433_spi_driver);
+unreg_class:
+ class_unregister(&pi433_class);
+unreg_chrdev:
+ unregister_chrdev(MAJOR(pi433_devt), pi433_spi_driver.driver.name);
+
return status;
}
@@ -1425,10 +1432,10 @@ module_init(pi433_init);
static void __exit pi433_exit(void)
{
+ debugfs_remove(root_dir);
spi_unregister_driver(&pi433_spi_driver);
class_unregister(&pi433_class);
unregister_chrdev(MAJOR(pi433_devt), pi433_spi_driver.driver.name);
- debugfs_remove(root_dir);
}
module_exit(pi433_exit);
--
2.34.1
next prev parent reply other threads:[~2024-04-02 11:14 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-02 11:14 [PATCH v2 0/6] staging: pi433: Remove duplicated code using the "goto" error recovery scheme Shahar Avidar
2024-04-02 11:14 ` [PATCH v2 1/6] staging: pi433: Rename struct pi433_device buffer field to tx_buffer Shahar Avidar
2024-04-02 11:14 ` [PATCH v2 2/6] staging: pi433: Rename struct pi433_device instances to pi433 Shahar Avidar
2024-04-02 11:14 ` [PATCH v2 3/6] staging: pi433: Replace pi433_receive param void type to struct pi433_device Shahar Avidar
2024-04-02 11:14 ` [PATCH v2 4/6] staging: pi433: Rename "pi433_dev" of type "dev_t" to "pi433_devt" Shahar Avidar
2024-04-02 11:14 ` Shahar Avidar [this message]
2024-04-02 16:46 ` [PATCH v2 5/6] staging: pi433: Remove duplicated code using the "goto" error recovery scheme Dan Carpenter
2024-04-05 7:46 ` Shahar Avidar
2024-04-02 11:14 ` [PATCH v2 6/6] staging: pi433: Rename return value from "status" to "ret" Shahar Avidar
2024-04-02 16:50 ` Dan Carpenter
2024-04-05 7:47 ` Shahar Avidar
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=20240402111414.871089-6-ikobh7@gmail.com \
--to=ikobh7@gmail.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=felixkimbu1@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=hverkuil-cisco@xs4all.nl \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=robh@kernel.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