From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 535BF21D3DD; Mon, 23 Jun 2025 21:37:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750714662; cv=none; b=V6/1FW8jg9EUa84mZSdnqXxMMJ7rI5FOpfgeQM6hNBn2nkUB8KpVnOaNn7vbRP6YeO8M47lRFeo6PgpOYwkMQ9ftvssEhzyyk7SYRVm6p9r3MfP9vK+eMjZ6M47S8qxiP1mHrSp1x9nPZfnrrAHJ1Q6Ox1RjgY2AQC0MbOlkm10= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750714662; c=relaxed/simple; bh=p3/qNWRPkj5EQOUeAePKdBsS8dUB9B6qeYiC/LiOUyQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OKugeSZdB/KHvNl9p7lHrttJF2Z8Dfxb9GsHFABSRWIandt6kpHD5Lm2iP7JFAmpXDReE4vrcnt7ylcpGnHpTz+ojQZsXkMo4+k7CCG78V2CAAQoH1Ickm41ifn2CYbeHAStxceMvSppIWFMDOiur/vYx9/89YmDMSQ5SgVANww= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=n4ShHlZ4; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="n4ShHlZ4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DFD19C4CEEA; Mon, 23 Jun 2025 21:37:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1750714662; bh=p3/qNWRPkj5EQOUeAePKdBsS8dUB9B6qeYiC/LiOUyQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n4ShHlZ4rHP+ivnP/P4zcNj03937XTI0UVxxbYnLODkgTM/6gSaXKz1dyZZsfGj7/ BQZ/LqhfvCmDnzqMsFNtBHP12Rp7sH+IvW3eWTlm/xrVUf2Tf2FzXaAT6q+aHckdSE M17L0P9uyvet5o0DwFrDiPfMSr4phpr8rOoSCBt0= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Peter Marheine , "Rafael J. Wysocki" , Sasha Levin Subject: [PATCH 5.10 221/355] ACPI: battery: negate current when discharging Date: Mon, 23 Jun 2025 15:07:02 +0200 Message-ID: <20250623130633.385516249@linuxfoundation.org> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250623130626.716971725@linuxfoundation.org> References: <20250623130626.716971725@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Peter Marheine [ Upstream commit 234f71555019d308c6bc6f98c78c5551cb8cd56a ] The ACPI specification requires that battery rate is always positive, but the kernel ABI for POWER_SUPPLY_PROP_CURRENT_NOW (Documentation/ABI/testing/sysfs-class-power) specifies that it should be negative when a battery is discharging. When reporting CURRENT_NOW, massage the value to match the documented ABI. This only changes the sign of `current_now` and not `power_now` because documentation doesn't describe any particular meaning for `power_now` so leaving `power_now` unchanged is less likely to confuse userspace unnecessarily, whereas becoming consistent with the documented ABI is worth potentially confusing clients that read `current_now`. Signed-off-by: Peter Marheine Link: https://patch.msgid.link/20250508024146.1436129-1-pmarheine@chromium.org Signed-off-by: Rafael J. Wysocki Signed-off-by: Sasha Levin --- drivers/acpi/battery.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c index f9fb092f33a26..4a188cc28b5ce 100644 --- a/drivers/acpi/battery.c +++ b/drivers/acpi/battery.c @@ -255,10 +255,23 @@ static int acpi_battery_get_property(struct power_supply *psy, break; case POWER_SUPPLY_PROP_CURRENT_NOW: case POWER_SUPPLY_PROP_POWER_NOW: - if (battery->rate_now == ACPI_BATTERY_VALUE_UNKNOWN) + if (battery->rate_now == ACPI_BATTERY_VALUE_UNKNOWN) { ret = -ENODEV; - else - val->intval = battery->rate_now * 1000; + break; + } + + val->intval = battery->rate_now * 1000; + /* + * When discharging, the current should be reported as a + * negative number as per the power supply class interface + * definition. + */ + if (psp == POWER_SUPPLY_PROP_CURRENT_NOW && + (battery->state & ACPI_BATTERY_STATE_DISCHARGING) && + acpi_battery_handle_discharging(battery) + == POWER_SUPPLY_STATUS_DISCHARGING) + val->intval = -val->intval; + break; case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN: case POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN: -- 2.39.5