[PATCH] power: regulator: pfuze100: Fix accessing the regulator desc
Peng Fan (OSS)
peng.fan at oss.nxp.com
Tue Sep 16 04:57:35 CEST 2025
From: Peng Fan <peng.fan at nxp.com>
se_desc loop check is wrong, it relies on the desc always has
the expected name to end of the loop. It works because the device tree
has the expected name as of now, but this may not be always true.
Drop se_desc by moving the check into probe and fix the loop check.
Reported-by: Andrew Goodbody <andrew.goodbody at linaro.org>
Cc: Tom Rini <trini at konsulko.com>
Cc: Fabio Estevam <festevam at gmail.com>
Signed-off-by: Peng Fan <peng.fan at nxp.com>
---
drivers/power/regulator/pfuze100.c | 44 ++++++++++++------------------
1 file changed, 17 insertions(+), 27 deletions(-)
diff --git a/drivers/power/regulator/pfuze100.c b/drivers/power/regulator/pfuze100.c
index bf3a7019411..f864b1d8834 100644
--- a/drivers/power/regulator/pfuze100.c
+++ b/drivers/power/regulator/pfuze100.c
@@ -241,56 +241,46 @@ static struct dm_regulator_mode pfuze_ldo_modes[] = {
MODE(LDO_MODE_ON, LDO_MODE_ON, "LDO_MODE_ON"),
};
-static struct pfuze100_regulator_desc *se_desc(struct pfuze100_regulator_desc *desc,
- int size,
- const char *name)
-{
- int i;
-
- for (i = 0; i < size; desc++) {
- if (!strcmp(desc->name, name))
- return desc;
- continue;
- }
-
- return NULL;
-}
-
static int pfuze100_regulator_probe(struct udevice *dev)
{
struct dm_regulator_uclass_plat *uc_pdata;
struct pfuze100_regulator_plat *plat = dev_get_plat(dev);
struct pfuze100_regulator_desc *desc;
+ int i, size;
switch (dev_get_driver_data(dev_get_parent(dev))) {
case PFUZE100:
- desc = se_desc(pfuze100_regulators,
- ARRAY_SIZE(pfuze100_regulators),
- dev->name);
+ desc = pfuze100_regulators;
+ size = ARRAY_SIZE(pfuze100_regulators);
break;
case PFUZE200:
- desc = se_desc(pfuze200_regulators,
- ARRAY_SIZE(pfuze200_regulators),
- dev->name);
+ desc = pfuze200_regulators;
+ size = ARRAY_SIZE(pfuze200_regulators);
break;
case PFUZE3000:
- desc = se_desc(pfuze3000_regulators,
- ARRAY_SIZE(pfuze3000_regulators),
- dev->name);
+ desc = pfuze3000_regulators;
+ size = ARRAY_SIZE(pfuze3000_regulators);
break;
default:
debug("Unsupported PFUZE\n");
return -EINVAL;
}
- if (!desc) {
+
+ for (i = 0; i < size; i++) {
+ if (strcmp(desc[i].name, dev->name))
+ continue;
+ break;
+ }
+
+ if (i == size) {
debug("Do not support regulator %s\n", dev->name);
return -EINVAL;
}
- plat->desc = desc;
+ plat->desc = &desc[i];
uc_pdata = dev_get_uclass_plat(dev);
- uc_pdata->type = desc->type;
+ uc_pdata->type = desc[i].type;
if (uc_pdata->type == REGULATOR_TYPE_BUCK) {
if (!strcmp(dev->name, "swbst")) {
uc_pdata->mode = pfuze_swbst_modes;
--
2.35.3
More information about the U-Boot
mailing list