Re: [PATCH] media: i2c: upd64031a: add error handling for I2C read
From: Hans Verkuil
Date: Tue May 05 2026 - 08:31:56 EST
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@xxxxxx>
> ---
> 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];
> }
>