From: Wenyuan Li <2063309626@qq.com>
To: Andy Walls <awalls@md.metrocast.net>,
Mauro Carvalho Chehab <mchehab@kernel.org>
Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
Markus Elfring <Markus.Elfring@web.de>,
gszhai@bjtu.edu.cn, 25125332@bjtu.edu.cn, 25125283@bjtu.edu.cn,
23120469@bjtu.edu.cn, Wenyuan Li <2063309626@qq.com>,
stable@vger.kernel.org
Subject: [PATCH v4] media: ivtv: ir-i2c: check I2C transfer errors in get_key_adaptec()
Date: Sun, 29 Mar 2026 20:41:28 +0800 [thread overview]
Message-ID: <tencent_820AAE865CAC3FB7596055F016FD7503210A@qq.com> (raw)
In get_key_adaptec(), a command byte (0x00) is sent via
i2c_master_send() to initiate a key read, but the return value is not
checked.
If the transfer fails, the IR chip may not receive the command and the
subsequent i2c_master_recv() may return stale or invalid data. In this
case, the driver silently reports "no key", making such failures hard
to diagnose.
Check the return values of both i2c_master_send() and
i2c_master_recv(), and log errors using dev_err_ratelimited().
Short transfers are converted to -EIO while preserving existing
kernel error codes.
On error, still return 0 to keep the current behavior (no key
reported), but emit a diagnostic message to aid debugging.
Fixes: e1e2c5756563 ("[media] ivtv: Add Adaptec Remote Controller")
Cc: stable@vger.kernel.org
Signed-off-by: Wenyuan Li <2063309626@qq.com>
---
v4:
- Reword commit message to improve clarity and rationale
- No functional changes
v3:
- Add correct Fixes tag
- No functional changes
v2:
- Add error handling for i2c_master_send()
- Extend checking to i2c_master_recv()
- Use dev_err_ratelimited()
- Clarify error handling behavior
---
drivers/media/pci/ivtv/ivtv-i2c.c | 21 +++++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)
diff --git a/drivers/media/pci/ivtv/ivtv-i2c.c b/drivers/media/pci/ivtv/ivtv-i2c.c
index 28cb22d6a892..c011f2246add 100644
--- a/drivers/media/pci/ivtv/ivtv-i2c.c
+++ b/drivers/media/pci/ivtv/ivtv-i2c.c
@@ -138,11 +138,28 @@ static int get_key_adaptec(struct IR_i2c *ir, enum rc_proto *protocol,
u32 *scancode, u8 *toggle)
{
unsigned char keybuf[4];
+ int ret;
keybuf[0] = 0x00;
- i2c_master_send(ir->c, keybuf, 1);
+
+ ret = i2c_master_send(ir->c, keybuf, 1);
+ if (ret != 1) {
+ int err = ret < 0 ? ret : -EIO;
+
+ dev_err_ratelimited(&ir->c->dev, "i2c_master_send failed: %pe\n", ERR_PTR(err));
+
+ /* Preserve existing behavior: treat error as no key */
+ return 0;
+ }
+
/* poll IR chip */
- if (i2c_master_recv(ir->c, keybuf, sizeof(keybuf)) != sizeof(keybuf)) {
+ ret = i2c_master_recv(ir->c, keybuf, sizeof(keybuf));
+ if (ret != sizeof(keybuf)) {
+ int err = ret < 0 ? ret : -EIO;
+
+ dev_err_ratelimited(&ir->c->dev, "i2c_master_recv failed: %pe\n", ERR_PTR(err));
+
+ /* Preserve existing behavior */
return 0;
}
--
2.43.0
next reply other threads:[~2026-03-29 12:41 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-29 12:41 Wenyuan Li [this message]
2026-05-05 12:49 ` Sean Young
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=tencent_820AAE865CAC3FB7596055F016FD7503210A@qq.com \
--to=2063309626@qq.com \
--cc=23120469@bjtu.edu.cn \
--cc=25125283@bjtu.edu.cn \
--cc=25125332@bjtu.edu.cn \
--cc=Markus.Elfring@web.de \
--cc=awalls@md.metrocast.net \
--cc=gszhai@bjtu.edu.cn \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=stable@vger.kernel.org \
/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®