Skip to contentSkip to conversation

media: solo6x10: Initialize I2C read data

PATCH NAK Ruoyu Wang 2 participants 2 messages Aug 13 – Aug 14

Subsystems (2)
lore
Share & tools
lore

Ruoyu Wang

author
#0 lore raw

PATCH 1/1 media: solo6x10: Initialize I2C read data

solo_i2c_readbyte() ignores the number of messages completed by i2c_transfer(). If the transfer stops before the read message completes, the adapter returns a short count without storing anything in data. The helper then returns an uninitialized stack byte, so chip detection and user-visible control and status reads can consume unpredictable values.

The helper returns a byte and has no error channel. Preserve that API and initialize data to zero as a deterministic fallback. Successful reads still overwrite it, while failed or partial transfers no longer expose indeterminate stack contents.

This issue was found by a static analysis checker and confirmed by manual source review.

Fixes faa4fd2a0951 ("Staging: solo6x10: New driver (staging) for Softlogic 6x10")
---
 drivers/media/pci/solo6x10/solo6x10-i2c.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/pci/solo6x10/solo6x10-i2c.c +1 -1
index 7db785e9c99791..1b37dccd137a05 100644
@@ -25,7 +25,7 @@
 u8 solo_i2c_readbyte(struct solo_dev *solo_dev, int id, u8 addr, u8 off)
 {
 	struct i2c_msg msgs[2];
-	u8 data;
+	u8 data = 0;
 
 	msgs[0].flags = 0;
 	msgs[0].addr = addr;
Signature · 1 line
2.51.0
maintainer Nacked-by on v1 1/1 NAK
#1 lore raw
Quoted 36 lines · Ruoyu Wang

solo_i2c_readbyte() ignores the number of messages completed by i2c_transfer(). If the transfer stops before the read message completes, the adapter returns a short count without storing anything in data. The helper then returns an uninitialized stack byte, so chip detection and user-visible control and status reads can consume unpredictable values.

The helper returns a byte and has no error channel. Preserve that API and initialize data to zero as a deterministic fallback. Successful reads still overwrite it, while failed or partial transfers no longer expose indeterminate stack contents.

This issue was found by a static analysis checker and confirmed by manual source review.

Fixes faa4fd2a0951 ("Staging: solo6x10: New driver (staging) for Softlogic 6x10")
---
 drivers/media/pci/solo6x10/solo6x10-i2c.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/pci/solo6x10/solo6x10-i2c.c +1 -1
index 7db785e9c99791..1b37dccd137a05 100644
@@ -25,7 +25,7 @@
 u8 solo_i2c_readbyte(struct solo_dev *solo_dev, int id, u8 addr, u8 off)
 {
 	struct i2c_msg msgs[2];
-	u8 data;
+	u8 data = 0;
 
 	msgs[0].flags = 0;
 	msgs[0].addr = addr;
Signature · 1 line
2.51.0

There's no guarantee that the buffer would remain zero on an error condition.

But even then returning a zero on error here is a bad idea, the interface needs some change.