linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Cristian Marussi <cristian.marussi@arm.com>
To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org
Cc: sudeep.holla@arm.com, f.fainelli@gmail.com,
	souvik.chakravarty@arm.com, nicola.mazzucato@arm.com,
	Cristian Marussi <cristian.marussi@arm.com>
Subject: [RFC PATCH 1/2] firmware: arm_scmi: Filter out negative results on scmi_reading_get
Date: Mon, 20 Dec 2021 17:41:54 +0000	[thread overview]
Message-ID: <20211220174155.40239-2-cristian.marussi@arm.com> (raw)
In-Reply-To: <20211220174155.40239-1-cristian.marussi@arm.com>

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


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2021-12-20 17:43 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-20 17:41 [RFC PATCH 0/2] Sensor readings fixes Cristian Marussi
2021-12-20 17:41 ` Cristian Marussi [this message]
2021-12-20 17:41 ` [RFC PATCH 2/2] hwmon: (scmi) Filter out results wrongly interpreted as negatives Cristian Marussi
2022-03-25 11:41 ` [RFC PATCH 0/2] Sensor readings fixes Cristian Marussi
2022-03-25 21:38   ` Florian Fainelli
2022-03-30 14:43     ` Cristian Marussi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211220174155.40239-2-cristian.marussi@arm.com \
    --to=cristian.marussi@arm.com \
    --cc=f.fainelli@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nicola.mazzucato@arm.com \
    --cc=souvik.chakravarty@arm.com \
    --cc=sudeep.holla@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).