From patchwork Mon Dec 20 17:41:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cristian Marussi X-Patchwork-Id: 12696867 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 828D6C433EF for ; Mon, 20 Dec 2021 17:43:47 +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=+EsB/YNTQncA30FNte5br+oj9soCT+2Ay3MjN4ufYgY=; b=bxvKU+0XMqfuyC bLm3clwG3qo1ZvI2zKXLCUq4cqrVk/Cxrp3Nj5r2/FjQlaAxGRLrGVQP+FDYcUx4zggH+hJJMyoWX xZGWjUKoVb4dBkzblsFWQ27uzA9/RJqu1WTYcIN41eDR5ZWYZWGAew9jCZdO7/GEzZxtx2OzenRCt j9H4ReqzRv4rcrGAc3ZT+l/5Xx/c1Vm5gXjC/j9rP055NtTzGq83TknAHxR7PyFrHY+GCZqVDOUrl zOGFj4Rdrj1H7dya3zTuTbt+zAKf+kzwVcqZlLk3Wv3/Z85RIg2MgaFCNjq5i4JRuV8zsX5j2xzuH AN4AW5evBZSR8kk7AQXw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mzMgF-003cQG-Bj; Mon, 20 Dec 2021 17:42:35 +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-003cJj-8O for linux-arm-kernel@lists.infradead.org; Mon, 20 Dec 2021 17:42:21 +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 D5676D6E; Mon, 20 Dec 2021 09:42:17 -0800 (PST) Received: from e120937-lin.home (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 7DB363F774; Mon, 20 Dec 2021 09:42:16 -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 1/2] firmware: arm_scmi: Filter out negative results on scmi_reading_get Date: Mon, 20 Dec 2021 17:41:54 +0000 Message-Id: <20211220174155.40239-2-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_375504_8210A738 X-CRM114-Status: GOOD ( 10.85 ) 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 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 Signed-off-by: Cristian Marussi --- 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; }