From 4fe3860dd779e7c23eb71a7c1cf9604c949ba2bb Mon Sep 17 00:00:00 2001 From: Alejandro Garcia Date: Sun, 1 Nov 2026 12:41:20 -0800 Subject: [PATCH] power: supply: max17042_battery: wait out the alert after a failed read too The MAX77759 sleep added at the end of max17042_thread_handler() is skipped when the Status read fails: the handler returns early, the oneshot interrupt is unmasked while ALRT is still asserted, and an I2C error during an alert would burst as before. Move the sleep to a common exit, so both paths wait one task period. Tested on a Pixel 7 (7.3.0-rc6), with only this change on top of the kernel it ran before: with the cable out for 15 minutes, seven alerts (RepSOC reaching 99 % on the cable, then six steps down to 93 %) fired the gauge's interrupt once each, as before this change, and the gauge read as before. The failed-read path itself wasn't triggered. Suggested-by: Derek Ross Assisted-by: Claude Opus 5.5 Signed-off-by: Alejandro Garcia --- drivers/power/supply/max17042_battery.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/power/supply/max17042_battery.c b/drivers/power/supply/max17042_battery.c index e65c2b0d5b..c2de7f28ec 100644 --- a/drivers/power/supply/max17042_battery.c +++ b/drivers/power/supply/max17042_battery.c @@ -1224,7 +1224,7 @@ static irqreturn_t max17042_thread_handler(int id, void *dev) ret = regmap_read(chip->regmap, MAX17042_STATUS, &val); if (ret) - return IRQ_HANDLED; + goto out; if ((val & STATUS_SMN_BIT) || (val & STATUS_SMX_BIT) || (val & STATUS_DSOCI_BIT)) { @@ -1238,11 +1238,13 @@ static irqreturn_t max17042_thread_handler(int id, void *dev) power_supply_changed(chip->battery); +out: /* * The MAX77759 releases ALRT only at its next task period after * Status is cleared, so the level interrupt would fire again as soon * as the oneshot thread returns, hundreds of times per alert. Wait - * one task period (in units of 1/32768 s) before returning. + * one task period (in units of 1/32768 s) before returning, also + * after a failed Status read. */ if (chip->chip_type == MAXIM_DEVICE_TYPE_MAX77759) msleep(DIV_ROUND_UP(chip->task_period * MSEC_PER_SEC, 32768));