Skip to contentSkip to conversation

ARM: mvebu: Adjustments for common code in two functions

PATCH New Markus Elfring 1 participant 3 messages Oct 2, 2024

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

cover ARM: mvebu: Adjustments for common code in two functions

From: Markus Elfring <[email protected]>
Date: Wed, 2 Oct 2024 19:32:23 +0200

A few update suggestions were taken into account
from static source code analysis.

Markus Elfring (2):
Call of_node_put(cpu_config_np) only once in armada_370_coherency_init() Use common of_node_put() code in mvebu_pm_suspend_init()

 arch/arm/mach-mvebu/coherency.c |  7 ++-----
 arch/arm/mach-mvebu/pm.c        | 21 +++++++++++----------
 2 files changed, 13 insertions(+), 15 deletions(-)

--
2.46.1

#1 lore raw

PATCH 1/2 ARM: mvebu: Call of_node_put(cpu_config_np) only once in armada_370_coherency_init()

From: Markus Elfring <[email protected]>
Date: Wed, 2 Oct 2024 19:02:28 +0200

An of_node_put(cpu_config_np) call was immediately used after a null pointer check for an of_iomap() call in this function implementation. Thus call such a function only once instead directly before the check.

This issue was transformed by using the Coccinelle software.

---
 arch/arm/mach-mvebu/coherency.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
arch/arm/mach-mvebu/coherency.c +2 -5
index a6b621ff0b87..262410ccc4bd 100644
@@ -137,12 +137,9 @@ static void __init armada_370_coherency_init(struct device_node *np)
 		goto exit;
 
 	cpu_config_base = of_iomap(cpu_config_np, 0);
-	if (!cpu_config_base) {
-		of_node_put(cpu_config_np);
-		goto exit;
-	}
-
 	of_node_put(cpu_config_np);
+	if (!cpu_config_base)
+		goto exit;
 
 	cpuhp_setup_state_nocalls(CPUHP_AP_ARM_MVEBU_COHERENCY,
 				  "arm/mvebu/coherency:starting",

--
2.46.1

#2 lore raw

PATCH 2/2 ARM: mvebu: Use common of_node_put() code in mvebu_pm_suspend_init()

In reply to Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 2 Oct 2024 19:15:09 +0200

Add a local variable “rc” and a label 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.

---
 arch/arm/mach-mvebu/pm.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)
arch/arm/mach-mvebu/pm.c +11 -10
index b149d9b77505..cd85f2c56836 100644
@@ -235,6 +235,7 @@ int __init mvebu_pm_suspend_init(void (*board_pm_enter)(void __iomem *sdram_reg,
 {
 	struct device_node *np;
 	struct resource res;
+	int rc;
 
 	np = of_find_compatible_node(NULL, NULL,
 				     "marvell,armada-xp-sdram-controller");
@@ -242,26 +243,26 @@ int __init mvebu_pm_suspend_init(void (*board_pm_enter)(void __iomem *sdram_reg,
 		return -ENODEV;
 
 	if (of_address_to_resource(np, 0, &res)) {
-		of_node_put(np);
-		return -ENODEV;
+		rc = -ENODEV;
+		goto put_node;
 	}
 
 	if (!request_mem_region(res.start, resource_size(&res),
 				np->full_name)) {
-		of_node_put(np);
-		return -EBUSY;
+		rc = -EBUSY;
+		goto put_node;
 	}
 
 	sdram_ctrl = ioremap(res.start, resource_size(&res));
 	if (!sdram_ctrl) {
 		release_mem_region(res.start, resource_size(&res));
-		of_node_put(np);
-		return -ENOMEM;
+		rc = -ENOMEM;
+		goto put_node;
 	}
 
-	of_node_put(np);
-
 	mvebu_board_pm_enter = board_pm_enter;
-
-	return 0;
+	rc = 0;
+put_node:
+	of_node_put(np);
+	return rc;
 }

--
2.46.1