* [PATCH v2] hwmon: (ad7314) Validate leading zero bits and return error
@ 2025-02-24 9:19 Erik Schumacher
2025-03-02 16:41 ` Guenter Roeck
0 siblings, 1 reply; 2+ messages in thread
From: Erik Schumacher @ 2025-02-24 9:19 UTC (permalink / raw)
Cc: linux, linux-hwmon, linux-kernel, jdelvare
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>
---
Changes v1 -> v2:
- return EIO instead of ENXIO
- check leading zeros for ADT7301/2 as well
drivers/hwmon/ad7314.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/drivers/hwmon/ad7314.c b/drivers/hwmon/ad7314.c
index 7802bbf5f958..59424103f634 100644
--- a/drivers/hwmon/ad7314.c
+++ b/drivers/hwmon/ad7314.c
@@ -22,11 +22,13 @@
*/
#define AD7314_TEMP_MASK 0x7FE0
#define AD7314_TEMP_SHIFT 5
+#define AD7314_LEADING_ZEROS_MASK BIT(15)
/*
* ADT7301 and ADT7302 temperature masks
*/
#define ADT7301_TEMP_MASK 0x3FFF
+#define ADT7301_LEADING_ZEROS_MASK (BIT(15) | BIT(14))
enum ad7314_variant {
adt7301,
@@ -65,12 +67,20 @@ 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 & AD7314_LEADING_ZEROS_MASK) {
+ /* Invalid read-out, leading zero part is missing */
+ return -EIO;
+ }
data = (ret & AD7314_TEMP_MASK) >> AD7314_TEMP_SHIFT;
data = sign_extend32(data, 9);
return sprintf(buf, "%d\n", 250 * data);
case adt7301:
case adt7302:
+ if (ret & ADT7301_LEADING_ZEROS_MASK) {
+ /* Invalid read-out, leading zero part is missing */
+ return -EIO;
+ }
/*
* Documented as a 13 bit twos complement register
* with a sign bit - which is a 14 bit 2's complement
--
2.44.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH v2] hwmon: (ad7314) Validate leading zero bits and return error
2025-02-24 9:19 [PATCH v2] hwmon: (ad7314) Validate leading zero bits and return error Erik Schumacher
@ 2025-03-02 16:41 ` Guenter Roeck
0 siblings, 0 replies; 2+ messages in thread
From: Guenter Roeck @ 2025-03-02 16:41 UTC (permalink / raw)
To: Erik Schumacher; +Cc: linux-hwmon, linux-kernel, jdelvare
On Mon, Feb 24, 2025 at 09:19:04AM +0000, Erik Schumacher wrote:
> 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>
Applied.
Thanks,
Guenter
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-03-02 16:41 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-24 9:19 [PATCH v2] hwmon: (ad7314) Validate leading zero bits and return error Erik Schumacher
2025-03-02 16:41 ` Guenter Roeck
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®