diff options
Diffstat (limited to 'drivers/regulator/core.c')
-rw-r--r-- | drivers/regulator/core.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 79a6910eb894..e38db55600e0 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c | |||
@@ -872,6 +872,7 @@ static int set_consumer_device_supply(struct regulator_dev *rdev, | |||
872 | const char *supply) | 872 | const char *supply) |
873 | { | 873 | { |
874 | struct regulator_map *node; | 874 | struct regulator_map *node; |
875 | int has_dev; | ||
875 | 876 | ||
876 | if (consumer_dev && consumer_dev_name) | 877 | if (consumer_dev && consumer_dev_name) |
877 | return -EINVAL; | 878 | return -EINVAL; |
@@ -882,6 +883,11 @@ static int set_consumer_device_supply(struct regulator_dev *rdev, | |||
882 | if (supply == NULL) | 883 | if (supply == NULL) |
883 | return -EINVAL; | 884 | return -EINVAL; |
884 | 885 | ||
886 | if (consumer_dev_name != NULL) | ||
887 | has_dev = 1; | ||
888 | else | ||
889 | has_dev = 0; | ||
890 | |||
885 | list_for_each_entry(node, ®ulator_map_list, list) { | 891 | list_for_each_entry(node, ®ulator_map_list, list) { |
886 | if (consumer_dev_name != node->dev_name) | 892 | if (consumer_dev_name != node->dev_name) |
887 | continue; | 893 | continue; |
@@ -896,17 +902,19 @@ static int set_consumer_device_supply(struct regulator_dev *rdev, | |||
896 | return -EBUSY; | 902 | return -EBUSY; |
897 | } | 903 | } |
898 | 904 | ||
899 | node = kmalloc(sizeof(struct regulator_map), GFP_KERNEL); | 905 | node = kzalloc(sizeof(struct regulator_map), GFP_KERNEL); |
900 | if (node == NULL) | 906 | if (node == NULL) |
901 | return -ENOMEM; | 907 | return -ENOMEM; |
902 | 908 | ||
903 | node->regulator = rdev; | 909 | node->regulator = rdev; |
904 | node->dev_name = kstrdup(consumer_dev_name, GFP_KERNEL); | ||
905 | node->supply = supply; | 910 | node->supply = supply; |
906 | 911 | ||
907 | if (node->dev_name == NULL) { | 912 | if (has_dev) { |
908 | kfree(node); | 913 | node->dev_name = kstrdup(consumer_dev_name, GFP_KERNEL); |
909 | return -ENOMEM; | 914 | if (node->dev_name == NULL) { |
915 | kfree(node); | ||
916 | return -ENOMEM; | ||
917 | } | ||
910 | } | 918 | } |
911 | 919 | ||
912 | list_add(&node->list, ®ulator_map_list); | 920 | list_add(&node->list, ®ulator_map_list); |