Skip to contentSkip to conversation

clk: at91: pmc: Use common error handling code in pmc_register_ops()

PATCH In review Markus Elfring 2 participants 3 messages Sep 17, 2024 – Sep 18, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 clk: at91: pmc: Use common error handling code in pmc_register_ops()

From: Markus Elfring <[email protected]>
Date: Tue, 17 Sep 2024 14:28:22 +0200

Add a jump target so that a bit of exception handling can be better reused at the end of this function implementation.

This issue was detected by using the Coccinelle software.

---
 drivers/clk/at91/pmc.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)
drivers/clk/at91/pmc.c +10 -8
index 5aa9c1f1c886..040b70e1ffbc 100644
@@ -162,20 +162,18 @@ static int __init pmc_register_ops(void)
 	if (!np)
 		return -ENODEV;
 
-	if (!of_device_is_available(np)) {
-		of_node_put(np);
-		return -ENODEV;
-	}
+	if (!of_device_is_available(np))
+		goto put_node;
+
 	of_node_put(np);
 
 	np = of_find_compatible_node(NULL, NULL, "atmel,sama5d2-securam");
 	if (!np)
 		return -ENODEV;
 
-	if (!of_device_is_available(np)) {
-		of_node_put(np);
-		return -ENODEV;
-	}
+	if (!of_device_is_available(np))
+		goto put_node;
+
 	of_node_put(np);
 
 	at91_pmc_backup_suspend = of_iomap(np, 0);
@@ -187,6 +185,10 @@ static int __init pmc_register_ops(void)
 	register_syscore_ops(&pmc_syscore_ops);
 
 	return 0;
+
+put_node:
+	of_node_put(np);
+	return -ENODEV;
 }
 /* This has to happen before arch_initcall because of the tcb_clksrc driver */
 postcore_initcall(pmc_register_ops);

--
2.46.0

maintainer
#1 lore raw
Quoted 9 lines · Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 17 Sep 2024 14:28:22 +0200

Add a jump target so that a bit of exception handling can be better reused at the end of this function implementation.

This issue was detected by using the Coccinelle software.

Bad track record and no real benefit from the patch:
NACK, sorry.

Regards,
Nicolas

Quoted 49 lines
---
  drivers/clk/at91/pmc.c | 18 ++++++++++--------
  1 file changed, 10 insertions(+), 8 deletions(-)
drivers/clk/at91/pmc.c +10 -9
index 5aa9c1f1c886..040b70e1ffbc 100644
@@ -162,20 +162,18 @@ static int __init pmc_register_ops(void)
         if (!np)
                 return -ENODEV;
 
-       if (!of_device_is_available(np)) {
-               of_node_put(np);
-               return -ENODEV;
-       }
+       if (!of_device_is_available(np))
+               goto put_node;
+
         of_node_put(np);
 
         np = of_find_compatible_node(NULL, NULL, "atmel,sama5d2-securam");
         if (!np)
                 return -ENODEV;
 
-       if (!of_device_is_available(np)) {
-               of_node_put(np);
-               return -ENODEV;
-       }
+       if (!of_device_is_available(np))
+               goto put_node;
+
         of_node_put(np);
 
         at91_pmc_backup_suspend = of_iomap(np, 0);
@@ -187,6 +185,10 @@ static int __init pmc_register_ops(void)
         register_syscore_ops(&pmc_syscore_ops);
 
         return 0;
+
+put_node:
+       of_node_put(np);
+       return -ENODEV;
  }
  /* This has to happen before arch_initcall because of the tcb_clksrc driver */
  postcore_initcall(pmc_register_ops);
--

2.46.0

#2 lore raw
Quoted 2 lines
Quoted 2 lines

Add a jump target so that a bit of exception handling can be better reused at the end of this function implementation.

…

Quoted 2 lines

Bad track record and no real benefit from the patch:
NACK, sorry.

…

Quoted 31 lines
Quoted 31 lines

+++ b/drivers/clk/at91/pmc.c

drivers/clk/at91/pmc.c +6 -8
@@ -162,20 +162,18 @@ static int __init pmc_register_ops(void)
          if (!np)
                  return -ENODEV;
 
-       if (!of_device_is_available(np)) {
-               of_node_put(np);
-               return -ENODEV;
-       }
+       if (!of_device_is_available(np))
+               goto put_node;
+
          of_node_put(np);
 
          np = of_find_compatible_node(NULL, NULL, "atmel,sama5d2-securam");
          if (!np)
                  return -ENODEV;
 
-       if (!of_device_is_available(np)) {
-               of_node_put(np);
-               return -ENODEV;
-       }
+       if (!of_device_is_available(np))
+               goto put_node;
+
          of_node_put(np);
 
          at91_pmc_backup_suspend = of_iomap(np, 0);
@@ -187,6 +185,10 @@ static int __init pmc_register_ops(void)
          register_syscore_ops(&pmc_syscore_ops);
 
Quoted 6 lines

drivers/clk/at91/pmc.c static int __init pmc_register_ops(void) · line 192

Quoted 6 lines
drivers/clk/at91/pmc.c +4 -0
          return 0;
+
+put_node:
+       of_node_put(np);
+       return -ENODEV;
   }

…

* Do you really disagree to advice from related information sources?
https://wiki.sei.cmu.edu/confluence/display/c/MEM12-C.+Consider+using+a+goto+chain+when+leaving+a+function+on+error+when+using+and+releasing+resources?

* How do you think about to increase the application of scope-based resource management?

Regards,
Markus