[PATCH] i2c: usbio: check the return value of usbio_acquire()
From: YuanZhe Liu
Date: Sun Nov 15 2026 - 21:09:34 EST
usbio_i2c_xfer() ignores the return value of usbio_acquire() and always
calls usbio_release() on the way out.
usbio_acquire() returns -ENODEV once the USBIO bridge has been
disconnected: usbio_disconnect() sets client->bridge to NULL, and
usbio_acquire() then only drops client->mutex and returns without
taking usbio->bulk_mutex or the runtime PM reference of the USB device.
The transfer is nevertheless issued. usbio_bulk_msg() dereferences the
NULL client->bridge in its packet size check and the kernel faults on
usbio->txbuf_len. The matching usbio_release() then drops a runtime PM
reference that was never taken, which is reported as "Runtime PM usage
count underflow!", and unlocks a mutex that nobody holds.
Propagate the error instead, so that a transfer racing with the
disconnect returns -ENODEV without touching the bridge.
A NULL pointer dereference in usbio_bulk_msg() was observed when the
bridge was unplugged while i2c-dev was reading from the adapter:
usbio-bridge 1-1:1.0: Bulk out failed: -19
usbio-bridge 1-1:1.0: Runtime PM usage count underflow!
usb 1-1: USB disconnect, device number 3
general protection fault, probably for non-canonical address
KASAN: null-ptr-deref in range [0x0000000000000060-0x0000000000000067]
RIP: 0010:usbio_bulk_msg+0xce/0x9f0
Call Trace:
usbio_i2c_init
usbio_i2c_xfer
__i2c_transfer
i2cdev_read
vfs_read
Fixes: daf161343a39 ("i2c: Add Intel USBIO I2C driver")
Cc: stable@xxxxxxxxxxxxxxx
Co-developed-by: Bin Yu <byu@xxxxxxxxxxxxx>
Signed-off-by: Bin Yu <byu@xxxxxxxxxxxxx>
Co-developed-by: Cheng Wen <wencheng@xxxxxxxxxxxxx>
Signed-off-by: Cheng Wen <wencheng@xxxxxxxxxxxxx>
Signed-off-by: YuanZhe Liu <25031212351@xxxxxxxxxxxxxxxxx>
---
drivers/i2c/busses/i2c-usbio.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/i2c/busses/i2c-usbio.c b/drivers/i2c/busses/i2c-usbio.c
index 259754e5fd05..232397efe8a4 100644
--- a/drivers/i2c/busses/i2c-usbio.c
+++ b/drivers/i2c/busses/i2c-usbio.c
@@ -178,7 +178,9 @@ static int usbio_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int nu
struct usbio_i2c *i2c = i2c_get_adapdata(adap);
int ret;
- usbio_acquire(i2c->adev);
+ ret = usbio_acquire(i2c->adev);
+ if (ret)
+ return ret;
ret = usbio_i2c_init(adap, msgs);
if (ret)
--
2.34.1