public inbox for linux-i2c@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] i2c: tiny-usb: disable zero-length read messages
@ 2025-05-22  6:43 Wolfram Sang
  2025-05-22  7:00 ` Wolfram Sang
  0 siblings, 1 reply; 4+ messages in thread
From: Wolfram Sang @ 2025-05-22  6:43 UTC (permalink / raw)
  To: linux-i2c
  Cc: Alan Stern, Nikita Zhandarovich, Wolfram Sang, Till Harbaum,
	Andi Shyti

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.

Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
 drivers/i2c/busses/i2c-tiny-usb.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/i2c/busses/i2c-tiny-usb.c b/drivers/i2c/busses/i2c-tiny-usb.c
index 0f2ed181b266..0cc7c0a816fc 100644
--- a/drivers/i2c/busses/i2c-tiny-usb.c
+++ b/drivers/i2c/busses/i2c-tiny-usb.c
@@ -138,6 +138,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,
@@ -246,6 +251,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),
-- 
2.47.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] i2c: tiny-usb: disable zero-length read messages
  2025-05-22  6:43 [PATCH] i2c: tiny-usb: disable zero-length read messages Wolfram Sang
@ 2025-05-22  7:00 ` Wolfram Sang
  2025-05-23  7:56   ` Andi Shyti
  0 siblings, 1 reply; 4+ messages in thread
From: Wolfram Sang @ 2025-05-22  7:00 UTC (permalink / raw)
  To: linux-i2c; +Cc: Alan Stern, Nikita Zhandarovich, Till Harbaum, Andi Shyti

[-- Attachment #1: Type: text/plain, Size: 500 bytes --]

On Thu, May 22, 2025 at 08:43:49AM +0200, Wolfram Sang wrote:
> 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.
> 
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>

Fixes: e8c76eed2ecd ("i2c: New i2c-tiny-usb bus driver")


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] i2c: tiny-usb: disable zero-length read messages
  2025-05-22  7:00 ` Wolfram Sang
@ 2025-05-23  7:56   ` Andi Shyti
  2025-05-23  8:16     ` Wolfram Sang
  0 siblings, 1 reply; 4+ messages in thread
From: Andi Shyti @ 2025-05-23  7:56 UTC (permalink / raw)
  To: Wolfram Sang, linux-i2c, Alan Stern, Nikita Zhandarovich,
	Till Harbaum, Andi Shyti

Hi Wolfram,

On Thu, May 22, 2025 at 09:00:12AM +0200, Wolfram Sang wrote:
> On Thu, May 22, 2025 at 08:43:49AM +0200, Wolfram Sang wrote:
> > 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.
> > 
> > Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
> 
> Fixes: e8c76eed2ecd ("i2c: New i2c-tiny-usb bus driver")

I will queue these up for next week. There are a few more fixes
that I deliberately left out of this week's pull request to give
them time to be properly reviewed and tested.

Thanks,
Andi

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] i2c: tiny-usb: disable zero-length read messages
  2025-05-23  7:56   ` Andi Shyti
@ 2025-05-23  8:16     ` Wolfram Sang
  0 siblings, 0 replies; 4+ messages in thread
From: Wolfram Sang @ 2025-05-23  8:16 UTC (permalink / raw)
  To: Andi Shyti; +Cc: linux-i2c, Alan Stern, Nikita Zhandarovich, Till Harbaum

[-- Attachment #1: Type: text/plain, Size: 442 bytes --]


> > > Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
> > 
> > Fixes: e8c76eed2ecd ("i2c: New i2c-tiny-usb bus driver")
> 
> I will queue these up for next week. There are a few more fixes
> that I deliberately left out of this week's pull request to give
> them time to be properly reviewed and tested.

Sure thing, this problem has been around for years. It can wait a little
more and will go to stable anyhow.


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-05-23  8:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-22  6:43 [PATCH] i2c: tiny-usb: disable zero-length read messages Wolfram Sang
2025-05-22  7:00 ` Wolfram Sang
2025-05-23  7:56   ` Andi Shyti
2025-05-23  8:16     ` Wolfram Sang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox