* [PATCH 1/8] regulator: core: Defer supply cleanup and unregister event forwarding on error
2026-11-27 18:35 [PATCH 0/8] regulator: Fix locking, OOB read, lifetime, and global state bugs (batch 2) Lee Jones
@ 2026-11-27 18:35 ` Lee Jones
2026-11-27 18:35 ` [PATCH 2/8] regulator: max8907: Duplicate of_regulator_match table per device Lee Jones
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Lee Jones @ 2026-11-27 18:35 UTC (permalink / raw)
To: lee, Liam Girdwood, Mark Brown, Douglas Anderson, Oleksij Rempel,
André Draszik, linux-kernel
Cc: stable
When enabling rdev->supply fails in set_machine_constraints(), the error
path calls _regulator_put(rdev->supply) without holding
regulator_list_mutex and clears rdev->supply to NULL. Neither
regulator_register() nor regulator_resolve_supply() holds
regulator_list_mutex here, and when called from
regulator_resolve_supply() under regulator_lock_dependent(), clearing
rdev->supply prevents regulator_unlock_dependent() from unlocking the
supply chain and skips unregister_regulator_event_forwarding().
In addition, the wash error label in regulator_register() releases
rdev->supply and drops the device reference without calling
unregister_regulator_event_forwarding(), leaving a dangling notifier on
the supply chain after rdev is freed.
Leave supply teardown in set_machine_constraints() to its callers, which
already handle cleanup with proper locking, and unregister event
forwarding before putting rdev->supply on the regulator_register() error
path.
Fixes: 05f224ca6693 ("regulator: core: Clean enabling always-on regulators + their supplies")
Fixes: 433e294c3c5b ("regulator: core: forward undervoltage events downstream by default")
Fixes: 8d38423d9dea ("regulator: core: don't fail regulator_register() with missing required supply")
Closes: https://sashiko.dev/#/bug/linux-f6e93cf6-c907-4a0b-b748-617186aee410
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/regulator/core.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 8bb1ae4e03ea..18ec8b77e620 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -1680,11 +1680,8 @@ static int set_machine_constraints(struct regulator_dev *rdev,
ret = (is_locked
? _regulator_enable(rdev->supply, NULL)
: regulator_enable(rdev->supply));
- if (ret < 0) {
- _regulator_put(rdev->supply);
- rdev->supply = NULL;
+ if (ret < 0)
return ret;
- }
supply_enabled = true;
}
@@ -6392,7 +6389,10 @@ regulator_register(struct device *dev,
regulator_remove_coupling(rdev);
mutex_unlock(®ulator_list_mutex);
wash:
- regulator_put(rdev->supply);
+ if (rdev->supply) {
+ unregister_regulator_event_forwarding(rdev);
+ regulator_put(rdev->supply);
+ }
kfree(rdev->coupling_desc.coupled_rdevs);
mutex_lock(®ulator_list_mutex);
regulator_ena_gpio_free(rdev);
--
2.56.1.839.g22a8290db9-goog
^ permalink raw reply [flat|nested] 9+ messages in thread* [PATCH 2/8] regulator: max8907: Duplicate of_regulator_match table per device
2026-11-27 18:35 [PATCH 0/8] regulator: Fix locking, OOB read, lifetime, and global state bugs (batch 2) Lee Jones
2026-11-27 18:35 ` [PATCH 1/8] regulator: core: Defer supply cleanup and unregister event forwarding on error Lee Jones
@ 2026-11-27 18:35 ` Lee Jones
2026-11-27 18:35 ` [PATCH 3/8] regulator: tps6594-regulator: Use dedicated handler for external regulator IRQs Lee Jones
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Lee Jones @ 2026-11-27 18:35 UTC (permalink / raw)
To: lee, Liam Girdwood, Mark Brown, Gyungoh Yoo, Graeme Gregory,
Eduardo Candelaria, Stephen Warren, Laxman Dewangan,
linux-kernel
Cc: stable
max8907_regulator_parse_dt() passes the static global max8907_matches
array directly to of_regulator_match(), which populates init_data and
of_node in place and registers a devres callback holding a pointer to
that array. With multiple MAX8907 instances, a second probe overwrites
the first instance's entries and subsequent unbinds invoke of_node_put()
twice on the same device nodes, causing reference count underflow and
use-after-free.
Mark max8907_matches const and duplicate it per device with
devm_kmemdup() before calling of_regulator_match().
Fixes: ffee19091a4e ("regulator: add MAX8907 driver")
Closes: https://sashiko.dev/#/bug/linux-295d0600-9849-4e47-802c-7e7a883167aa
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/regulator/max8907-regulator.c | 57 +++++++++++----------------
1 file changed, 24 insertions(+), 33 deletions(-)
diff --git a/drivers/regulator/max8907-regulator.c b/drivers/regulator/max8907-regulator.c
index fd227fd13612..7781901ed115 100644
--- a/drivers/regulator/max8907-regulator.c
+++ b/drivers/regulator/max8907-regulator.c
@@ -186,7 +186,7 @@ static const struct regulator_desc max8907_regulators[] = {
.driver_data = (void *)&max8907_regulators[MAX8907_##_id], \
}
-static struct of_regulator_match max8907_matches[] = {
+static const struct of_regulator_match max8907_matches[] = {
MATCH(mbatt, MBATT),
MATCH(sd1, SD1),
MATCH(sd2, SD2),
@@ -218,54 +218,44 @@ static struct of_regulator_match max8907_matches[] = {
MATCH(vrtc, VRTC),
};
-static int max8907_regulator_parse_dt(struct platform_device *pdev)
+static struct of_regulator_match *
+max8907_regulator_parse_dt(struct platform_device *pdev)
{
+ struct of_regulator_match *matches;
struct device_node *np, *regulators;
int ret;
np = pdev->dev.parent->of_node;
if (!np)
- return 0;
+ return NULL;
regulators = of_get_child_by_name(np, "regulators");
if (!regulators) {
dev_err(&pdev->dev, "regulators node not found\n");
- return -EINVAL;
+ return ERR_PTR(-EINVAL);
}
- ret = of_regulator_match(&pdev->dev, regulators, max8907_matches,
+ matches = devm_kmemdup(&pdev->dev, max8907_matches,
+ sizeof(max8907_matches), GFP_KERNEL);
+ if (!matches) {
+ of_node_put(regulators);
+ return ERR_PTR(-ENOMEM);
+ }
+
+ ret = of_regulator_match(&pdev->dev, regulators, matches,
ARRAY_SIZE(max8907_matches));
of_node_put(regulators);
if (ret < 0) {
dev_err(&pdev->dev, "Error parsing regulator init data: %d\n",
ret);
- return ret;
+ return ERR_PTR(ret);
}
- return 0;
-}
-
-static inline struct regulator_init_data *match_init_data(int index)
-{
- return max8907_matches[index].init_data;
-}
-
-static inline struct device_node *match_of_node(int index)
-{
- return max8907_matches[index].of_node;
+ return matches;
}
#else
-static int max8907_regulator_parse_dt(struct platform_device *pdev)
-{
- return 0;
-}
-
-static inline struct regulator_init_data *match_init_data(int index)
-{
- return NULL;
-}
-
-static inline struct device_node *match_of_node(int index)
+static struct of_regulator_match *
+max8907_regulator_parse_dt(struct platform_device *pdev)
{
return NULL;
}
@@ -280,12 +270,13 @@ static int max8907_regulator_probe(struct platform_device *pdev)
unsigned int val;
int i;
struct regulator_config config = {};
+ struct of_regulator_match *matches;
struct regulator_init_data *idata;
const char *mbatt_rail_name = NULL;
- ret = max8907_regulator_parse_dt(pdev);
- if (ret)
- return ret;
+ matches = max8907_regulator_parse_dt(pdev);
+ if (IS_ERR(matches))
+ return PTR_ERR(matches);
pmic = devm_kzalloc_obj(&pdev->dev, *pmic);
if (!pmic)
@@ -315,11 +306,11 @@ static int max8907_regulator_probe(struct platform_device *pdev)
if (pdata)
idata = pdata->init_data[i];
else
- idata = match_init_data(i);
+ idata = matches ? matches[i].init_data : NULL;
config.init_data = idata;
config.driver_data = pmic;
config.regmap = max8907->regmap_gen;
- config.of_node = match_of_node(i);
+ config.of_node = matches ? matches[i].of_node : NULL;
switch (pmic->desc[i].id) {
case MAX8907_MBATT:
--
2.56.1.839.g22a8290db9-goog
^ permalink raw reply [flat|nested] 9+ messages in thread* [PATCH 3/8] regulator: tps6594-regulator: Use dedicated handler for external regulator IRQs
2026-11-27 18:35 [PATCH 0/8] regulator: Fix locking, OOB read, lifetime, and global state bugs (batch 2) Lee Jones
2026-11-27 18:35 ` [PATCH 1/8] regulator: core: Defer supply cleanup and unregister event forwarding on error Lee Jones
2026-11-27 18:35 ` [PATCH 2/8] regulator: max8907: Duplicate of_regulator_match table per device Lee Jones
@ 2026-11-27 18:35 ` Lee Jones
2026-11-27 18:35 ` [PATCH 4/8] regulator: tps65910: Fix OOB read and bit shift in external sleep config Lee Jones
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Lee Jones @ 2026-11-27 18:35 UTC (permalink / raw)
To: lee, Liam Girdwood, Mark Brown, Uday Khare, Jerome Neanne,
Mal Nadar, Esteban Blanc, linux-kernel
Cc: stable
External regulator and VMON interrupts are registered with a pointer to
struct tps6594_ext_regulator_irq_data, which has no rdev member, yet
they reuse tps6594_regulator_irq_handler(). That handler casts the
pointer to struct tps6594_regulator_irq_data and reads irq_data->rdev
out of bounds before passing it to regulator_notifier_call_chain().
Add a dedicated tps6594_ext_regulator_irq_handler() that operates on
struct tps6594_ext_regulator_irq_data and logs the trap without calling
regulator_notifier_call_chain().
Fixes: f17ccc5deb4d ("regulator: tps6594-regulator: Add driver for TI TPS6594 regulators")
Closes: https://sashiko.dev/#/bug/linux-e6806c5e-76ed-41e2-924e-7110aa9f7d58
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/regulator/tps6594-regulator.c | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/drivers/regulator/tps6594-regulator.c b/drivers/regulator/tps6594-regulator.c
index 1bbad407acb7..66052753610f 100644
--- a/drivers/regulator/tps6594-regulator.c
+++ b/drivers/regulator/tps6594-regulator.c
@@ -509,6 +509,23 @@ static irqreturn_t tps6594_regulator_irq_handler(int irq, void *data)
return IRQ_HANDLED;
}
+static irqreturn_t tps6594_ext_regulator_irq_handler(int irq, void *data)
+{
+ struct tps6594_ext_regulator_irq_data *irq_data = data;
+
+ if (irq_data->type->event_name[0] == '\0') {
+ /* This is the timeout interrupt no specific regulator */
+ dev_err(irq_data->dev,
+ "System was put in shutdown due to timeout during an active or standby transition.\n");
+ return IRQ_HANDLED;
+ }
+
+ dev_err(irq_data->dev, "Error IRQ trap %s for %s\n",
+ irq_data->type->event_name, irq_data->type->regulator_name);
+
+ return IRQ_HANDLED;
+}
+
static int tps6594_request_reg_irqs(struct platform_device *pdev,
struct regulator_dev *rdev,
struct tps6594_regulator_irq_data *irq_data,
@@ -827,7 +844,7 @@ static int tps6594_regulator_probe(struct platform_device *pdev)
irq_ext_reg_data[i].type = irq_type;
error = devm_request_threaded_irq(tps->dev, irq, NULL,
- tps6594_regulator_irq_handler,
+ tps6594_ext_regulator_irq_handler,
IRQF_ONESHOT,
irq_type->irq_name,
&irq_ext_reg_data[i]);
--
2.56.1.839.g22a8290db9-goog
^ permalink raw reply [flat|nested] 9+ messages in thread* [PATCH 4/8] regulator: tps65910: Fix OOB read and bit shift in external sleep config
2026-11-27 18:35 [PATCH 0/8] regulator: Fix locking, OOB read, lifetime, and global state bugs (batch 2) Lee Jones
` (2 preceding siblings ...)
2026-11-27 18:35 ` [PATCH 3/8] regulator: tps6594-regulator: Use dedicated handler for external regulator IRQs Lee Jones
@ 2026-11-27 18:35 ` Lee Jones
2026-11-27 18:35 ` [PATCH 5/8] regulator: tps6594-regulator: Bind IRQ resources to child platform device Lee Jones
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Lee Jones @ 2026-11-27 18:35 UTC (permalink / raw)
To: lee, Aaro Koskinen, Andreas Kemnade, Kevin Hilman, Roger Quadros,
Tony Lindgren, Liam Girdwood, Mark Brown, Graeme Gregory,
Eduardo Candelaria, Markus Schneider-Pargmann, linux-omap,
linux-kernel
Cc: stable
tps65910_regs contains 14 regulators including VBB at index 13, whereas
tps65910_ext_sleep_control has only 13 elements. Both tps65910_probe()
and tps65910_shutdown() iterate up to pmic->num_regulators and index
pmic->ext_sleep_control[id] out of bounds for VBB.
In addition, unsupported rails such as VRTC use 0, which collides with
VMMC and LDO6 (offset 0, bit 0), and computing
(1 << pmic->ext_sleep_control[id] & 0xFF) shifts by more than 31 bits
whenever regs_offs is non-zero because << binds tighter than &.
Introduce EXT_CONTROL_REG_NONE as a distinct sentinel for rails without
external sleep control (VRTC and VBB), add BUILD_BUG_ON() array-size
checks, return early in tps65910_set_ext_sleep_config() for unsupported
rails, and use BIT(pmic->ext_sleep_control[id] & 0xFF) for bit_pos.
Fixes: 03746dcbde75 ("regulator: tps65910: Add backup battery regulator")
Closes: https://sashiko.dev/#/bug/linux-ed3bcc60-149e-497b-93aa-50138953c49a
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/regulator/tps65910-regulator.c | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)
diff --git a/drivers/regulator/tps65910-regulator.c b/drivers/regulator/tps65910-regulator.c
index b99923773701..d42ffc237bf4 100644
--- a/drivers/regulator/tps65910-regulator.c
+++ b/drivers/regulator/tps65910-regulator.c
@@ -271,9 +271,10 @@ static struct tps_info tps65911_regs[] = {
},
};
+#define EXT_CONTROL_REG_NONE (~0U)
#define EXT_CONTROL_REG_BITS(id, regs_offs, bits) (((regs_offs) << 8) | (bits))
static unsigned int tps65910_ext_sleep_control[] = {
- 0,
+ EXT_CONTROL_REG_NONE,
EXT_CONTROL_REG_BITS(VIO, 1, 0),
EXT_CONTROL_REG_BITS(VDD1, 1, 1),
EXT_CONTROL_REG_BITS(VDD2, 1, 2),
@@ -286,10 +287,11 @@ static unsigned int tps65910_ext_sleep_control[] = {
EXT_CONTROL_REG_BITS(VAUX2, 0, 4),
EXT_CONTROL_REG_BITS(VAUX33, 0, 5),
EXT_CONTROL_REG_BITS(VMMC, 0, 0),
+ EXT_CONTROL_REG_NONE,
};
static unsigned int tps65911_ext_sleep_control[] = {
- 0,
+ EXT_CONTROL_REG_NONE,
EXT_CONTROL_REG_BITS(VIO, 1, 0),
EXT_CONTROL_REG_BITS(VDD1, 1, 1),
EXT_CONTROL_REG_BITS(VDD2, 1, 2),
@@ -822,10 +824,16 @@ static int tps65910_set_ext_sleep_config(struct tps65910_reg *pmic,
int id, int ext_sleep_config)
{
struct tps65910 *mfd = pmic->mfd;
- u8 regoffs = (pmic->ext_sleep_control[id] >> 8) & 0xFF;
- u8 bit_pos = (1 << pmic->ext_sleep_control[id] & 0xFF);
+ u8 regoffs;
+ u8 bit_pos;
int ret;
+ if (pmic->ext_sleep_control[id] == EXT_CONTROL_REG_NONE)
+ return 0;
+
+ regoffs = (pmic->ext_sleep_control[id] >> 8) & 0xFF;
+ bit_pos = BIT(pmic->ext_sleep_control[id] & 0xFF);
+
/*
* Regulator can not be control from multiple external input EN1, EN2
* and EN3 together.
@@ -1104,6 +1112,8 @@ static int tps65910_probe(struct platform_device *pdev)
switch (tps65910_chip_id(tps65910)) {
case TPS65910:
BUILD_BUG_ON(TPS65910_NUM_REGS < ARRAY_SIZE(tps65910_regs));
+ BUILD_BUG_ON(ARRAY_SIZE(tps65910_regs) !=
+ ARRAY_SIZE(tps65910_ext_sleep_control));
pmic->get_ctrl_reg = &tps65910_get_ctrl_register;
pmic->num_regulators = ARRAY_SIZE(tps65910_regs);
pmic->ext_sleep_control = tps65910_ext_sleep_control;
@@ -1117,6 +1127,8 @@ static int tps65910_probe(struct platform_device *pdev)
break;
case TPS65911:
BUILD_BUG_ON(TPS65910_NUM_REGS < ARRAY_SIZE(tps65911_regs));
+ BUILD_BUG_ON(ARRAY_SIZE(tps65911_regs) !=
+ ARRAY_SIZE(tps65911_ext_sleep_control));
pmic->get_ctrl_reg = &tps65911_get_ctrl_register;
pmic->num_regulators = ARRAY_SIZE(tps65911_regs);
pmic->ext_sleep_control = tps65911_ext_sleep_control;
--
2.56.1.839.g22a8290db9-goog
^ permalink raw reply [flat|nested] 9+ messages in thread* [PATCH 5/8] regulator: tps6594-regulator: Bind IRQ resources to child platform device
2026-11-27 18:35 [PATCH 0/8] regulator: Fix locking, OOB read, lifetime, and global state bugs (batch 2) Lee Jones
` (3 preceding siblings ...)
2026-11-27 18:35 ` [PATCH 4/8] regulator: tps65910: Fix OOB read and bit shift in external sleep config Lee Jones
@ 2026-11-27 18:35 ` Lee Jones
2026-11-27 18:35 ` [PATCH 6/8] regulator: core: Respect is_locked when disabling supply on enable failure Lee Jones
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Lee Jones @ 2026-11-27 18:35 UTC (permalink / raw)
To: lee, Liam Girdwood, Mark Brown, Uday Khare, Jerome Neanne,
Mal Nadar, Esteban Blanc, linux-kernel
Cc: stable
tps6594_regulator_probe() and tps6594_request_reg_irqs() allocate IRQ
data and request threaded IRQs using devres attached to the parent MFD
device tps->dev, while registering the regulators with &pdev->dev. If
probe fails partway through or the regulator platform device is unbound,
the regulators are unregistered and freed while the threaded IRQs remain
active with dangling rdev pointers and block subsequent probes.
Attach the devm_kmalloc_objs() allocations and devm_request_threaded_irq()
handlers to &pdev->dev so LIFO devres teardown frees the IRQs before
unregistering the regulators and freeing the IRQ data.
Fixes: f17ccc5deb4d ("regulator: tps6594-regulator: Add driver for TI TPS6594 regulators")
Closes: https://sashiko.dev/#/bug/linux-5557312d-1058-44ee-a8e4-cb48dab3566f
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/regulator/tps6594-regulator.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/regulator/tps6594-regulator.c b/drivers/regulator/tps6594-regulator.c
index 66052753610f..dab4bd6b0282 100644
--- a/drivers/regulator/tps6594-regulator.c
+++ b/drivers/regulator/tps6594-regulator.c
@@ -549,7 +549,7 @@ static int tps6594_request_reg_irqs(struct platform_device *pdev,
irq_data[*irq_idx].type = irq_type;
irq_data[*irq_idx].rdev = rdev;
- error = devm_request_threaded_irq(tps->dev, irq, NULL,
+ error = devm_request_threaded_irq(&pdev->dev, irq, NULL,
tps6594_regulator_irq_handler, IRQF_ONESHOT,
irq_type->irq_name, &irq_data[*irq_idx]);
if (error) {
@@ -738,7 +738,7 @@ static int tps6594_regulator_probe(struct platform_device *pdev)
reg_irq_nb = desc->num_irq_types * (desc->num_buck_regs + desc->num_ldo_regs);
- irq_data = devm_kmalloc_objs(tps->dev,
+ irq_data = devm_kmalloc_objs(&pdev->dev,
struct tps6594_regulator_irq_data,
reg_irq_nb);
if (!irq_data)
@@ -828,7 +828,7 @@ static int tps6594_regulator_probe(struct platform_device *pdev)
return error;
}
- irq_ext_reg_data = devm_kmalloc_objs(tps->dev,
+ irq_ext_reg_data = devm_kmalloc_objs(&pdev->dev,
struct tps6594_ext_regulator_irq_data,
desc->num_ext_irqs);
if (!irq_ext_reg_data)
@@ -843,7 +843,7 @@ static int tps6594_regulator_probe(struct platform_device *pdev)
irq_ext_reg_data[i].dev = tps->dev;
irq_ext_reg_data[i].type = irq_type;
- error = devm_request_threaded_irq(tps->dev, irq, NULL,
+ error = devm_request_threaded_irq(&pdev->dev, irq, NULL,
tps6594_ext_regulator_irq_handler,
IRQF_ONESHOT,
irq_type->irq_name,
--
2.56.1.839.g22a8290db9-goog
^ permalink raw reply [flat|nested] 9+ messages in thread* [PATCH 6/8] regulator: core: Respect is_locked when disabling supply on enable failure
2026-11-27 18:35 [PATCH 0/8] regulator: Fix locking, OOB read, lifetime, and global state bugs (batch 2) Lee Jones
` (4 preceding siblings ...)
2026-11-27 18:35 ` [PATCH 5/8] regulator: tps6594-regulator: Bind IRQ resources to child platform device Lee Jones
@ 2026-11-27 18:35 ` Lee Jones
2026-11-27 18:35 ` [PATCH 7/8] regulator: of: Guard against NULL device_node in of_regulator_bulk_get_all() Lee Jones
2026-11-27 18:35 ` [PATCH 8/8] regulator: aat2870: Duplicate regulator data per device Lee Jones
7 siblings, 0 replies; 9+ messages in thread
From: Lee Jones @ 2026-11-27 18:35 UTC (permalink / raw)
To: lee, Liam Girdwood, Mark Brown, André Draszik, linux-kernel; +Cc: stable
When set_machine_constraints() is called with is_locked set from
regulator_resolve_supply(), it already holds regulator_lock_dependent()
and uses _regulator_enable() to enable rdev->supply. If
_regulator_do_enable() then fails, however, the error path calls
regulator_disable() unconditionally, re-entering
regulator_lock_dependent() and inverting regulator_list_mutex against
the held ww_mutex locks.
Use _regulator_disable() when is_locked is true, matching the enable
path above.
Fixes: 8d38423d9dea ("regulator: core: don't fail regulator_register() with missing required supply")
Closes: https://sashiko.dev/#/bug/linux-e745c649-52f1-4f96-966d-49c3f8addf7a
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/regulator/core.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 18ec8b77e620..121b0b49b8df 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -1688,8 +1688,12 @@ static int set_machine_constraints(struct regulator_dev *rdev,
ret = _regulator_do_enable(rdev);
if (ret < 0 && ret != -EINVAL) {
rdev_err(rdev, "failed to enable: %pe\n", ERR_PTR(ret));
- if (supply_enabled)
- regulator_disable(rdev->supply);
+ if (supply_enabled) {
+ if (is_locked)
+ _regulator_disable(rdev->supply);
+ else
+ regulator_disable(rdev->supply);
+ }
return ret;
}
--
2.56.1.839.g22a8290db9-goog
^ permalink raw reply [flat|nested] 9+ messages in thread* [PATCH 7/8] regulator: of: Guard against NULL device_node in of_regulator_bulk_get_all()
2026-11-27 18:35 [PATCH 0/8] regulator: Fix locking, OOB read, lifetime, and global state bugs (batch 2) Lee Jones
` (5 preceding siblings ...)
2026-11-27 18:35 ` [PATCH 6/8] regulator: core: Respect is_locked when disabling supply on enable failure Lee Jones
@ 2026-11-27 18:35 ` Lee Jones
2026-11-27 18:35 ` [PATCH 8/8] regulator: aat2870: Duplicate regulator data per device Lee Jones
7 siblings, 0 replies; 9+ messages in thread
From: Lee Jones @ 2026-11-27 18:35 UTC (permalink / raw)
To: lee, Liam Girdwood, Mark Brown, Alexey Charkov, Rajendra Nayak,
Corentin Labbe, linux-kernel
Cc: stable
of_regulator_bulk_get_all() passes np straight into
for_each_property_of_node(), which dereferences np->properties without
checking for NULL. Callers passing dev_of_node(dev) on non-DT devices
therefore crash with a NULL pointer dereference.
Return 0 immediately when np is NULL, matching the !CONFIG_OF stub and
the empty-supply case.
Fixes: 27b9ecc7a9ba ("regulator: Add of_regulator_bulk_get_all")
Closes: https://sashiko.dev/#/bug/linux-626e95b1-6ae0-438b-95b4-b7a96b2fd27e
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/regulator/of_regulator.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c
index 81d4f8b6458b..0a316ccefaa9 100644
--- a/drivers/regulator/of_regulator.c
+++ b/drivers/regulator/of_regulator.c
@@ -947,6 +947,9 @@ int of_regulator_bulk_get_all(struct device *dev, struct device_node *np,
char *names;
int i, n = 0, ret;
+ if (!np)
+ return 0;
+
/*
* first pass: get numbers of xxx-supply and the room their names take
* second pass: fill consumers
--
2.56.1.839.g22a8290db9-goog
^ permalink raw reply [flat|nested] 9+ messages in thread* [PATCH 8/8] regulator: aat2870: Duplicate regulator data per device
2026-11-27 18:35 [PATCH 0/8] regulator: Fix locking, OOB read, lifetime, and global state bugs (batch 2) Lee Jones
` (6 preceding siblings ...)
2026-11-27 18:35 ` [PATCH 7/8] regulator: of: Guard against NULL device_node in of_regulator_bulk_get_all() Lee Jones
@ 2026-11-27 18:35 ` Lee Jones
7 siblings, 0 replies; 9+ messages in thread
From: Lee Jones @ 2026-11-27 18:35 UTC (permalink / raw)
To: lee, Liam Girdwood, Mark Brown, Jin Park, Samuel Ortiz, linux-kernel
Cc: stable
aat2870_get_regulator() returns a pointer into the static global
aat2870_regulators array and mutates its fields in place, after which
aat2870_regulator_probe() stores the parent MFD pointer into that shared
entry. Probing a second AAT2870 device overwrites the first device's
state and leads to misrouted operations or use-after-free on removal.
Mark aat2870_regulators const and duplicate the matching entry per
device with devm_kmemdup() before registering the regulator.
Fixes: f7eb6c5e8e5e ("regulator: aat2870: Add AAT2870 regulator driver")
Closes: https://sashiko.dev/#/bug/linux-6f356dcb-fbbc-487c-8fb3-0f765ac5a4d6
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/regulator/aat2870-regulator.c | 30 +++++++++++++++++----------
1 file changed, 19 insertions(+), 11 deletions(-)
diff --git a/drivers/regulator/aat2870-regulator.c b/drivers/regulator/aat2870-regulator.c
index 52c08e6c4803..326886371e85 100644
--- a/drivers/regulator/aat2870-regulator.c
+++ b/drivers/regulator/aat2870-regulator.c
@@ -114,26 +114,33 @@ static const unsigned int aat2870_ldo_voltages[] = {
}, \
}
-static struct aat2870_regulator aat2870_regulators[] = {
+static const struct aat2870_regulator aat2870_regulators[] = {
AAT2870_LDO(LDOA),
AAT2870_LDO(LDOB),
AAT2870_LDO(LDOC),
AAT2870_LDO(LDOD),
};
-static struct aat2870_regulator *aat2870_get_regulator(int id)
+static struct aat2870_regulator *aat2870_get_regulator(struct device *dev,
+ int id)
{
- struct aat2870_regulator *ri = NULL;
+ const struct aat2870_regulator *template = NULL;
+ struct aat2870_regulator *ri;
int i;
for (i = 0; i < ARRAY_SIZE(aat2870_regulators); i++) {
- ri = &aat2870_regulators[i];
- if (ri->desc.id == id)
+ if (aat2870_regulators[i].desc.id == id) {
+ template = &aat2870_regulators[i];
break;
+ }
}
- if (i == ARRAY_SIZE(aat2870_regulators))
- return NULL;
+ if (!template)
+ return ERR_PTR(-EINVAL);
+
+ ri = devm_kmemdup(dev, template, sizeof(*ri), GFP_KERNEL);
+ if (!ri)
+ return ERR_PTR(-ENOMEM);
ri->enable_addr = AAT2870_LDO_EN;
ri->enable_shift = id - AAT2870_ID_LDOA;
@@ -153,10 +160,11 @@ static int aat2870_regulator_probe(struct platform_device *pdev)
struct regulator_config config = { };
struct regulator_dev *rdev;
- ri = aat2870_get_regulator(pdev->id);
- if (!ri) {
- dev_err(&pdev->dev, "Invalid device ID, %d\n", pdev->id);
- return -EINVAL;
+ ri = aat2870_get_regulator(&pdev->dev, pdev->id);
+ if (IS_ERR(ri)) {
+ if (PTR_ERR(ri) == -EINVAL)
+ dev_err(&pdev->dev, "Invalid device ID, %d\n", pdev->id);
+ return PTR_ERR(ri);
}
ri->aat2870 = dev_get_drvdata(pdev->dev.parent);
--
2.56.1.839.g22a8290db9-goog
^ permalink raw reply [flat|nested] 9+ messages in thread