[PATCH RESEND] bbc_i2c: Fix exception handling in attach_one_i2c()

From: Markus Elfring
Date: Tue Mar 04 2025 - 14:50:49 EST


From: Markus Elfring <elfring@xxxxxxxxxxxxxxxxxxxxx>
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@xxxxxxxxxxxxxxxxxxxxx>
---
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