summaryrefslogtreecommitdiff
path: root/drivers/power
diff options
context:
space:
mode:
authorPeng Fan <[email protected]>2025-09-16 10:57:35 +0800
committerFabio Estevam <[email protected]>2025-09-20 17:47:08 -0300
commit2727de799a644f4db15e8682503f783a62fa4af2 (patch)
treedc6f062907b826b259e9d111ff2dbdbacd276351 /drivers/power
parent8918b60e33157dd6abaaf11ea24437da133eed0a (diff)
power: regulator: pfuze100: Fix accessing the regulator desc
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 <[email protected]> Cc: Tom Rini <[email protected]> Cc: Fabio Estevam <[email protected]> Signed-off-by: Peng Fan <[email protected]>
Diffstat (limited to 'drivers/power')
-rw-r--r--drivers/power/regulator/pfuze100.c44
1 files 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;