Skip to content

Commit 5c06540

Browse files
osctobebroonie
authored andcommitted
regulator: push allocation in set_consumer_device_supply() out of lock
Pull regulator_list_mutex into set_consumer_device_supply() and keep allocations outside of it. Fourth of the fs_reclaim deadlock case. Fixes: 45389c4 ("regulator: core: Add early supply resolution for regulators") Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl> Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/f0380bdb3d60aeefa9693c4e234d2dcda7e56747.1597195321.git.mirq-linux@rere.qmqm.pl Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 87fe29b commit 5c06540

File tree

1 file changed

+26
-20
lines changed

1 file changed

+26
-20
lines changed

drivers/regulator/core.c

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,7 +1461,7 @@ static int set_consumer_device_supply(struct regulator_dev *rdev,
14611461
const char *consumer_dev_name,
14621462
const char *supply)
14631463
{
1464-
struct regulator_map *node;
1464+
struct regulator_map *node, *new_node;
14651465
int has_dev;
14661466

14671467
if (supply == NULL)
@@ -1472,6 +1472,22 @@ static int set_consumer_device_supply(struct regulator_dev *rdev,
14721472
else
14731473
has_dev = 0;
14741474

1475+
new_node = kzalloc(sizeof(struct regulator_map), GFP_KERNEL);
1476+
if (new_node == NULL)
1477+
return -ENOMEM;
1478+
1479+
new_node->regulator = rdev;
1480+
new_node->supply = supply;
1481+
1482+
if (has_dev) {
1483+
new_node->dev_name = kstrdup(consumer_dev_name, GFP_KERNEL);
1484+
if (new_node->dev_name == NULL) {
1485+
kfree(new_node);
1486+
return -ENOMEM;
1487+
}
1488+
}
1489+
1490+
mutex_lock(&regulator_list_mutex);
14751491
list_for_each_entry(node, &regulator_map_list, list) {
14761492
if (node->dev_name && consumer_dev_name) {
14771493
if (strcmp(node->dev_name, consumer_dev_name) != 0)
@@ -1489,26 +1505,19 @@ static int set_consumer_device_supply(struct regulator_dev *rdev,
14891505
node->regulator->desc->name,
14901506
supply,
14911507
dev_name(&rdev->dev), rdev_get_name(rdev));
1492-
return -EBUSY;
1508+
goto fail;
14931509
}
14941510

1495-
node = kzalloc(sizeof(struct regulator_map), GFP_KERNEL);
1496-
if (node == NULL)
1497-
return -ENOMEM;
1498-
1499-
node->regulator = rdev;
1500-
node->supply = supply;
1501-
1502-
if (has_dev) {
1503-
node->dev_name = kstrdup(consumer_dev_name, GFP_KERNEL);
1504-
if (node->dev_name == NULL) {
1505-
kfree(node);
1506-
return -ENOMEM;
1507-
}
1508-
}
1511+
list_add(&new_node->list, &regulator_map_list);
1512+
mutex_unlock(&regulator_list_mutex);
15091513

1510-
list_add(&node->list, &regulator_map_list);
15111514
return 0;
1515+
1516+
fail:
1517+
mutex_unlock(&regulator_list_mutex);
1518+
kfree(new_node->dev_name);
1519+
kfree(new_node);
1520+
return -EBUSY;
15121521
}
15131522

15141523
static void unset_regulator_supplies(struct regulator_dev *rdev)
@@ -5269,19 +5278,16 @@ regulator_register(const struct regulator_desc *regulator_desc,
52695278

52705279
/* add consumers devices */
52715280
if (init_data) {
5272-
mutex_lock(&regulator_list_mutex);
52735281
for (i = 0; i < init_data->num_consumer_supplies; i++) {
52745282
ret = set_consumer_device_supply(rdev,
52755283
init_data->consumer_supplies[i].dev_name,
52765284
init_data->consumer_supplies[i].supply);
52775285
if (ret < 0) {
5278-
mutex_unlock(&regulator_list_mutex);
52795286
dev_err(dev, "Failed to set supply %s\n",
52805287
init_data->consumer_supplies[i].supply);
52815288
goto unset_supplies;
52825289
}
52835290
}
5284-
mutex_unlock(&regulator_list_mutex);
52855291
}
52865292

52875293
if (!rdev->desc->ops->get_voltage &&

0 commit comments

Comments
 (0)