From: Sean Young <sean@mess.org>
To: Wenyuan Li <2063309626@qq.com>
Cc: Andy Walls <awalls@md.metrocast.net>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
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, stable@vger.kernel.org
Subject: Re: [PATCH v4] media: ivtv: ir-i2c: check I2C transfer errors in get_key_adaptec()
Date: Tue, 5 May 2026 13:49:56 +0100 [thread overview]
Message-ID: <afnndDiYeNmHEjTE@extorris.mess.org> (raw)
In-Reply-To: <tencent_820AAE865CAC3FB7596055F016FD7503210A@qq.com>
On Sun, Mar 29, 2026 at 08:41:28PM +0800, Wenyuan Li wrote:
> 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));
get_key_adaptec() is called from ir_key_poll(), which already logs errors
with dev_warn(). Other i2c key handlers simply return an error and let
ir_key_poll() log the error code. That's better than duplicating a dev_err()
or dev_warn() here.
> +
> + /* Preserve existing behavior: treat error as no key */
> + return 0;
> + }
Simply return the error.
> +
> /* 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;
Same here - simply return the error (or -EIO if rc >= 0).
Thanks,
Sean
prev parent reply other threads:[~2026-05-05 12:49 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-29 12:41 [PATCH v4] media: ivtv: ir-i2c: check I2C transfer errors in get_key_adaptec() Wenyuan Li
2026-05-05 12:49 ` Sean Young [this message]
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=afnndDiYeNmHEjTE@extorris.mess.org \
--to=sean@mess.org \
--cc=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