mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Siqi Chen <chensiqi@uniontech.com>
To: Anshul Dalal <anshulusr@gmail.com>,
	Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: "Thomas Weißschuh" <linux@weissschuh.net>,
	linux-input@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] Input: adafruit-seesaw - check i2c_transfer() return value
Date: Tue, 24 Nov 2026 13:43:44 +0800	[thread overview]
Message-ID: <20261124054344.1067234-1-chensiqi@uniontech.com> (raw)

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")
Signed-off-by: Siqi Chen <chensiqi@uniontech.com>
---
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(+)

diff --git a/drivers/input/joystick/adafruit-seesaw.c b/drivers/input/joystick/adafruit-seesaw.c
index 897e14bb61f7..8374381dcc87 100644
--- a/drivers/input/joystick/adafruit-seesaw.c
+++ b/drivers/input/joystick/adafruit-seesaw.c
@@ -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;
 }
-- 
2.20.1

             reply	other threads:[~2026-11-24  5:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24  5:43 Siqi Chen [this message]
2026-11-24  6:14 ` Dmitry Torokhov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261124054344.1067234-1-chensiqi@uniontech.com \
    --to=chensiqi@uniontech.com \
    --cc=anshulusr@gmail.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@weissschuh.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®