mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v3] media: ir-i2c: add error handling for I2C send in get_key_adaptec()
@ 2026-03-27 10:30 Wenyuan Li
  2026-03-27 14:15 ` Markus Elfring
  0 siblings, 1 reply; 3+ messages in thread
From: Wenyuan Li @ 2026-03-27 10:30 UTC (permalink / raw)
  To: Andy Walls, Mauro Carvalho Chehab
  Cc: Sean Young, linux-media, linux-kernel, Markus Elfring, gszhai,
	25125332, 25125283, 23120469, Wenyuan Li, stable

In get_key_adaptec(), a command byte (0x00) is sent to the IR chip via
i2c_master_send() to initiate a key read. However, the return value of
i2c_master_send() is not checked.

If this I2C transfer fails, the IR chip may not receive the read
command, causing the subsequent i2c_master_recv() to read stale or
invalid data. The driver would then return 0 (no key) without logging
the error, making debugging difficult.

Fix this by:
- Checking the return value of i2c_master_send()
- Converting partial sends to -EIO while preserving kernel error codes
- Adding dev_err_ratelimited() logging with %pe format
- Adding similar error logging for the i2c_master_recv() path

If the send fails, return 0 to maintain the existing behavior (no key
detected), but log the error for debugging purposes.

Fixes: e1e2c5756563 ("[media] ivtv: Add Adaptec Remote Controller")
Cc: stable@vger.kernel.org
Signed-off-by: Wenyuan Li <2063309626@qq.com>

---
v2:
- Add error handling for i2c_master_send() as suggested
- Extend checking to i2c_master_recv()
- Use dev_err_ratelimited() instead of dev_err()
- Clarify error handling behavior
- Drop incorrect Fixes tag

---
v3:
-Add correct Fixes tag
---
 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));
+
+		/* Preserve existing behavior: treat error as no key */
+		return 0;
+	}
+
 	/* 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;
 	}
 
-- 
2.43.0



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v3] media: ir-i2c: add error handling for I2C send in get_key_adaptec()
  2026-03-27 10:30 [PATCH v3] media: ir-i2c: add error handling for I2C send in get_key_adaptec() Wenyuan Li
@ 2026-03-27 14:15 ` Markus Elfring
  0 siblings, 0 replies; 3+ messages in thread
From: Markus Elfring @ 2026-03-27 14:15 UTC (permalink / raw)
  To: Wenyuan Li, Mauro Carvalho Chehab, Andy Walls, linux-media
  Cc: stable, LKML, Sean Young, gszhai, 23120469, 25125332, 25125283

…
> Fix this by:
> - Checking the return value of i2c_master_send()
> - Converting partial sends to -EIO while preserving kernel error codes
> - Adding dev_err_ratelimited() logging with %pe format
> - Adding similar error logging for the i2c_master_recv() path

See also once more:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v7.0-rc5#n94> ---
> v2:
> ---
> v3:
> ---
>  drivers/media/pci/ivtv/ivtv-i2c.c | 21 +++++++++++++++++++--
…

How do you think about to avoid the specification of redundant marker lines?

Regards,
Markus

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v3] media: ir-i2c: add error handling for I2C send in get_key_adaptec()
@ 2026-03-27 14:41 Wenyuan Li
  0 siblings, 0 replies; 3+ messages in thread
From: Wenyuan Li @ 2026-03-27 14:41 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linux-media, linux-kernel, Markus Elfring, gszhai, 25125332,
	25125283, 23120469, Wenyuan Li, stable

In get_key_adaptec(), a command byte (0x00) is sent to the IR chip via
i2c_master_send() to initiate a key read. However, the return value of
i2c_master_send() is not checked.

If this I2C transfer fails, the IR chip may not receive the read
command, causing the subsequent i2c_master_recv() to read stale or
invalid data. The driver would then return 0 (no key) without logging
the error, making debugging difficult.

Fix this by:
- Checking the return value of i2c_master_send()
- Converting partial sends to -EIO while preserving kernel error codes
- Adding dev_err_ratelimited() logging with %pe format
- Adding similar error logging for the i2c_master_recv() path

If the send fails, return 0 to maintain the existing behavior (no key
detected), but log the error for debugging purposes.

Fixes: e1e2c5756563 ("[media] ivtv: Add Adaptec Remote Controller")
Cc: stable@vger.kernel.org
Signed-off-by: Wenyuan Li <2063309626@qq.com>

---
v2:
- Add error handling for i2c_master_send() as suggested
- Extend checking to i2c_master_recv()
- Use dev_err_ratelimited() instead of dev_err()
- Clarify error handling behavior
- Drop incorrect Fixes tag

v3:
-Add correct Fixes tag
---
 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));
+
+		/* Preserve existing behavior: treat error as no key */
+		return 0;
+	}
+
 	/* 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;
 	}
 
-- 
2.43.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-03-27 14:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-03-27 10:30 [PATCH v3] media: ir-i2c: add error handling for I2C send in get_key_adaptec() Wenyuan Li
2026-03-27 14:15 ` Markus Elfring
2026-03-27 14:41 Wenyuan Li

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox