[RFC PATCH 1/2] firmware: arm_scmi: Filter out negative results on scmi_reading_get
Cristian Marussi
cristian.marussi at arm.com
Mon Dec 20 09:41:54 PST 2021
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 at arm.com>
Signed-off-by: Cristian Marussi <cristian.marussi at 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 --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;
}
--
2.17.1
More information about the linux-arm-kernel
mailing list