Commit cbdb25cc authored by Wolfram Sang's avatar Wolfram Sang Committed by Andi Shyti
Browse files

i2c: tiny-usb: disable zero-length read messages



This driver passes the length of an i2c_msg directly to
usb_control_msg(). If the message is now a read and of length 0, it
violates the USB protocol and a warning will be printed. Enable the
I2C_AQ_NO_ZERO_LEN_READ quirk for this adapter thus forbidding 0-length
read messages altogether.

Fixes: e8c76eed ("i2c: New i2c-tiny-usb bus driver")
Signed-off-by: default avatarWolfram Sang <wsa+renesas@sang-engineering.com>
Cc: <stable@vger.kernel.org> # v2.6.22+
Signed-off-by: default avatarAndi Shyti <andi.shyti@kernel.org>
Link: https://lore.kernel.org/r/20250522064349.3823-2-wsa+renesas@sang-engineering.com
parent 56ad91c1
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -139,6 +139,11 @@ static u32 usb_func(struct i2c_adapter *adapter)
	return ret;
}

/* prevent invalid 0-length usb_control_msg */
static const struct i2c_adapter_quirks usb_quirks = {
	.flags = I2C_AQ_NO_ZERO_LEN_READ,
};

/* This is the actual algorithm we define */
static const struct i2c_algorithm usb_algorithm = {
	.xfer = usb_xfer,
@@ -247,6 +252,7 @@ static int i2c_tiny_usb_probe(struct usb_interface *interface,
	/* setup i2c adapter description */
	dev->adapter.owner = THIS_MODULE;
	dev->adapter.class = I2C_CLASS_HWMON;
	dev->adapter.quirks = &usb_quirks;
	dev->adapter.algo = &usb_algorithm;
	dev->adapter.algo_data = dev;
	snprintf(dev->adapter.name, sizeof(dev->adapter.name),