Hi, On Thu, Dec 03, 2026 at 04:12:27PM +0000, Lee Jones wrote: > __power_supply_populate_supplied_from() stores matched supplier names at > the sparse firmware reference index (i - 1) while independently > incrementing psy->num_supplies. If an earlier referenced supply > unregisters concurrently, psy->supplied_from[0] remains NULL while > psy->num_supplies is non-zero, causing __power_supply_is_supplied_by() > to dereference NULL in strcmp(). Furthermore, multiple supplies sharing > the same fwnode can increment num_supplies past the allocated array. > > Pass the allocated slot count to power_supply_populate_supplied_from(), > pack entries densely at psy->supplied_from[psy->num_supplies++], and > stop before exceeding the allocation. > > Fixes: f6e0b081fb30 ("power_supply: Populate supplied_from hierarchy from the device tree") > Closes: https://sashiko.dev/#/bug/linux-a0295e92-ec18-42a6-9e66-60792792613b > Cc: stable@vger.kernel.org > Signed-off-by: Lee Jones > --- This one conflicts with the following patch: https://patch.msgid.link/20261126-psy-core-supplier-fixes-v1-1-33de6aa53cd8@linaro.org Greetings, -- Sebastian > drivers/power/supply/power_supply_core.c | 27 ++++++++++++++++++------ > 1 file changed, 20 insertions(+), 7 deletions(-) > > diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c > index de15314ef954..7488c7b94f40 100644 > --- a/drivers/power/supply/power_supply_core.c > +++ b/drivers/power/supply/power_supply_core.c > @@ -219,10 +219,16 @@ static int power_supply_check_supplies_by_name(struct power_supply *psy) > return 0; > } > > +struct psy_populate_supplied_from_data { > + struct power_supply *psy; > + int max_supplies; > +}; > + > static int __power_supply_populate_supplied_from(struct power_supply *epsy, > void *data) > { > - struct power_supply *psy = data; > + struct psy_populate_supplied_from_data *ctx = data; > + struct power_supply *psy = ctx->psy; > struct fwnode_handle *np; > int i = 0; > > @@ -232,11 +238,13 @@ static int __power_supply_populate_supplied_from(struct power_supply *epsy, > break; > > if (np == epsy->dev.fwnode) { > + fwnode_handle_put(np); > + if (psy->num_supplies >= ctx->max_supplies) > + break; > dev_dbg(&psy->dev, "%s: Found supply : %s\n", > psy->desc->name, epsy->desc->name); > - psy->supplied_from[i-1] = (char *)epsy->desc->name; > - psy->num_supplies++; > - fwnode_handle_put(np); > + psy->supplied_from[psy->num_supplies++] = > + (char *)epsy->desc->name; > break; > } > fwnode_handle_put(np); > @@ -245,11 +253,16 @@ static int __power_supply_populate_supplied_from(struct power_supply *epsy, > return 0; > } > > -static int power_supply_populate_supplied_from(struct power_supply *psy) > +static int power_supply_populate_supplied_from(struct power_supply *psy, > + int max_supplies) > { > + struct psy_populate_supplied_from_data data = { > + .psy = psy, > + .max_supplies = max_supplies, > + }; > int error; > > - error = power_supply_for_each_psy(psy, __power_supply_populate_supplied_from); > + error = power_supply_for_each_psy(&data, __power_supply_populate_supplied_from); > > dev_dbg(&psy->dev, "%s %d\n", __func__, error); > > @@ -326,7 +339,7 @@ static int power_supply_check_supplies(struct power_supply *psy) > if (!psy->supplied_from) > return -ENOMEM; > > - return power_supply_populate_supplied_from(psy); > + return power_supply_populate_supplied_from(psy, cnt); > } > > struct psy_am_i_supplied_data { > -- > 2.56.1.911.g883d8bcb20-goog >