lkml.org 
[lkml]   [2021]   [Dec]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[RFC PATCH 2/2] hwmon: (scmi) Filter out results wrongly interpreted as negatives
Date
SCMI Sensor scmi_reading_get interface can report only unsigned values
while hwmon_ops.read allows for signed negative values to be passed on:
this has the undesired side effect of silently interpreting as negative
any big-enough positive reading reported by the SCMI interface.

Filter out such big positives reporting an error.

Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
---
drivers/hwmon/scmi-hwmon.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)

diff --git a/drivers/hwmon/scmi-hwmon.c b/drivers/hwmon/scmi-hwmon.c
index b1329a58ce40..0924d1b8a9ce 100644
--- a/drivers/hwmon/scmi-hwmon.c
+++ b/drivers/hwmon/scmi-hwmon.c
@@ -73,10 +73,24 @@ static int scmi_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
struct scmi_sensors *scmi_sensors = dev_get_drvdata(dev);

sensor = *(scmi_sensors->info[type] + channel);
+ /*
+ * Can fail with EIO if the backing SCMI Sensor FW version tried to
+ * report a negative value.
+ */
ret = sensor_ops->reading_get(scmi_sensors->ph, sensor->id, &value);
if (ret)
return ret;

+ /*
+ * Cannot accept either valid positive values so big that would be
+ * interpreted as negative by HWMON signed long *val return value.
+ */
+ if (value & BIT(63)) {
+ dev_warn_once(dev,
+ "Reported unsigned value too big.\n");
+ return -EIO;
+ }
+
ret = scmi_hwmon_scale(sensor, &value);
if (!ret)
*val = value;
--
2.17.1
\
 
 \ /
  Last update: 2021-12-20 18:43    [W:0.046 / U:0.020 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site