mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 1/2] platform/x86: thinkpad_acpi: Update charge_stop only after it was applied
@ 2026-11-24 10:39 Tom Hu
  2026-11-24 17:55 ` Mark Pearson
  0 siblings, 1 reply; 4+ messages in thread
From: Tom Hu @ 2026-11-24 10:39 UTC (permalink / raw)
  To: linux-kernel
  Cc: hmh, mpearson-lenovo, derekjohn.clark, i, hansg, ilpo.jarvinen,
	platform-driver-x86, xiaoying_hu, huxiaoying

From: huxiaoying <huxiaoying@kylinos.cn>

The charge_stop_threshold store writes the new value into the cached
battery_info before the EC has accepted it.  If the ACPI call fails,
the cache and the hardware disagree, and subsequent charge_start
writes are validated against the stale-not-applied value.

Move the cache update after a successful EC write and report -ENODEV
on failure, matching the charge_start path.

Signed-off-by: huxiaoying <huxiaoying@kylinos.cn>
---
 drivers/platform/x86/lenovo/thinkpad_acpi.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c b/drivers/platform/x86/lenovo/thinkpad_acpi.c
index 4f81855ad721..8fc5569131f6 100644
--- a/drivers/platform/x86/lenovo/thinkpad_acpi.c
+++ b/drivers/platform/x86/lenovo/thinkpad_acpi.c
@@ -9847,16 +9847,15 @@ static ssize_t tpacpi_battery_store(int what,
 			return -EINVAL;
 		if (value < battery_info.batteries[battery].charge_start)
 			return -EINVAL;
-		battery_info.batteries[battery].charge_stop = value;
 		/*
 		 * When 100 is passed to stop, we need to flip
 		 * it to 0 as that the EC understands that as
 		 * "Default", which will charge to 100%
 		 */
-		if (value == 100)
-			value = 0;
-		if (tpacpi_battery_set(THRESHOLD_STOP, battery, value))
-			return -EINVAL;
+		if (tpacpi_battery_set(THRESHOLD_STOP, battery,
+				       value == 100 ? 0 : value))
+			return -ENODEV;
+		battery_info.batteries[battery].charge_stop = value;
 		return count;
 	default:
 		pr_crit("Wrong parameter: %d", what);
-- 
2.34.1


^ permalink raw reply	[flat|nested] 4+ messages in thread
* [PATCH 1/2] platform/x86: thinkpad_acpi: Update charge_stop only after it was applied
@ 2026-11-24 10:39 Tom Hu
  2026-11-24 14:02 ` Rong Zhang
  0 siblings, 1 reply; 4+ messages in thread
From: Tom Hu @ 2026-11-24 10:39 UTC (permalink / raw)
  To: linux-kernel
  Cc: hmh, mpearson-lenovo, derekjohn.clark, i, hansg, ilpo.jarvinen,
	platform-driver-x86, xiaoying_hu, huxiaoying

From: huxiaoying <huxiaoying@kylinos.cn>

The charge_stop_threshold store writes the new value into the cached
battery_info before the EC has accepted it.  If the ACPI call fails,
the cache and the hardware disagree, and subsequent charge_start
writes are validated against the stale-not-applied value.

Move the cache update after a successful EC write and report -ENODEV
on failure, matching the charge_start path.

Signed-off-by: huxiaoying <huxiaoying@kylinos.cn>
---
 drivers/platform/x86/lenovo/thinkpad_acpi.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c b/drivers/platform/x86/lenovo/thinkpad_acpi.c
index 4f81855ad721..8fc5569131f6 100644
--- a/drivers/platform/x86/lenovo/thinkpad_acpi.c
+++ b/drivers/platform/x86/lenovo/thinkpad_acpi.c
@@ -9847,16 +9847,15 @@ static ssize_t tpacpi_battery_store(int what,
 			return -EINVAL;
 		if (value < battery_info.batteries[battery].charge_start)
 			return -EINVAL;
-		battery_info.batteries[battery].charge_stop = value;
 		/*
 		 * When 100 is passed to stop, we need to flip
 		 * it to 0 as that the EC understands that as
 		 * "Default", which will charge to 100%
 		 */
-		if (value == 100)
-			value = 0;
-		if (tpacpi_battery_set(THRESHOLD_STOP, battery, value))
-			return -EINVAL;
+		if (tpacpi_battery_set(THRESHOLD_STOP, battery,
+				       value == 100 ? 0 : value))
+			return -ENODEV;
+		battery_info.batteries[battery].charge_stop = value;
 		return count;
 	default:
 		pr_crit("Wrong parameter: %d", what);
-- 
2.34.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-24 17:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-24 10:39 [PATCH 1/2] platform/x86: thinkpad_acpi: Update charge_stop only after it was applied Tom Hu
2026-11-24 17:55 ` Mark Pearson
2026-11-24 10:39 Tom Hu
2026-11-24 14:02 ` Rong Zhang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®