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 2029019049B; Mon, 23 Jun 2025 21:54:28 +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=1750715668; cv=none; b=HWb0EtidSI4b0ANrVAldCZNfDy4cuMzBK9megtAjh57IApYOLOKFq3IW26001ItNm4zFPSOmzdKqTbZS60qVYQa3gUaaFa0/zPy1qIPpzGSstcfte56A5fvVVqlYLMwJSfE6VXEvYXRiz0Se/2KGc01EpyGxyNAgED2aCFN1AP4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750715668; c=relaxed/simple; bh=knTVJ0UtNA2vQSdMo1Dy+DCKkKwYWb2TZur5F0JSJuI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gPR8uHVaoDVP2oAuc3TxxuCHioljW8s7rF6luJrd3c6GCdzjSUN1nJ8YkRzC26qvaco00vaDSQtM5144WfFwU/JCLqrtl3t9Pom44TiqUJ1NOohE4r6qEUtmwcgEaVdirhUBo14fGVGfDCItlhNrBZoGCNx4TBg/VhqbtGblS4k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=G3fSNuvQ; 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="G3fSNuvQ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id ADE33C4CEEA; Mon, 23 Jun 2025 21:54:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1750715668; bh=knTVJ0UtNA2vQSdMo1Dy+DCKkKwYWb2TZur5F0JSJuI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G3fSNuvQtgSc0+u1xWZ4pUZaQogeiXlaM78d4Ndn2qM+T93XYH1DyLrL9iFkqCus7 9LOCwzugpbU1m2NdIr/pfrBr+dMibifRRBWU1GzeNSMPrECtRhvqOjJmgwq3wM6IUo AMeFJnMrEnlmtiB2vuWNSgvQqQIiohSOWrS1dRsI= 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.15 271/411] ACPI: battery: negate current when discharging Date: Mon, 23 Jun 2025 15:06:55 +0200 Message-ID: <20250623130640.476657146@linuxfoundation.org> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250623130632.993849527@linuxfoundation.org> References: <20250623130632.993849527@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.15-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 8bb0f4d06adc0..b0a5d077db905 100644 --- a/drivers/acpi/battery.c +++ b/drivers/acpi/battery.c @@ -250,10 +250,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