Input: adafruit-seesaw - check i2c_transfer() return value
Subsystems (3)
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.
---
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.oNo 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
@@ -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
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
-EIOfor a short transfer.Fixes 52c4e5985a73 ("Input: driver for Adafruit Seesaw Gamepad")Signed-off-by Siqi Chen <[email protected]>
Applied, thank you.
Signature · 1 line
Dmitry