From patchwork Mon Dec 20 17:41:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cristian Marussi X-Patchwork-Id: 12696868 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 884DAC433F5 for ; Mon, 20 Dec 2021 17:43:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Vzn5A3e/91inea3XBadsZwkEQw2TG5PSCw4hIdx7G/s=; b=0paWBygjI5UF7u 6u3J0xux434Ssa2lR9/ONVtV2Um6qDl8y8CoMC8JYTMNpn+ay56mCRY/0wlCAHWAGeE+qt7/LIEH+ Yq2A0Ctz6x9DfyAtar7zxAyytt0//TPmfxcd7I88GDQEEbeViJxrn6VxT89ODpWkyXTnps0oEyVUo +F8YLIaB479LCDAQXaFbwiTpWiF4pf5GvGw3TPUEZzn3h3aiRh+auy0KPn3UDwxE9AGGeTK7AIbfK uoUcTRlHi2vi7xgNcFG8nuINHe21gQS4e1jVQKadjnYqvA9HO+vmT531O1H0MD9ob/01HURWhrXLS Ilc5NixCFdFOwz4DLvjw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mzMgS-003cUc-DP; Mon, 20 Dec 2021 17:42:48 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mzMg0-003cKg-EK for linux-arm-kernel@lists.infradead.org; Mon, 20 Dec 2021 17:42:22 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 53184ED1; Mon, 20 Dec 2021 09:42:19 -0800 (PST) Received: from e120937-lin.home (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 164563F774; Mon, 20 Dec 2021 09:42:17 -0800 (PST) From: Cristian Marussi 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 Subject: [RFC PATCH 2/2] hwmon: (scmi) Filter out results wrongly interpreted as negatives Date: Mon, 20 Dec 2021 17:41:55 +0000 Message-Id: <20211220174155.40239-3-cristian.marussi@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211220174155.40239-1-cristian.marussi@arm.com> References: <20211220174155.40239-1-cristian.marussi@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211220_094220_552225_79386663 X-CRM114-Status: UNSURE ( 9.62 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 --- 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;