Skip to contentSkip to conversation

x86/hpet: Use common error handling code in hpet_create_irq_domain()

PATCH In review Markus Elfring 2 participants 2 messages Jun 9 – Sep 25

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

PATCH 1/1 x86/hpet: Use common error handling code in hpet_create_irq_domain()

From: Markus Elfring <[email protected]>
Date: Tue, 9 Jun 2026 13:28:18 +0200

Use additional labels 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/x86/kernel/hpet.c | 27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)
arch/x86/kernel/hpet.c +14 -13
index 8dc7b710e125..ac7e06b40a16 100644
@@ -553,30 +553,31 @@ static struct irq_domain *hpet_create_irq_domain(int hpet_id)
 
 	fn = irq_domain_alloc_named_id_fwnode(hpet_msi_controller.name,
 					      hpet_id);
-	if (!fn) {
-		kfree(domain_info);
-		return NULL;
-	}
+	if (!fn)
+		goto free_info;
 
 	fwspec.fwnode = fn;
 	fwspec.param_count = 1;
 	fwspec.param[0] = hpet_id;
 
 	parent = irq_find_matching_fwspec(&fwspec, DOMAIN_BUS_GENERIC_MSI);
-	if (!parent) {
-		irq_domain_free_fwnode(fn);
-		kfree(domain_info);
-		return NULL;
-	}
+	if (!parent)
+		goto free_fwnode;
+
 	if (parent != x86_vector_domain)
 		hpet_msi_controller.name = "IR-HPET-MSI";
 
 	d = msi_create_irq_domain(fn, domain_info, parent);
-	if (!d) {
-		irq_domain_free_fwnode(fn);
-		kfree(domain_info);
-	}
+	if (!d)
+		goto free_fwnode;
+
 	return d;
+
+free_fwnode:
+	irq_domain_free_fwnode(fn);
+free_info:
+	kfree(domain_info);
+	return NULL;
 }
 
 static inline int hpet_dev_id(struct irq_domain *domain)
Signature · 1 line
2.54.0
#1 lore raw

Hi Markus,

Thanks for the patch.

While consolidating the error paths using gotos can sometimes provide better simplicity and readability in codes, the implicit fall-through from free_fwnode label straight into free_info feels a bit error-prone for future maintenance.

If someone later modifies the code and uses these labels, it could lead to unintended side effects or a double-free error. Although the syntax of the original code blocks involves repetition, it is readable and safe.

Personally, I believe the original code is cleaner and less risky to maintain in the long run.

Sincerely,
Habil Eren Türker <[email protected]>