sparclinux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Markus Elfring <Markus.Elfring@web.de>
To: kernel-janitors@vger.kernel.org, sparclinux@vger.kernel.org,
	Andreas Larsson <andreas@gaisler.com>,
	Christopher Alexander Tobias Schulze <cat.schulze@alice-dsl.net>,
	"David S. Miller" <davem@davemloft.net>
Cc: cocci@inria.fr, LKML <linux-kernel@vger.kernel.org>,
	"Jeff Johnson" <jeff.johnson@oss.qualcomm.com>,
	"Uwe Kleine-König" <u.kleine-koenig@baylibre.com>
Subject: [PATCH RESEND] bbc_i2c: Fix exception handling in attach_one_i2c()
Date: Tue, 4 Mar 2025 20:50:06 +0100	[thread overview]
Message-ID: <f7d11fd7-6b41-4dbd-b7dc-518fe6e6426f@web.de> (raw)
In-Reply-To: <21e58abb-f215-b9b7-ffe8-236dd40c6bd2@web.de>

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Tue, 21 Mar 2023 21:12:29 +0100

The label “fail” was used to jump to another pointer check despite of
the detail in the implementation of the function “attach_one_i2c”
that it was determined already that a corresponding variable contained
a null pointer because of a failed call of the function “of_ioremap”.

* Thus use more appropriate labels instead.

* Delete a redundant check.


This issue was detected by using the Coccinelle software.

Fixes: 5cdceab3d5e0 ("bbc-i2c: Fix BBC I2C envctrl on SunBlade 2000")
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/sbus/char/bbc_i2c.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/sbus/char/bbc_i2c.c b/drivers/sbus/char/bbc_i2c.c
index 537e55cd038d..03e29f2760b2 100644
--- a/drivers/sbus/char/bbc_i2c.c
+++ b/drivers/sbus/char/bbc_i2c.c
@@ -306,19 +306,19 @@ static struct bbc_i2c_bus * attach_one_i2c(struct platform_device *op, int index

 	bp->i2c_control_regs = of_ioremap(&op->resource[0], 0, 0x2, "bbc_i2c_regs");
 	if (!bp->i2c_control_regs)
-		goto fail;
+		goto free_bus;

 	if (op->num_resources == 2) {
 		bp->i2c_bussel_reg = of_ioremap(&op->resource[1], 0, 0x1, "bbc_i2c_bussel");
 		if (!bp->i2c_bussel_reg)
-			goto fail;
+			goto unmap_io_control_regs;
 	}

 	bp->waiting = 0;
 	init_waitqueue_head(&bp->wq);
 	if (request_irq(op->archdata.irqs[0], bbc_i2c_interrupt,
 			IRQF_SHARED, "bbc_i2c", bp))
-		goto fail;
+		goto recheck_bussel_reg;

 	bp->index = index;
 	bp->op = op;
@@ -348,11 +348,12 @@ static struct bbc_i2c_bus * attach_one_i2c(struct platform_device *op, int index

 	return bp;

-fail:
+recheck_bussel_reg:
 	if (bp->i2c_bussel_reg)
 		of_iounmap(&op->resource[1], bp->i2c_bussel_reg, 1);
-	if (bp->i2c_control_regs)
-		of_iounmap(&op->resource[0], bp->i2c_control_regs, 2);
+unmap_io_control_regs:
+	of_iounmap(&op->resource[0], bp->i2c_control_regs, 2);
+free_bus:
 	kfree(bp);
 	return NULL;
 }
--
2.40.0


           reply	other threads:[~2025-03-04 19:50 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <21e58abb-f215-b9b7-ffe8-236dd40c6bd2@web.de>]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f7d11fd7-6b41-4dbd-b7dc-518fe6e6426f@web.de \
    --to=markus.elfring@web.de \
    --cc=andreas@gaisler.com \
    --cc=cat.schulze@alice-dsl.net \
    --cc=cocci@inria.fr \
    --cc=davem@davemloft.net \
    --cc=jeff.johnson@oss.qualcomm.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sparclinux@vger.kernel.org \
    --cc=u.kleine-koenig@baylibre.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).