From: Wenyuan Li <2063309626@qq.com>
To: 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, Wenyuan Li <2063309626@qq.com>
Subject: [PATCH] media: i2c: upd64031a: add error handling for I2C read
Date: Tue, 31 Mar 2026 21:20:41 +0800 [thread overview]
Message-ID: <tencent_F39F0BC7671F8B898AC622B86E21C4C75507@qq.com> (raw)
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
next reply other threads:[~2026-03-31 13:20 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-31 13:20 Wenyuan Li [this message]
2026-05-05 12:30 ` [PATCH] media: i2c: upd64031a: add error handling for I2C read Hans Verkuil
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_F39F0BC7671F8B898AC622B86E21C4C75507@qq.com \
--to=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