linux/drivers/regulator
Vladimir Zapolskiy afa16b50e2 regulator: fix memory leak on error path of regulator_register()
[ Upstream commit 9177514ce3 ]

The change corrects registration and deregistration on error path
of a regulator, the problem was manifested by a reported memory
leak on deferred probe:

    as3722-regulator as3722-regulator: regulator 13 register failed -517

    # cat /sys/kernel/debug/kmemleak
    unreferenced object 0xecc43740 (size 64):
      comm "swapper/0", pid 1, jiffies 4294937640 (age 712.880s)
      hex dump (first 32 bytes):
        72 65 67 75 6c 61 74 6f 72 2e 32 34 00 5a 5a 5a  regulator.24.ZZZ
        5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a  ZZZZZZZZZZZZZZZZ
      backtrace:
        [<0c4c3d1c>] __kmalloc_track_caller+0x15c/0x2c0
        [<40c0ad48>] kvasprintf+0x64/0xd4
        [<109abd29>] kvasprintf_const+0x70/0x84
        [<c4215946>] kobject_set_name_vargs+0x34/0xa8
        [<62282ea2>] dev_set_name+0x40/0x64
        [<a39b6757>] regulator_register+0x3a4/0x1344
        [<16a9543f>] devm_regulator_register+0x4c/0x84
        [<51a4c6a1>] as3722_regulator_probe+0x294/0x754
        ...

The memory leak problem was introduced as a side ef another fix in
regulator_register() error path, I believe that the proper fix is
to decouple device_register() function into its two compounds and
initialize a struct device before assigning any values to its fields
and then using it before actual registration of a device happens.

This lets to call put_device() safely after initialization, and, since
now a release callback is called, kfree(rdev->constraints) shall be
removed to exclude a double free condition.

