* [PATCH] media: i2c: upd64031a: add error handling for I2C read
@ 2026-03-31 13:20 Wenyuan Li
2026-05-05 12:30 ` Hans Verkuil
0 siblings, 1 reply; 2+ messages in thread
From: Wenyuan Li @ 2026-03-31 13:20 UTC (permalink / raw)
To: Mauro Carvalho Chehab
Cc: Hans Verkuil, linux-media, linux-kernel, gszhai, 25125332,
25125283, 23120469, Wenyuan Li
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
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];
}
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] media: i2c: upd64031a: add error handling for I2C read
2026-03-31 13:20 [PATCH] media: i2c: upd64031a: add error handling for I2C read Wenyuan Li
@ 2026-05-05 12:30 ` Hans Verkuil
0 siblings, 0 replies; 2+ messages in thread
From: Hans Verkuil @ 2026-05-05 12:30 UTC (permalink / raw)
To: Wenyuan Li, Mauro Carvalho Chehab
Cc: Hans Verkuil, linux-media, linux-kernel, gszhai, 25125332,
25125283, 23120469
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];
> }
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-05-05 12:30 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox