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 2/2] hwmon: (scmi) Filter out results wrongly interpreted as negatives Date: Mon, 20 Dec 2021 17:41:55 +0000 [thread overview] Message-ID: <20211220174155.40239-3-cristian.marussi@arm.com> (raw) In-Reply-To: <20211220174155.40239-1-cristian.marussi@arm.com> 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@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
WARNING: multiple messages have this Message-ID (diff)
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 2/2] hwmon: (scmi) Filter out results wrongly interpreted as negatives Date: Mon, 20 Dec 2021 17:41:55 +0000 [thread overview] Message-ID: <20211220174155.40239-3-cristian.marussi@arm.com> (raw) In-Reply-To: <20211220174155.40239-1-cristian.marussi@arm.com> 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@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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2021-12-20 17:42 UTC|newest] Thread overview: 16+ 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 2021-12-20 17:41 ` [RFC PATCH 1/2] firmware: arm_scmi: Filter out negative results on scmi_reading_get Cristian Marussi 2021-12-20 17:41 ` Cristian Marussi 2021-12-20 22:28 ` kernel test robot 2021-12-20 22:28 ` kernel test robot 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 2021-12-21 3:54 ` kernel test robot 2021-12-21 3:54 ` kernel test robot 2022-03-25 11:41 ` [RFC PATCH 0/2] Sensor readings fixes Cristian Marussi 2022-03-25 11:41 ` Cristian Marussi 2022-03-25 21:38 ` Florian Fainelli 2022-03-25 21:38 ` Florian Fainelli 2022-03-30 14:43 ` Cristian Marussi 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-3-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: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.