[PATCH] powerpc/powermac: Use common error handling code in kw_i2c_host_init()

Markus Elfring <[email protected]> Wed, 10 Jun 2026 19:56:39 +0200
Newsgroups org.kernel.vger.kernel-janitors,org.kernel.vger.linux-kernel,org.ozlabs.lists.linuxppc-dev
Message-ID <[email protected]>
From: Markus Elfring <[email protected]>
Date: Wed, 10 Jun 2026 19:50:08 +0200

Use an additional 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.

Signed-off-by: Markus Elfring <[email protected]>
---
 arch/powerpc/platforms/powermac/low_i2c.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/platforms/powermac/low_i2c.c b/arch/powerpc/platforms/powermac/low_i2c.c
index da72a30ab865..8daf389d72e9 100644
--- a/arch/powerpc/platforms/powermac/low_i2c.c
+++ b/arch/powerpc/platforms/powermac/low_i2c.c
@@ -504,8 +504,7 @@ static struct pmac_i2c_host_kw *__init kw_i2c_host_init(struct device_node *np)
 	if (addrp == NULL) {
 		printk(KERN_ERR "low_i2c: Can't find address for %pOF\n",
 		       np);
-		kfree(host);
-		return NULL;
+		goto free_host;
 	}
 	mutex_init(&host->mutex);
 	init_completion(&host->complete);
@@ -540,8 +539,7 @@ static struct pmac_i2c_host_kw *__init kw_i2c_host_init(struct device_node *np)
 	if (host->base == NULL) {
 		printk(KERN_ERR "low_i2c: Can't map registers for %pOF\n",
 		       np);
-		kfree(host);
-		return NULL;
+		goto free_host;
 	}
 
 	/* Make sure IRQ is disabled */
@@ -559,6 +557,10 @@ static struct pmac_i2c_host_kw *__init kw_i2c_host_init(struct device_node *np)
 	       *addrp, host->irq, np);
 
 	return host;
+
+free_host:
+	kfree(host);
+	return NULL;
 }
 
 
-- 
2.54.0