]> Pileus Git - ~andy/linux/blobdiff - drivers/regulator/core.c
regulator: fix unset_regulator_supplies() to remove all matches
[~andy/linux] / drivers / regulator / core.c
index 51cf2bb37438d92f9711bb385fde0f642e663c48..a50672f33afa8f7ea6fb2917b2d870eb42211262 100644 (file)
@@ -944,8 +944,13 @@ static int set_consumer_device_supply(struct regulator_dev *rdev,
                has_dev = 0;
 
        list_for_each_entry(node, &regulator_map_list, list) {
-               if (consumer_dev_name != node->dev_name)
+               if (node->dev_name && consumer_dev_name) {
+                       if (strcmp(node->dev_name, consumer_dev_name) != 0)
+                               continue;
+               } else if (node->dev_name || consumer_dev_name) {
                        continue;
+               }
+
                if (strcmp(node->supply, supply) != 0)
                        continue;
 
@@ -1008,7 +1013,6 @@ static void unset_regulator_supplies(struct regulator_dev *rdev)
                        list_del(&node->list);
                        kfree(node->dev_name);
                        kfree(node);
-                       return;
                }
        }
 }
@@ -2328,7 +2332,37 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,
                goto scrub;
 
        /* set supply regulator if it exists */
+       if (init_data->supply_regulator && init_data->supply_regulator_dev) {
+               dev_err(dev,
+                       "Supply regulator specified by both name and dev\n");
+               goto scrub;
+       }
+
+       if (init_data->supply_regulator) {
+               struct regulator_dev *r;
+               int found = 0;
+
+               list_for_each_entry(r, &regulator_list, list) {
+                       if (strcmp(rdev_get_name(r),
+                                  init_data->supply_regulator) == 0) {
+                               found = 1;
+                               break;
+                       }
+               }
+
+               if (!found) {
+                       dev_err(dev, "Failed to find supply %s\n",
+                               init_data->supply_regulator);
+                       goto scrub;
+               }
+
+               ret = set_supply(rdev, r);
+               if (ret < 0)
+                       goto scrub;
+       }
+
        if (init_data->supply_regulator_dev) {
+               dev_warn(dev, "Uses supply_regulator_dev instead of regulator_supply\n");
                ret = set_supply(rdev,
                        dev_get_drvdata(init_data->supply_regulator_dev));
                if (ret < 0)