Skip to contentSkip to conversation

Input: adafruit-seesaw - check i2c_transfer() return value

PATCH Applied Siqi Chen 2 participants 2 messages Nov 24

Subsystems (3)
lore
Share & tools
lore

Siqi Chen

author
#0 lore raw

PATCH 1/1 Input: adafruit-seesaw - check i2c_transfer() return value

i2c_transfer() returns the number of messages transferred or a negative error code. The seesaw register read helper only checks for negative errors and therefore treats short transfers as successful.

If only the register-address message is transferred, callers consume data that was not read from the device. This can result in bogus button or axis events.

Require both messages to be transferred, preserve negative error codes, and return -EIO for a short transfer.

Fixes 52c4e5985a73 ("Input: driver for Adafruit Seesaw Gamepad")

---
OpenCode was used to identify the issue and draft the code and changelog.

Compile-tested with CONFIG_I2C=y and CONFIG_JOYSTICK_SEESAW=m using:

  make O=/tmp/opencode/linux-build-seesaw W=1 \
       drivers/input/joystick/adafruit-seesaw.o

No hardware or I2C fault-injection testing was performed.

 drivers/input/joystick/adafruit-seesaw.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/input/joystick/adafruit-seesaw.c +2 -0
index 897e14bb61f7..8374381dcc87 100644
@@ -107,6 +107,8 @@ static int seesaw_register_read(struct i2c_client *client, u16 reg, void *buf,
 			   ARRAY_SIZE(message_buf));
 	if (ret < 0)
 		return ret;
+	if (ret != ARRAY_SIZE(message_buf))
+		return -EIO;
 
 	return 0;
 }
Signature · 1 line
2.20.1
maintainer Applied
#1 lore raw
Quoted 8 lines · Siqi Chen

i2c_transfer() returns the number of messages transferred or a negative error code. The seesaw register read helper only checks for negative errors and therefore treats short transfers as successful.

If only the register-address message is transferred, callers consume data that was not read from the device. This can result in bogus button or axis events.

Quoted 5 lines

Require both messages to be transferred, preserve negative error codes, and return -EIO for a short transfer.

Fixes 52c4e5985a73 ("Input: driver for Adafruit Seesaw Gamepad")

Applied, thank you.

Signature · 1 line
Dmitry