Linux Media Controller development
 help / color / mirror / Atom feed
From: Hans Verkuil <hverkuil+cisco@kernel.org>
To: Wenyuan Li <2063309626@qq.com>,
	Mauro Carvalho Chehab <mchehab@kernel.org>
Cc: Hans Verkuil <hverkuil@kernel.org>,
	linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
	gszhai@bjtu.edu.cn, 25125332@bjtu.edu.cn, 25125283@bjtu.edu.cn,
	23120469@bjtu.edu.cn
Subject: Re: [PATCH] media: i2c: upd64031a: add error handling for I2C read
Date: Tue, 5 May 2026 14:30:36 +0200	[thread overview]
Message-ID: <d99168b1-cc8a-4041-b183-17fcb90b2913@kernel.org> (raw)
In-Reply-To: <tencent_F39F0BC7671F8B898AC622B86E21C4C75507@qq.com>

On 3/31/26 15:20, Wenyuan Li wrote:
> In upd64031a_read(), i2c_master_recv() is called without checking
> its return value. If the I2C read fails, the function proceeds to
> return invalid data from the buffer.
> 
> Add proper error checking:
> - Check if all 2 bytes were read successfully
> - Log the error with %pe format
> - Return 0xff (the same as invalid register) on error

I'm not picking this up: it's not worth the effort, and this read is
used for debugging only. Failures won't hurt anything.

Ditto for your upd64083 patch.

Regards,

	Hans

> 
> Signed-off-by: Wenyuan Li <2063309626@qq.com>
> ---
>  drivers/media/i2c/upd64031a.c | 11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/media/i2c/upd64031a.c b/drivers/media/i2c/upd64031a.c
> index a178af46e695..ec9179cf9b69 100644
> --- a/drivers/media/i2c/upd64031a.c
> +++ b/drivers/media/i2c/upd64031a.c
> @@ -73,10 +73,19 @@ static u8 upd64031a_read(struct v4l2_subdev *sd, u8 reg)
>  {
>  	struct i2c_client *client = v4l2_get_subdevdata(sd);
>  	u8 buf[2];
> +	int ret;
>  
>  	if (reg >= sizeof(buf))
>  		return 0xff;
> -	i2c_master_recv(client, buf, 2);
> +
> +	ret = i2c_master_recv(client, buf, 2);
> +	if (ret != sizeof(buf)) {
> +		int err = ret < 0 ? ret : -EIO;
> +
> +		v4l2_err(sd, "I2C read failed: %pe\n", ERR_PTR(err));
> +		return 0xff;
> +	}
> +
>  	return buf[reg];
>  }
>  


      reply	other threads:[~2026-05-05 12:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-31 13:20 [PATCH] media: i2c: upd64031a: add error handling for I2C read Wenyuan Li
2026-05-05 12:30 ` Hans Verkuil [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=d99168b1-cc8a-4041-b183-17fcb90b2913@kernel.org \
    --to=hverkuil+cisco@kernel.org \
    --cc=2063309626@qq.com \
    --cc=23120469@bjtu.edu.cn \
    --cc=25125283@bjtu.edu.cn \
    --cc=25125332@bjtu.edu.cn \
    --cc=gszhai@bjtu.edu.cn \
    --cc=hverkuil@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@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