[PATCH 1/2] power: supply: max17040: preserve alert threshold on write failure
From: Jianing Li
Date: Mon Nov 02 2026 - 02:34:12 EST
max17040_set_property() updates chip->low_soc_alert even when programming
the new threshold fails. A failed write to capacity_alert_min therefore
changes the value returned by subsequent reads despite the error reported
to the caller.
On models with an alert interrupt, max17040_thread_handler() also uses
this cached value when rearming the alert, so a later interrupt can apply
a threshold whose write previously failed.
Return the register access error before updating the cached threshold.
Fixes: 2f38dc4d9190 ("power: supply: max17040: Add POWER_SUPPLY_PROP_CAPACITY_ALERT_MIN")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Jianing Li <m13940358460@xxxxxxx>
---
drivers/power/supply/max17040_battery.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/power/supply/max17040_battery.c b/drivers/power/supply/max17040_battery.c
index 16e42de..f415876 100644
--- a/drivers/power/supply/max17040_battery.c
+++ b/drivers/power/supply/max17040_battery.c
@@ -384,6 +384,9 @@ static int max17040_set_property(struct power_supply *psy,
break;
}
ret = max17040_set_low_soc_alert(chip, val->intval);
+ if (ret)
+ return ret;
+
chip->low_soc_alert = val->intval;
break;
default:
--
2.23.0.windows.1