diff mbox series

[RFC,1/2] firmware: arm_scmi: Filter out negative results on scmi_reading_get

Message ID 20211220174155.40239-2-cristian.marussi@arm.com (mailing list archive)
State New, archived
Headers show
Series Sensor readings fixes | expand

Commit Message

Cristian Marussi Dec. 20, 2021, 5:41 p.m. UTC
When the backing SCMI Platform supports a Sensor protocol whose version is
greater than SCMI v2.0 (0x10000), the underlying SCMI SENSOR_READING_GET
command will report sensors readings no more as unsigned but as signed
values.

A new scmi_reading_get_timestamped operation was added to properly handle
this and other changes like timestamps and multi-axis sensors; on the other
side the Sensor scmi_reading_get protocol operation was kepts as it was for
backward compatibility and so it stil reports values as unsigned, but no
check was added to detect the situation in which a newer FW could try to
report negative values over an unsigned quantity.

Filter out negative values in scmi_reading_get, reporting an error, when
the SCMI FW version is greater than V2.0 and a negative value has been
received.

Reported-by: Nicola Mazzucato <nicola.mazzucato@arm.com>
Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
---
Note that, till now, HWMON SCMI driver was silently interpreting u64 as
s64, so after this change whenever a FW >2.0 is used it won't be possible
anymore to report negative values in HWMON.
---
 drivers/firmware/arm_scmi/sensors.c | 8 ++++++++
 1 file changed, 8 insertions(+)
diff mbox series

Patch

diff --git a/drivers/firmware/arm_scmi/sensors.c b/drivers/firmware/arm_scmi/sensors.c
index cdbb287bd8bc..f3952f1d9f61 100644
--- a/drivers/firmware/arm_scmi/sensors.c
+++ b/drivers/firmware/arm_scmi/sensors.c
@@ -730,6 +730,14 @@  static int scmi_sensor_reading_get(const struct scmi_protocol_handle *ph,
 			*value = get_unaligned_le64(t->rx.buf);
 	}
 
+	if (!ret && si->version > SCMIv2_SENSOR_PROTOCOL && *value & BIT(63)) {
+		dev_warn_once(ph->dev,
+			      "SCMI FW Sensor version:0x%X reported negative value %ld\n",
+			      si->version, (long)*value);
+		*value = 0;
+		ret = -EIO;
+	}
+
 	ph->xops->xfer_put(ph, t);
 	return ret;
 }