[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20211220174155.40239-2-cristian.marussi@arm.com>
Date: Mon, 20 Dec 2021 17:41:54 +0000
From: Cristian Marussi <cristian.marussi@....com>
To: linux-kernel@...r.kernel.org, linux-arm-kernel@...ts.infradead.org
Cc: sudeep.holla@....com, f.fainelli@...il.com,
souvik.chakravarty@....com, nicola.mazzucato@....com,
Cristian Marussi <cristian.marussi@....com>
Subject: [RFC PATCH 1/2] firmware: arm_scmi: Filter out negative results on scmi_reading_get
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@....com>
Signed-off-by: Cristian Marussi <cristian.marussi@....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
Powered by blists - more mailing lists