[PATCH] sh: kfr2r09: Fix serial I2C adapter reference leak
From: Haoxiang Li
Date: Tue Jun 23 2026 - 00:33:17 EST
kfr2r09_serial_i2c_setup() gets I2C adapter 0 with i2c_get_adapter(),
but returns without dropping the reference. Release the adapter with
i2c_put_adapter() before returning from all paths after i2c_get_adapter()
succeeds.
Fixes: e6d8460aca63 ("sh: Improve kfr2r09 serial port setup code")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Haoxiang Li <haoxiang_li2024@xxxxxxx>
---
arch/sh/boards/mach-kfr2r09/setup.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/arch/sh/boards/mach-kfr2r09/setup.c b/arch/sh/boards/mach-kfr2r09/setup.c
index 70236859919d..56381fddbbe7 100644
--- a/arch/sh/boards/mach-kfr2r09/setup.c
+++ b/arch/sh/boards/mach-kfr2r09/setup.c
@@ -411,7 +411,7 @@ static int kfr2r09_serial_i2c_setup(void)
msg.flags = 0;
ret = i2c_transfer(a, &msg, 1);
if (ret != 1)
- return -ENODEV;
+ goto err;
buf[0] = 0;
msg.addr = 0x09;
@@ -420,7 +420,7 @@ static int kfr2r09_serial_i2c_setup(void)
msg.flags = I2C_M_RD;
ret = i2c_transfer(a, &msg, 1);
if (ret != 1)
- return -ENODEV;
+ goto err;
buf[1] = buf[0] | (1 << 6);
buf[0] = 0x13;
@@ -430,9 +430,14 @@ static int kfr2r09_serial_i2c_setup(void)
msg.flags = 0;
ret = i2c_transfer(a, &msg, 1);
if (ret != 1)
- return -ENODEV;
+ goto err;
+ i2c_put_adapter(a);
return 0;
+
+err:
+ i2c_put_adapter(a);
+ return -ENODEV;
}
#else
static int kfr2r09_usb0_gadget_i2c_setup(void)
--
2.25.1