mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] hwmon: (ad7314) Validate leading zero bit and return error
@ 2025-02-20 10:18 Erik Schumacher
  2025-02-20 22:22 ` Guenter Roeck
  0 siblings, 1 reply; 2+ messages in thread
From: Erik Schumacher @ 2025-02-20 10:18 UTC (permalink / raw)
  Cc: linux, linux-hwmon, linux-kernel, jdelvare

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.

Signed-off-by: Erik Schumacher <erik.schumacher@iris-sensing.com>
---
 drivers/hwmon/ad7314.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/hwmon/ad7314.c b/drivers/hwmon/ad7314.c
index 7802bbf5f958..025846f1f18b 100644
--- a/drivers/hwmon/ad7314.c
+++ b/drivers/hwmon/ad7314.c
@@ -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);
 
-- 
2.48.1


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

* Re: [PATCH] hwmon: (ad7314) Validate leading zero bit and return error
  2025-02-20 10:18 [PATCH] hwmon: (ad7314) Validate leading zero bit and return error Erik Schumacher
@ 2025-02-20 22:22 ` Guenter Roeck
  0 siblings, 0 replies; 2+ messages in thread
From: Guenter Roeck @ 2025-02-20 22:22 UTC (permalink / raw)
  To: Erik Schumacher; +Cc: linux-hwmon, linux-kernel, jdelvare

On Thu, Feb 20, 2025 at 10:18:17AM +0000, Erik Schumacher wrote:
> 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.
> 
> Signed-off-by: Erik Schumacher <erik.schumacher@iris-sensing.com>
> ---
>  drivers/hwmon/ad7314.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/hwmon/ad7314.c b/drivers/hwmon/ad7314.c
> index 7802bbf5f958..025846f1f18b 100644
> --- a/drivers/hwmon/ad7314.c
> +++ b/drivers/hwmon/ad7314.c
> @@ -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

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

end of thread, other threads:[~2025-02-20 22:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-20 10:18 [PATCH] hwmon: (ad7314) Validate leading zero bit and return error Erik Schumacher
2025-02-20 22:22 ` 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®