[PATCH] regulator: act8865: Tie the power-off handler to the PMIC

From: Tian Xuechen

Date: Sat Nov 28 2026 - 06:02:42 EST


From: Tian Xuechen <202300460064@xxxxxxxxxxxxxxx>

The global power-off callback can outlive the I2C client on probe
failure or unbind. Register a managed handler with the PMIC as its
context so the callback is removed before its regmap is released.

This issue was found by our static analysis tool under development.

Fixes: 2b17fa2825fe ("regulator: act8865: Add support to turn off all outputs")
Signed-off-by: Tian Xuechen <202300460064@xxxxxxxxxxxxxxx>
---
drivers/regulator/act8865-regulator.c | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/drivers/regulator/act8865-regulator.c b/drivers/regulator/act8865-regulator.c
index c2460f5904b9..2aa93baff815 100644
--- a/drivers/regulator/act8865-regulator.c
+++ b/drivers/regulator/act8865-regulator.c
@@ -17,6 +17,7 @@
#include <linux/of.h>
#include <linux/of_device.h>
#include <linux/power_supply.h>
+#include <linux/reboot.h>
#include <linux/regulator/of_regulator.h>
#include <linux/regmap.h>
#include <dt-bindings/regulator/active-semi,8865-regulator.h>
@@ -572,14 +573,15 @@ static struct act8865_regulator_data *act8865_get_regulator_data(
return NULL;
}

-static struct i2c_client *act8865_i2c_client;
-static void act8865_power_off(void)
+static int act8865_power_off(struct sys_off_data *data)
{
- struct act8865 *act8865;
+ struct act8865 *act8865 = data->cb_data;

- act8865 = i2c_get_clientdata(act8865_i2c_client);
regmap_write(act8865->regmap, act8865->off_reg, act8865->off_mask);
- while (1);
+ while (1)
+ cpu_relax();
+
+ return NOTIFY_DONE;
}

static int act8600_charger_get_status(struct regmap *map)
@@ -724,10 +726,11 @@ static int act8865_pmic_probe(struct i2c_client *client)

if (of_device_is_system_power_controller(dev->of_node)) {
if (!pm_power_off && (off_reg > 0)) {
- act8865_i2c_client = client;
act8865->off_reg = off_reg;
act8865->off_mask = off_mask;
- pm_power_off = act8865_power_off;
+ ret = devm_register_power_off_handler(dev, act8865_power_off, act8865);
+ if (ret)
+ dev_err(dev, "Failed to register power-off handler: %d\n", ret);
} else {
dev_err(dev, "Failed to set poweroff capability, already defined\n");
}
@@ -769,8 +772,6 @@ static int act8865_pmic_probe(struct i2c_client *client)
}
}

- i2c_set_clientdata(client, act8865);
-
/* Unlock expert registers for ACT8865. */
return type != ACT8865 ? 0 : regmap_write(act8865->regmap,
ACT8865_SYS_UNLK_REGS, 0xef);

base-commit: 4dce97c6c265544342e716e62fd24bbb232590c5
--
2.43.0