[PATCH 7/8] regulator: of: Guard against NULL device_node in of_regulator_bulk_get_all()

From: Lee Jones

Date: Fri Nov 27 2026 - 13:37:19 EST


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@xxxxxxxxxxxxxxx
Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
---
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