Skip to content

Commit 8adb4e6

Browse files
osctobebroonie
authored andcommitted
regulator/core: regulator_register: set device->class earlier
When fixing a memory leak in commit d3c7315 ("regulator: plug of_node leak in regulator_register()'s error path") it moved the device_initialize() call earlier, but did not move the `dev->class` initialization. The bug was spotted and fixed by reverting part of the commit (in commit 5f4b204 "regulator: core: fix kobject release warning and memory leak in regulator_register()") but introducing a different bug: now early error paths use `kfree(dev)` instead of `put_device()` for an already initialized `struct device`. Move the missing assignments to just after `device_initialize()`. Fixes: d3c7315 ("regulator: plug of_node leak in regulator_register()'s error path") Signed-off-by: Michał Mirosław <[email protected]> Link: https://lore.kernel.org/r/b5b19cb458c40c9d02f3d5a7bd1ba7d97ba17279.1695077303.git.mirq-linux@rere.qmqm.pl Signed-off-by: Mark Brown <[email protected]>
1 parent 7e37c85 commit 8adb4e6

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/regulator/core.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5542,6 +5542,8 @@ regulator_register(struct device *dev,
55425542
goto rinse;
55435543
}
55445544
device_initialize(&rdev->dev);
5545+
dev_set_drvdata(&rdev->dev, rdev);
5546+
rdev->dev.class = &regulator_class;
55455547
spin_lock_init(&rdev->err_lock);
55465548

55475549
/*
@@ -5603,11 +5605,9 @@ regulator_register(struct device *dev,
56035605
rdev->supply_name = regulator_desc->supply_name;
56045606

56055607
/* register with sysfs */
5606-
rdev->dev.class = &regulator_class;
56075608
rdev->dev.parent = config->dev;
56085609
dev_set_name(&rdev->dev, "regulator.%lu",
56095610
(unsigned long) atomic_inc_return(&regulator_no));
5610-
dev_set_drvdata(&rdev->dev, rdev);
56115611

56125612
/* set regulator constraints */
56135613
if (init_data)

0 commit comments

Comments
 (0)