[RFC PATCH 2/2] hwmon: (scmi) Filter out results wrongly interpreted as negatives

Cristian Marussi cristian.marussi at arm.com
Mon Dec 20 09:41:55 PST 2021


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 at 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




More information about the linux-arm-kernel mailing list