From patchwork Fri Nov 24 18:27:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 169540 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce62:0:b0:403:3b70:6f57 with SMTP id o2csp1439168vqx; Fri, 24 Nov 2023 10:28:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IE1DhWAokd+NArwKVeyd030pidpq0a1ZNLS67+t/atMC+IsphvQsuDeD/Tk43aOkPpo9Ene X-Received: by 2002:a05:6a00:1914:b0:68b:e29c:b69 with SMTP id y20-20020a056a00191400b0068be29c0b69mr5076640pfi.9.1700850512519; Fri, 24 Nov 2023 10:28:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700850512; cv=none; d=google.com; s=arc-20160816; b=qpqklXPnazzhpiiiIJUSdk3mcLlIL+rXxrFmpP5aMb2X4oc07Z1OY2eZUHDQm97esQ uvGTyI/++CV3Zcg6934kMDF9y6wdFwRIlC7Qvh5VF9Vn6seu7WsENsXna/pN3oOTpiM4 q/5dmgxcAnf2zhtPVv8nrTc6PEERl5Im31JthiuAh12Jx5d1+GQK6LOj83aBcqR34lwg HIxO6NJLBx9ECYVp9DS8uS3r0YSyHg9G+OTZU+PN7Cs7BhY+mh8F8aRV2LAbWKOQhLfm nXy7tpbd7BNCKiR4AdD2WXdwQcbYZ1rye4U+lvy3An5QZ6iZL33+UjjRwwgE0WKG3kaY SlTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:ui-outboundreport:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=CF9JAhEdDN6KhtHlzODAmneH3YhNfO1TlWVnj73XHcM=; fh=lWF+5mlxh1xbPfW9b76vfCqWQLpYpco7XzHHbsflC+8=; b=Taj0Sbkcs7FWYN4LB9lqZ2de1I8J9rGCgq7+aRU1F3u9lg3ki5a7E4Q+QuH87aiU30 1kUOsGK8oiT8X8jDXZ7bv5wVBauJGyBhzft4GbPqAMvDmAVnfSE1/wFN045iv7P63C5a wm3NuZDR4OQjsyfph59/2CoekPLaQCJHpEl+GAbYPVi+RdLE0GFUOg+Ni5/5G+mef2SI lu35lln/T1yBueoIFECRJeA8Bar6aeYX0zxu3HWBIll76GeDcbS0qRT5FHgDyDgmadhX oI3FJ6V+k/5vhggUe36/JUQEtpzwbPtzkqprDGcI8gL3wvK5wzzj2QNxsgfXMTKrP6qm hSGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b="RG0xaV/0"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id q21-20020a656855000000b005bddb4be6fcsi4132338pgt.520.2023.11.24.10.28.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Nov 2023 10:28:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b="RG0xaV/0"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id A07CC8263745; Fri, 24 Nov 2023 10:28:13 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231173AbjKXS2F (ORCPT + 99 others); Fri, 24 Nov 2023 13:28:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230104AbjKXS2D (ORCPT ); Fri, 24 Nov 2023 13:28:03 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 411211BC9; Fri, 24 Nov 2023 10:28:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1700850472; x=1701455272; i=w_armin@gmx.de; bh=YOwNjDfGnJRJthcNBht0dNRhiwLqkmRlexlwOFwzi44=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date; b=RG0xaV/0Th+t69dZ+vzHSCjLERYvu/mBSKNlrG1LxgamPxKcUzarGDd8dkLM8KJM ye0glsE1DZCQX7W5MTKNHX4BD1he20dTbxg5h+YgdV/G2IxMcZZn21Jamp0jaXFKY Hfl73iQgLLGg34AVBbZoMzyvj5Rwpk+KMHPaFDfj0RWIgdC+mBRZQRGlE1qPlmVH4 gOHgAautMpOakAi5XEayHTkk/D/GEM9sjlVcxaPgbMMFi9FdMA4n/Wrwjz7ZYye9G QBT65sQyZGRvYahEP8xzhFAU2as37wUz8Alxh7VRzscJjiewzMPN6Cw4+iRz3meZy 84AxzmxPMxEgG1ixWg== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from mx-amd-b650.users.agdsn.de ([141.30.226.129]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MatVh-1rifTf1kSJ-00cULO; Fri, 24 Nov 2023 19:27:52 +0100 From: Armin Wolf To: jdelvare@suse.com, linux@roeck-us.net Cc: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] hwmon: (acpi_power_meter) Fix 4.29 MW bug Date: Fri, 24 Nov 2023 19:27:47 +0100 Message-Id: <20231124182747.13956-1-W_Armin@gmx.de> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Provags-ID: V03:K1:FSfNVWMWv8UmnIPizhw0uZDKiGrcoL0B18QnbH5XNikbR+CPo+r UhCsbAxKGd8saZs5Jt0uMC7HphiM7y//Rx9IQjSIWQfmwlOwfqA3UZ3SMf0lyyyaD7ajvfI JrboNahOd1r8+D0fX+lQ4nWIKKII6nr8Ja5PFws2jFv6BeLj0lUHmB7/CGV44eVg/VfIo0T jHu8U291TkotvmhNi0X2w== UI-OutboundReport: notjunk:1;M01:P0:6rj7i4piqfE=;XFSf2fXxtxeD6KElg3zwEDlmweZ qYUnmgmsNyQ7o/HjxD2PMhsH2Mpn8U4KZEzR6KCeqgKfNQWOHddUg+3Tug7yWPkMR3c9CFvzd RnXpknb2ZfuyqacYzfI+SNLli75YvXTHORiSdWUj5/b8sBjGdfMo41UJIdLpOW5urBtownWu0 Xwr+L0GFG3WNxQtVRtUPy1HMRHUcNlZ+xpRfpc9ejcM5B7aSCXQ1sD8G7kRvGx76argJMohcQ P/+9yI1ChUTdTPfUpYUb5WhhQ+zu0XPOnePGyiLCxQDVqR+mqq6W5LBtObrZxUwOOF3MteGQ5 MAhJw/zcZyw/+0OGNYXxQMhiyW3pwyoi8XVc0ld8Clycht2R6pIesz54a2mFZdH1Hyws+2zyp aebSgkaVcCE3iNjLNeXz2mOB9y4438B/rkTXs84cxna6L0xHOoVeW6DEwZjJ2SnvjLG3F31J3 HsKNtUsVlxtpznN960hs1bOeGSS73nmpDlOEC6JptUyVAh6sR3wlrDKdRIIt5SsW4Yb+lkD/l NG6ZUG1vMIL2WQmrxL5yOJoM+jfWneJeelH0om/k+5uv4S1dk7F+MrmnIuwR8UHWgZLjccTop 8C7Bdes/n7HfrgijlyfPFDRtSYIlLmecxSlMYRQUFbCzxcH37VXLk3LXvQSJlC4wpeYrkg04m XjKZvaLMG0ARBoP3gHaT4nRZWVvrvLSGMOa1eB8SMkHM8b5KHiG7na0yszd3jjW6VFL7SRa9A ctThhVEZ7TrmNsRiBchu+iYyawT9d/n1xGqOuyj323TBF0HNGpxpIzhcBwff5+u/5n5n+2eSU g/NMC3RMDPinFWkq+eZ8NWVbOp0iT1bgU2e7OQRAovRlXRzWkZ9ucSRxFP6f/h2MOGNVPRqjI IpnJUyoG6IHRm0uMDA1UPjThsprCSKYO7DZQmQLw9tdxxqpXusxCXuJ0R6p4Zf2xMZTHvWSPq TYnL2UBSZxMwlXVAruZZ1bdPU90= X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Fri, 24 Nov 2023 10:28:13 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783471027383165972 X-GMAIL-MSGID: 1783471027383165972 The ACPI specification says: "If an error occurs while obtaining the meter reading or if the value is not available then an Integer with all bits set is returned" Since the "integer" is 32 bits in case of the ACPI power meter, userspace will get a power reading of 2^32 * 1000 miliwatts (~4.29 MW) in case of such an error. This was discovered due to a lm_sensors bugreport (https://github.com/lm-sensors/lm-sensors/issues/460). Fix this by returning -ENODATA instead. Tested-by: Fixes: de584afa5e18 ("hwmon driver for ACPI 4.0 power meters") Signed-off-by: Armin Wolf --- drivers/hwmon/acpi_power_meter.c | 4 ++++ 1 file changed, 4 insertions(+) -- 2.39.2 diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c index 8db740214ffd..703666b95bf4 100644 --- a/drivers/hwmon/acpi_power_meter.c +++ b/drivers/hwmon/acpi_power_meter.c @@ -31,6 +31,7 @@ #define POWER_METER_CAN_NOTIFY (1 << 3) #define POWER_METER_IS_BATTERY (1 << 8) #define UNKNOWN_HYSTERESIS 0xFFFFFFFF +#define UNKNOWN_POWER 0xFFFFFFFF #define METER_NOTIFY_CONFIG 0x80 #define METER_NOTIFY_TRIP 0x81 @@ -348,6 +349,9 @@ static ssize_t show_power(struct device *dev, update_meter(resource); mutex_unlock(&resource->lock); + if (resource->power == UNKNOWN_POWER) + return -ENODATA; + return sprintf(buf, "%llu\n", resource->power * 1000); }