Fixes: a3cde9534e ("regulator: core: fix regulator_register() error paths to properly release rdev")
Signed-off-by: Vladimir Zapolskiy <vz@mleia.com>
Cc: Wen Yang <wenyang@linux.alibaba.com>
Link: https://lore.kernel.org/r/20200724005013.23278-1-vz@mleia.com
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2020-08-19 08:15:57 +02:00
..
88pg86x.c
88pm800-regulator.c Merge branch 'regulator-5.3' into regulator-next 2019-07-04 17:34:32 +01:00
88pm8607.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
Kconfig regulator: mt6358: Add BROKEN dependency while waiting for MFD to merge 2019-08-30 12:29:22 +01:00
Makefile regulator: mt6358: Add support for MT6358 regulator 2019-08-28 11:51:27 +01:00
aat2870-regulator.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 336 2019-06-05 17:37:07 +02:00
ab3100.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 194 2019-05-30 11:29:22 -07:00
ab8500-ext.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 197 2019-05-30 11:29:22 -07:00
ab8500.c regulator: ab8500: Remove AB8505 USB regulator 2020-01-09 10:20:04 +01:00
act8865-regulator.c regulator: act8865: operating mode and suspend state support 2019-08-15 18:10:40 +01:00
act8945a-regulator.c regulator: act8945a-regulator: fix ldo register addresses in set_mode hook 2019-08-13 12:41:46 +01:00
ad5398.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 149 2019-05-30 11:25:18 -07:00
anatop-regulator.c
arizona-ldo1.c
arizona-micsupp.c regulator: arizona-micsupp: Delete unused include 2019-06-03 17:51:20 +01:00
as3711-regulator.c
as3722-regulator.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 156 2019-05-30 11:26:35 -07:00
axp20x-regulator.c regulator: axp20x: Fix AXP22x ELDO2 regulator enable bitmask 2020-01-09 10:20:04 +01:00
bcm590xx-regulator.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
bd718x7-regulator.c - Core Frameworks 2019-07-15 20:18:40 -07:00
bd9571mwv-regulator.c
bd70528-regulator.c regulator: bd70528: Add MODULE_ALIAS to allow module auto loading 2020-01-26 10:01:05 +01:00
core.c regulator: fix memory leak on error path of regulator_register() 2020-08-19 08:15:57 +02:00
cpcap-regulator.c regulator: cpcap: Spelling s/configuraion/configuration/ 2019-06-07 13:14:37 +01:00
da903x.c
da9052-regulator.c
da9055-regulator.c
da9062-regulator.c regulator: da9062: fix suspend_enable/disable preparation 2019-09-23 14:21:05 -07:00
da9063-regulator.c regulator: Remove dev_err() usage after platform_get_irq() 2019-08-02 12:13:23 +01:00
da9210-regulator.c
da9210-regulator.h
da9211-regulator.c regulator: da9211: fix obtaining "enable" GPIO 2019-09-11 11:17:07 +01:00
da9211-regulator.h
db8500-prcmu.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 197 2019-05-30 11:29:22 -07:00
dbx500-prcmu.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 197 2019-05-30 11:29:22 -07:00
dbx500-prcmu.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 197 2019-05-30 11:29:22 -07:00
devres.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
dummy.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
dummy.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
fan53555.c
fixed-helper.c
fixed.c regulator: fixed: Prevent NULL pointer dereference when !CONFIG_OF 2019-09-23 14:19:52 -07:00
gpio-regulator.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
helpers.c regulator: core: Add regulator_is_equal() helper 2020-02-11 04:35:48 -08:00
hi655x-regulator.c
hi6421-regulator.c
hi6421v530-regulator.c
internal.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
isl6271a-regulator.c
isl9305.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
lm363x-regulator.c regulator: lm363x: Fix n_voltages setting for lm36274 2019-07-22 13:18:13 +01:00
lochnagar-regulator.c regulator: lochnagar: Add on_off_delay for VDDCORE 2019-10-01 17:46:01 +01:00
lp872x.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
lp873x-regulator.c
lp3971.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
lp3972.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
lp8755.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
lp8788-buck.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
lp8788-ldo.c regulator: lp8788-ldo: make array en_mask static const, makes object smaller 2019-09-09 10:53:48 +01:00
lp87565-regulator.c regulator: lp87565: Simplify lp87565_buck_set_ramp_delay 2019-09-09 13:22:49 +01:00
ltc3589.c
ltc3676.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 174 2019-05-30 11:26:41 -07:00
max1586.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 156 2019-05-30 11:26:35 -07:00
max8649.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
max8660.c regulator: max8660: remove redundant assignment of variable ret 2019-08-15 15:09:21 +01:00
max8907-regulator.c regulator: max8907: Fix the usage of uninitialized variable in max8907_regulator_probe() 2019-12-31 16:43:39 +01:00
max8925-regulator.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
max8952.c Linux 5.2-rc4 2019-06-18 19:12:47 +01:00
max8973-regulator.c
max8997-regulator.c
max8998.c
max14577-regulator.c
max77620-regulator.c regulator: max77620: remove redundant assignment to variable ret 2019-07-03 13:02:38 +01:00
max77650-regulator.c regulator: max77650: use vsel_step 2019-07-04 17:31:37 +01:00
max77686-regulator.c regulator: max77686: fix obtaining "maxim,ena" GPIO 2019-09-11 11:16:51 +01:00
max77693-regulator.c
max77802-regulator.c regulator: max77802: Drop unused includes 2019-06-10 15:40:58 +01:00
mc13xxx-regulator-core.c
mc13xxx.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
mc13783-regulator.c
mc13892-regulator.c
mcp16502.c
mt6311-regulator.c
mt6311-regulator.h
mt6323-regulator.c
mt6358-regulator.c regulator: mt6358: Add support for MT6358 regulator 2019-08-28 11:51:27 +01:00
mt6380-regulator.c
mt6397-regulator.c
of_regulator.c regulator: Fixes for v5.4 2019-10-23 15:31:17 -04:00
palmas-regulator.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
pbias-regulator.c
pcap-regulator.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
pcf50633-regulator.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
pfuze100-regulator.c regualtor: pfuze100: correct sw1a/sw2 on pfuze3000 2020-06-30 15:36:54 -04:00
pv88060-regulator.c
pv88060-regulator.h
pv88080-regulator.c
pv88080-regulator.h
pv88090-regulator.c
pv88090-regulator.h
pwm-regulator.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
qcom-rpmh-regulator.c regulator: qcom-rpmh: Fix typos in pm8150 and pm8150l 2020-06-22 09:30:58 +02:00
qcom_rpm-regulator.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 284 2019-06-05 17:36:37 +02:00
qcom_smd-regulator.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 284 2019-06-05 17:36:37 +02:00
qcom_spmi-regulator.c regulator: qcom_spmi: Do NULL check for lvs 2019-06-24 17:26:15 +01:00
rc5t583-regulator.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 201 2019-05-30 11:29:52 -07:00
rk808-regulator.c regulator: rk808: Lower log level on optional GPIOs being not available 2020-02-24 08:36:33 +01:00
rn5t618-regulator.c regulator: rn5t618: fix module aliases 2020-01-12 12:21:34 +01:00
rt5033-regulator.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 450 2019-06-05 17:37:18 +02:00
s2mpa01.c
s2mps11.c regulator: s2mps11: Consistently use local variable 2019-09-10 11:03:30 +01:00
s5m8767.c gpio: Fix return value mismatch of function gpiod_get_from_of_node() 2019-06-25 15:26:24 +01:00
sc2731-regulator.c
sky81452-regulator.c
slg51000-regulator.c regulator: slg51000: use devm_gpiod_get_optional() in probe 2019-09-09 10:58:15 +01:00
slg51000-regulator.h
stm32-booster.c regulator: stm32-booster: Remove .min_uV and .list_voltage for fixed regulator 2019-07-23 12:28:01 +01:00
stm32-pwr.c
stm32-vrefbuf.c regulator: stm32-vrefbuf: fix a possible overshoot when re-enabling 2020-03-12 13:00:29 +01:00
stpmic1_regulator.c
stw481x-vmmc.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 194 2019-05-30 11:29:22 -07:00
sy8106a-regulator.c
sy8824x.c regulator: sy8824x: add prefixes to BUCK_EN and MODE macros 2019-08-30 12:39:47 +01:00
ti-abb-regulator.c regulator: ti-abb: Fix timeout in ti_abb_wait_txdone/ti_abb_clear_all_txdone 2019-10-01 12:21:02 +01:00
tps6105x-regulator.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 194 2019-05-30 11:29:22 -07:00
tps6507x-regulator.c
tps6524x-regulator.c
tps6586x-regulator.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
tps51632-regulator.c
tps62360-regulator.c
tps65023-regulator.c
tps65086-regulator.c
tps65090-regulator.c gpio: Fix return value mismatch of function gpiod_get_from_of_node() 2019-06-25 15:26:24 +01:00
tps65132-regulator.c regulator: tps65132: Stop parsing DT when gpio is not found 2019-09-05 19:07:30 +01:00
tps65217-regulator.c
tps65218-regulator.c
tps65910-regulator.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
tps65912-regulator.c
tps80031-regulator.c
twl-regulator.c regulator: twl: voltage lists for vdd1/2 on twl4030 2019-08-15 15:08:41 +01:00
twl6030-regulator.c regulator: twl6030: workaround the VMMC reset behavior 2019-08-09 18:04:22 +01:00
uniphier-regulator.c regulator: uniphier: Add Pro5 USB3 VBUS support 2019-09-10 11:04:12 +01:00
userspace-consumer.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
vctrl-regulator.c regulator: vctrl-regulator: Avoid deadlock getting and setting the voltage 2020-02-24 08:36:52 +01:00
vexpress-regulator.c
virtual.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
wm831x-dcdc.c regulator: wm831x: Convert to use GPIO descriptors 2019-06-12 13:59:11 +01:00
wm831x-isink.c
wm831x-ldo.c
wm8350-regulator.c
wm8400-regulator.c
wm8994-regulator.c