Skip to contentSkip to conversation

hwmon: (ad7314) Validate leading zero bit and return error

PATCH Superseded Erik Schumacher 2 participants 2 messages Feb 20, 2025 Hardware monitoring

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hwmon: (ad7314) Validate leading zero bit and return error

A leading zero bit is sent on the bus before the temperature value is transmitted. If this bit is high, the connection might be unstable or it could mean that no AD7314 (or compatible) is connected on the bus. Return -ENXIO in that case.

---
 drivers/hwmon/ad7314.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/hwmon/ad7314.c +4 -0
index 7802bbf5f958..025846f1f18b 100644
@@ -65,6 +65,10 @@ static ssize_t ad7314_temperature_show(struct device *dev,
 		return ret;
 	switch (spi_get_device_id(chip->spi_dev)->driver_data) {
 	case ad7314:
+		if (ret & BIT(15)) {
+			/* Invalid read-out, leading zero bit is missing */
+			return -ENXIO;
+		}
 		data = (ret & AD7314_TEMP_MASK) >> AD7314_TEMP_SHIFT;
 		data = sign_extend32(data, 9);
 
Signature · 1 line
2.48.1
maintainer
#1 lore raw
Quoted 15 lines · Erik Schumacher

A leading zero bit is sent on the bus before the temperature value is transmitted. If this bit is high, the connection might be unstable or it could mean that no AD7314 (or compatible) is connected on the bus. Return -ENXIO in that case.

---
 drivers/hwmon/ad7314.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/hwmon/ad7314.c +0 -0
index 7802bbf5f958..025846f1f18b 100644

drivers/hwmon/ad7314.c static ssize_t ad7314_temperature_show(struct device *dev, · line 70

Quoted 6 lines
drivers/hwmon/ad7314.c +3 -0
@@ -65,6 +65,10 @@ static ssize_t ad7314_temperature_show(struct device *dev,
 		return ret;
 	switch (spi_get_device_id(chip->spi_dev)->driver_data) {
 	case ad7314:
+		if (ret & BIT(15)) {
+			/* Invalid read-out, leading zero bit is missing */
+			return -ENXIO;

ENXIO = No such device or address

We don't know if that is the case. -EIO seems more appropriate.

Also, AD7301 and AD7302 transmit two leading zeros. If we make this change for one of the chips supported by the driver, we should make it for all chips.

Thanks,
Guenter