From: Erik Schumacher <erik.schumacher@iris-sensing.com>
Cc: "linux@roeck-us.net" <linux@roeck-us.net>,
"linux-hwmon@vger.kernel.org" <linux-hwmon@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"jdelvare@suse.com" <jdelvare@suse.com>
Subject: [PATCH] hwmon: (ad7314) Validate leading zero bit and return error
Date: Thu, 20 Feb 2025 10:18:17 +0000 [thread overview]
Message-ID: <c54ef4dd7b562268768200239b00441a74b547c3.camel@iris-sensing.com> (raw)
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
next reply other threads:[~2025-02-20 10:18 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-20 10:18 Erik Schumacher [this message]
2025-02-20 22:22 ` Guenter Roeck
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c54ef4dd7b562268768200239b00441a74b547c3.camel@iris-sensing.com \
--to=erik.schumacher@iris-sensing.com \
--cc=jdelvare@suse.com \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®