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 1B1234414; Mon, 23 Jun 2025 21:47:03 +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=1750715223; cv=none; b=pG+rVODzJ1WWzMY5WmsT4E1fW2lGyePZUJJ+TZ/8Y7IltDCqZ1KEBKC5pRKqa1kJWmD8R5Ot6fEGPcjgvLHTfaoXU8weAoXxn0l7XX6kBbBPb0Wq+7Ou+M8DBPJLlyxV6wzAdwM6Y2nT3pI3ERX135O9TleBB156CnwK1/W/Y+Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750715223; c=relaxed/simple; bh=xXza+kR8OLSi9W65a6DnBLIz0ceoLTiHQoUE5N4OSfw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bA6E7JGMycHLTYjQmXBIMTILZYA7/cjSOXG6Ti51pBmcM/sB2h/uj9rOATRJB825dRSHSCILT1GrkeTdKRbBU8azsOB7YkBdeyLKeko5rIV9rWMGziQVukHOgyuzaU/81tw/pYfcqCZxcKGLNIHyZlsgpFaFq0ti9VMWnYJSKH0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=G7gaRFiG; 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="G7gaRFiG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A6656C4CEEA; Mon, 23 Jun 2025 21:47:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1750715223; bh=xXza+kR8OLSi9W65a6DnBLIz0ceoLTiHQoUE5N4OSfw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G7gaRFiGzr+YhNWw2HNHWJ9ZinrauJ1fodyHEnxBfTDNqC7C4wOPXWnTJzaGfhUUv lxx7t1ofgAwwzg+pyFP493roYsWxutheDMETNXPRS3FNzTP8xctiVgG0zWzjHZBh7E ZzEd3dPhiQHcrD6kKBe+/vQctVeWdQdIYfVhe0KU= 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 6.12 190/414] ACPI: battery: negate current when discharging Date: Mon, 23 Jun 2025 15:05:27 +0200 Message-ID: <20250623130646.770142062@linuxfoundation.org> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250623130642.015559452@linuxfoundation.org> References: <20250623130642.015559452@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-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 65fa3444367a1..6a7ac34d73bda 100644 --- a/drivers/acpi/battery.c +++ b/drivers/acpi/battery.c @@ -243,10 +243,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