Skip to content

Commit 557bc4f

Browse files
osctobegregkh
authored andcommitted
regulator: push allocations in create_regulator() outside of lock
commit 87fe29b upstream. Move all allocations outside of the regulator_lock()ed section. ====================================================== WARNING: possible circular locking dependency detected 5.7.13+ torvalds#535 Not tainted ------------------------------------------------------ f2fs_discard-179:7/702 is trying to acquire lock: c0e5d920 (regulator_list_mutex){+.+.}-{3:3}, at: regulator_lock_dependent+0x54/0x2c0 but task is already holding lock: cb95b080 (&dcc->cmd_lock){+.+.}-{3:3}, at: __issue_discard_cmd+0xec/0x5f8 which lock already depends on the new lock. the existing dependency chain (in reverse order) is: [...] -> #3 (fs_reclaim){+.+.}-{0:0}: fs_reclaim_acquire.part.11+0x40/0x50 fs_reclaim_acquire+0x24/0x28 __kmalloc_track_caller+0x54/0x218 kstrdup+0x40/0x5c create_regulator+0xf4/0x368 regulator_resolve_supply+0x1a0/0x200 regulator_register+0x9c8/0x163c [...] other info that might help us debug this: Chain exists of: regulator_list_mutex --> &sit_i->sentry_lock --> &dcc->cmd_lock [...] Fixes: f8702f9 ("regulator: core: Use ww_mutex for regulators locking") Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl> Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/6eebc99b2474f4ffaa0405b15178ece0e7e4f608.1597195321.git.mirq-linux@rere.qmqm.pl Signed-off-by: Mark Brown <broonie@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 96ccd5a commit 557bc4f

File tree

1 file changed

+28
-25
lines changed

1 file changed

+28
-25
lines changed

drivers/regulator/core.c

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1579,44 +1579,53 @@ static struct regulator *create_regulator(struct regulator_dev *rdev,
15791579
const char *supply_name)
15801580
{
15811581
struct regulator *regulator;
1582-
char buf[REG_STR_SIZE];
1583-
int err, size;
1582+
int err;
1583+
1584+
if (dev) {
1585+
char buf[REG_STR_SIZE];
1586+
int size;
1587+
1588+
size = snprintf(buf, REG_STR_SIZE, "%s-%s",
1589+
dev->kobj.name, supply_name);
1590+
if (size >= REG_STR_SIZE)
1591+
return NULL;
1592+
1593+
supply_name = kstrdup(buf, GFP_KERNEL);
1594+
if (supply_name == NULL)
1595+
return NULL;
1596+
} else {
1597+
supply_name = kstrdup_const(supply_name, GFP_KERNEL);
1598+
if (supply_name == NULL)
1599+
return NULL;
1600+
}
15841601

15851602
regulator = kzalloc(sizeof(*regulator), GFP_KERNEL);
1586-
if (regulator == NULL)
1603+
if (regulator == NULL) {
1604+
kfree(supply_name);
15871605
return NULL;
1606+
}
15881607

1589-
regulator_lock(rdev);
15901608
regulator->rdev = rdev;
1609+
regulator->supply_name = supply_name;
1610+
1611+
regulator_lock(rdev);
15911612
list_add(&regulator->list, &rdev->consumer_list);
1613+
regulator_unlock(rdev);
15921614

15931615
if (dev) {
15941616
regulator->dev = dev;
15951617

15961618
/* Add a link to the device sysfs entry */
1597-
size = snprintf(buf, REG_STR_SIZE, "%s-%s",
1598-
dev->kobj.name, supply_name);
1599-
if (size >= REG_STR_SIZE)
1600-
goto overflow_err;
1601-
1602-
regulator->supply_name = kstrdup(buf, GFP_KERNEL);
1603-
if (regulator->supply_name == NULL)
1604-
goto overflow_err;
1605-
16061619
err = sysfs_create_link_nowarn(&rdev->dev.kobj, &dev->kobj,
1607-
buf);
1620+
supply_name);
16081621
if (err) {
16091622
rdev_dbg(rdev, "could not add device link %s err %d\n",
16101623
dev->kobj.name, err);
16111624
/* non-fatal */
16121625
}
1613-
} else {
1614-
regulator->supply_name = kstrdup_const(supply_name, GFP_KERNEL);
1615-
if (regulator->supply_name == NULL)
1616-
goto overflow_err;
16171626
}
16181627

1619-
regulator->debugfs = debugfs_create_dir(regulator->supply_name,
1628+
regulator->debugfs = debugfs_create_dir(supply_name,
16201629
rdev->debugfs);
16211630
if (!regulator->debugfs) {
16221631
rdev_dbg(rdev, "Failed to create debugfs directory\n");
@@ -1641,13 +1650,7 @@ static struct regulator *create_regulator(struct regulator_dev *rdev,
16411650
_regulator_is_enabled(rdev))
16421651
regulator->always_on = true;
16431652

1644-
regulator_unlock(rdev);
16451653
return regulator;
1646-
overflow_err:
1647-
list_del(&regulator->list);
1648-
kfree(regulator);
1649-
regulator_unlock(rdev);
1650-
return NULL;
16511654
}
16521655

16531656
static int _regulator_get_enable_time(struct regulator_dev *rdev)

0 commit comments

Comments
 (0)