Skip to content

Commit e278d5e

Browse files
iris-erscgroeck
authored andcommitted
hwmon: (ad7314) Validate leading zero bits and return error
Leading zero bits are sent on the bus before the temperature value is transmitted. If any of these bits are high, the connection might be unstable or there could be no AD7314 / ADT730x (or compatible) at all. Return -EIO in that case. Signed-off-by: Erik Schumacher <erik.schumacher@iris-sensing.com> Fixes: 4f3a659 ("hwmon: AD7314 driver (ported from IIO)") Link: https://lore.kernel.org/r/24a50c2981a318580aca8f50d23be7987b69ea00.camel@iris-sensing.com Signed-off-by: Guenter Roeck <linux@roeck-us.net>
1 parent 1c7932d commit e278d5e

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

drivers/hwmon/ad7314.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@
2222
*/
2323
#define AD7314_TEMP_MASK 0x7FE0
2424
#define AD7314_TEMP_SHIFT 5
25+
#define AD7314_LEADING_ZEROS_MASK BIT(15)
2526

2627
/*
2728
* ADT7301 and ADT7302 temperature masks
2829
*/
2930
#define ADT7301_TEMP_MASK 0x3FFF
31+
#define ADT7301_LEADING_ZEROS_MASK (BIT(15) | BIT(14))
3032

3133
enum ad7314_variant {
3234
adt7301,
@@ -65,12 +67,20 @@ static ssize_t ad7314_temperature_show(struct device *dev,
6567
return ret;
6668
switch (spi_get_device_id(chip->spi_dev)->driver_data) {
6769
case ad7314:
70+
if (ret & AD7314_LEADING_ZEROS_MASK) {
71+
/* Invalid read-out, leading zero part is missing */
72+
return -EIO;
73+
}
6874
data = (ret & AD7314_TEMP_MASK) >> AD7314_TEMP_SHIFT;
6975
data = sign_extend32(data, 9);
7076

7177
return sprintf(buf, "%d\n", 250 * data);
7278
case adt7301:
7379
case adt7302:
80+
if (ret & ADT7301_LEADING_ZEROS_MASK) {
81+
/* Invalid read-out, leading zero part is missing */
82+
return -EIO;
83+
}
7484
/*
7585
* Documented as a 13 bit twos complement register
7686
* with a sign bit - which is a 14 bit 2's complement

0 commit comments

Comments
 (0)