From: Dan Carpenter <dan.carpenter@linaro.org>
To: Shahar Avidar <ikobh7@gmail.com>
Cc: gregkh@linuxfoundation.org, hverkuil-cisco@xs4all.nl,
andriy.shevchenko@linux.intel.com, robh@kernel.org,
felixkimbu1@gmail.com, linux-staging@lists.linux.dev,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 5/5] staging: pi433: Remove duplicated code using the "goto" error recovery scheme.
Date: Thu, 28 Mar 2024 17:03:17 +0300 [thread overview]
Message-ID: <9c5b4159-da26-49d8-9682-445c01b19a51@moroto.mountain> (raw)
In-Reply-To: <20240328121244.1244719-7-ikobh7@gmail.com>
On Thu, Mar 28, 2024 at 02:12:44PM +0200, Shahar Avidar wrote:
> pi433_init had "unregister_chrdev" called twice.
> Remove it using goto statements.
>
> Signed-off-by: Shahar Avidar <ikobh7@gmail.com>
> ---
> drivers/staging/pi433/pi433_if.c | 23 ++++++++++++-----------
> 1 file changed, 12 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/staging/pi433/pi433_if.c b/drivers/staging/pi433/pi433_if.c
> index 62ce75b07bf0..e538f1d4e787 100644
> --- a/drivers/staging/pi433/pi433_if.c
> +++ b/drivers/staging/pi433/pi433_if.c
> @@ -1400,24 +1400,25 @@ static int __init pi433_init(void)
> */
> status = alloc_chrdev_region(&pi433_devt, 0, N_PI433_MINORS, "pi433");
> if (status < 0)
> - return status;
> + goto fail;
Just return directly. Do nothing gotos are bad for readability and they
create Forgot to Set the Error Code bugs. Also there was a direct
return earlier in the function so it's better to do things consistently.
>
> status = class_register(&pi433_class);
> - if (status) {
> - unregister_chrdev(MAJOR(pi433_devt),
> - pi433_spi_driver.driver.name);
> - return status;
> - }
> + if (status)
> + goto unreg_chrdev;
>
> root_dir = debugfs_create_dir(KBUILD_MODNAME, NULL);
>
> 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 < 0)
> + goto unreg_class;
>
> + return 0;
> +
> +unreg_class:
> + class_unregister(&pi433_class);
There is a debugfs_remove() missing. I have written a blog that might
be helpful:
https://staticthinking.wordpress.com/2022/04/28/free-the-last-thing-style/
regards,
dan carpenter
> +unreg_chrdev:
> + unregister_chrdev(MAJOR(pi433_devt), pi433_spi_driver.driver.name);
> +fail:
> return status;
> }
next prev parent reply other threads:[~2024-03-28 14:03 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-28 12:12 [PATCH 0/5] staging: pi433: Rename vars, update param type & remove duplicated code Shahar Avidar
2024-03-28 12:12 ` [PATCH 1/5] staging: pi433: Rename struct pi433_device buffer field to tx_buffer Shahar Avidar
2024-03-28 12:12 ` [PATCH 2/5] staging: pi433: Rename struct pi433_device instances to pi433 Shahar Avidar
2024-03-28 12:12 ` [PATCH 3/5] staging: pi433: Replace pi433_receive param void type to struct pi433_device Shahar Avidar
2024-03-28 12:12 ` Shahar Avidar
2024-03-28 12:12 ` [PATCH 4/5] staging: pi433: Rename "pi433_dev" of type "dev_t" to "pi433_devt" Shahar Avidar
2024-03-28 12:12 ` [PATCH 5/5] staging: pi433: Remove duplicated code using the "goto" error recovery scheme Shahar Avidar
2024-03-28 14:03 ` Dan Carpenter [this message]
2024-04-02 11:19 ` 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=9c5b4159-da26-49d8-9682-445c01b19a51@moroto.mountain \
--to=dan.carpenter@linaro.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=felixkimbu1@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=hverkuil-cisco@xs4all.nl \
--cc=ikobh7@gmail.com \
--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
all inboxes | Powered by JetHome®