[PATCH] sh: kfr2r09: Fix USB gadget I2C adapter reference leak
From: Haoxiang Li
Date: Tue Jun 23 2026 - 00:30:04 EST
kfr2r09_usb0_gadget_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: 5a1c4cb5bc22 ("sh: add r8a66597 usb0 gadget to the kfr2r09 board")
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..66c0015ec726 100644
--- a/arch/sh/boards/mach-kfr2r09/setup.c
+++ b/arch/sh/boards/mach-kfr2r09/setup.c
@@ -368,7 +368,7 @@ static int kfr2r09_usb0_gadget_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;
@@ -377,7 +377,7 @@ static int kfr2r09_usb0_gadget_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 << 1);
buf[0] = 0x13;
@@ -387,9 +387,14 @@ static int kfr2r09_usb0_gadget_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;
}
static int kfr2r09_serial_i2c_setup(void)
--
2.25.1