[PATCH v3 5/7] staging: pi433: Remove duplicated code using the "goto" error recovery scheme.

Shahar Avidar posted 7 patches 1 year, 10 months ago
[PATCH v3 5/7] staging: pi433: Remove duplicated code using the "goto" error recovery scheme.
Posted by Shahar Avidar 1 year, 10 months ago
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.
v2->v3:
        - Undo pi433 init & exit calls reordering. Reorder exit calls in
          a seperate patch.
        - Remove "unreg_spi_drv" tag.
        - Undo return value checking for "debugfs_create_dir".
        - Undo "if" statements update.

 drivers/staging/pi433/pi433_if.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/staging/pi433/pi433_if.c b/drivers/staging/pi433/pi433_if.c
index 62ce75b07bf0..b01ee145ff3c 100644
--- a/drivers/staging/pi433/pi433_if.c
+++ b/drivers/staging/pi433/pi433_if.c
@@ -1403,21 +1403,21 @@ static int __init pi433_init(void)
 		return status;
 
 	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_and_remove_dbfs;
 
+	return 0;
+
+unreg_class_and_remove_dbfs:
+	class_unregister(&pi433_class);
+unreg_chrdev:
+	unregister_chrdev(MAJOR(pi433_devt), pi433_spi_driver.driver.name);
 	return status;
 }
 
-- 
2.34.1
Re: [PATCH v3 5/7] staging: pi433: Remove duplicated code using the "goto" error recovery scheme.
Posted by Markus Elfring 1 year, 10 months ago
I suggest to use the summary phrase “Use common error handling code
in pi433_init()” instead.


> pi433_init had "unregister_chrdev" called twice.
> Remove it using goto statements.

How do you think about to use the following change description?

   unregister_chrdev() was called in two if branches.
   Thus add jump targets so that a bit of exception handling can be better
   reused at the end of this function implementation.


…
v2->v3:
…
          a seperate patch.
…

Would you like to avoid a typo here?

Regards,
Markus
Re: [PATCH v3 5/7] staging: pi433: Remove duplicated code using the "goto" error recovery scheme.
Posted by Greg Kroah-Hartman 1 year, 10 months ago
On Fri, Apr 05, 2024 at 12:05:56PM +0200, Markus Elfring wrote:
> I suggest to use the summary phrase “Use common error handling code
> in pi433_init()” instead.
> 
> 
> > pi433_init had "unregister_chrdev" called twice.
> > Remove it using goto statements.
> 
> How do you think about to use the following change description?
> 
>    unregister_chrdev() was called in two if branches.
>    Thus add jump targets so that a bit of exception handling can be better
>    reused at the end of this function implementation.
> 
> 
> …
> v2->v3:
> …
>           a seperate patch.
> …
> 
> Would you like to avoid a typo here?
> 
> Regards,
> Markus
> 

Hi,

This is the semi-friendly patch-bot of Greg Kroah-Hartman.

Markus, you seem to have sent a nonsensical or otherwise pointless
review comment to a patch submission on a Linux kernel developer mailing
list.  I strongly suggest that you not do this anymore.  Please do not
bother developers who are actively working to produce patches and
features with comments that, in the end, are a waste of time.

Patch submitter, please ignore Markus's suggestion; you do not need to
follow it at all.  The person/bot/AI that sent it is being ignored by
almost all Linux kernel maintainers for having a persistent pattern of
behavior of producing distracting and pointless commentary, and
inability to adapt to feedback.  Please feel free to also ignore emails
from them.

thanks,

greg k-h's patch email bot