]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
power: regulator: pfuze100: Fix accessing the regulator desc
authorPeng Fan <peng.fan@nxp.com>
Tue, 16 Sep 2025 02:57:35 +0000 (10:57 +0800)
committerFabio Estevam <festevam@gmail.com>
Sat, 20 Sep 2025 20:47:08 +0000 (17:47 -0300)
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@linaro.org>
Cc: Tom Rini <trini@konsulko.com>
Cc: Fabio Estevam <festevam@gmail.com>
Signed-off-by: Peng Fan <peng.fan@nxp.com>
drivers/power/regulator/pfuze100.c

index bf3a7019411e764a19b5ceb0dc259dfd76152369..f864b1d8834d20ad69d4e0b09dadd4b82992451e 100644 (file)
@@ -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;