Skip to contentSkip to conversation

firmware: arm_scmi: Use common error handling code in __scmi_device_create()

PATCH In review Markus Elfring 2 participants 2 messages Jun 11

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

PATCH 1/1 firmware: arm_scmi: Use common error handling code in __scmi_device_create()

From: Markus Elfring <[email protected]>
Date: Thu, 11 Jun 2026 10:27:45 +0200

Use an additional label so that a bit of exception handling can be better reused at the end of an if branch.

This issue was detected by using the Coccinelle software.

---
 drivers/firmware/arm_scmi/bus.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/firmware/arm_scmi/bus.c +3 -4
index 793be9eabaed..8c20ed1a8243 100644
@@ -450,14 +450,13 @@ __scmi_device_create(struct device_node *np, struct device *parent,
 		return NULL;
 
 	scmi_dev->name = kstrdup_const(name ?: "unknown", GFP_KERNEL);
-	if (!scmi_dev->name) {
-		kfree(scmi_dev);
-		return NULL;
-	}
+	if (!scmi_dev->name)
+		goto free_scmi_dev;
 
 	id = ida_alloc_min(&scmi_bus_id, 1, GFP_KERNEL);
 	if (id < 0) {
 		kfree_const(scmi_dev->name);
+free_scmi_dev:
 		kfree(scmi_dev);
 		return NULL;
 	}
Signature · 1 line
2.54.0
#1 lore raw
Quoted 6 lines · Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 11 Jun 2026 10:27:45 +0200

Use an additional label so that a bit of exception handling can be better reused at the end of an if branch.

Hi,

Quoted 17 lines

This issue was detected by using the Coccinelle software.

---
 drivers/firmware/arm_scmi/bus.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/firmware/arm_scmi/bus.c +0 -2
index 793be9eabaed..8c20ed1a8243 100644
@@ -450,14 +450,13 @@ __scmi_device_create(struct device_node *np, struct device *parent,
 		return NULL;
 
 	scmi_dev->name = kstrdup_const(name ?: "unknown", GFP_KERNEL);
-	if (!scmi_dev->name) {
-		kfree(scmi_dev);

drivers/firmware/arm_scmi/bus.c __scmi_device_create(struct device_node *np, struct device *parent, · line 460

Quoted 10 lines
drivers/firmware/arm_scmi/bus.c +3 -2
-		return NULL;
-	}
+	if (!scmi_dev->name)
+		goto free_scmi_dev;
 
 	id = ida_alloc_min(&scmi_bus_id, 1, GFP_KERNEL);
 	if (id < 0) {
 		kfree_const(scmi_dev->name);
+free_scmi_dev:
 		kfree(scmi_dev);

I can understand the aim, but jumping in the middle of another block just to reuse the cleanup statement is far less readable (and ugly)

Cleanup handlers probably a better solution here...but I have NOT looked at all the sorrounding code here recently...so I maybe wrong and keeping the current code could be even bette.

Thanks,
Cristian