Yang Yingliang
35593d60b1
regulator: core: fix resource leak in regulator_register()
[ Upstream commit ba62319a42 ]
I got some resource leak reports while doing fault injection test:
OF: ERROR: memory leak, expected refcount 1 instead of 100,
of_node_get()/of_node_put() unbalanced - destroy cset entry:
attach overlay node /i2c/pmic@64/regulators/buck1
unreferenced object 0xffff88810deea000 (size 512):
comm "490-i2c-rt5190a", pid 253, jiffies 4294859840 (age 5061.046s)
hex dump (first 32 bytes):
00 00 00 00 ad 4e ad de ff ff ff ff 00 00 00 00 .....N..........
ff ff ff ff ff ff ff ff a0 1e 00 a1 ff ff ff ff ................
backtrace:
[<00000000d78541e2>] kmalloc_trace+0x21/0x110
[<00000000b343d153>] device_private_init+0x32/0xd0
[<00000000be1f0c70>] device_add+0xb2d/0x1030
[<00000000e3e6344d>] regulator_register+0xaf2/0x12a0
[<00000000e2f5e754>] devm_regulator_register+0x57/0xb0
[<000000008b898197>] rt5190a_probe+0x52a/0x861 [rt5190a_regulator]
unreferenced object 0xffff88810b617b80 (size 32):
comm "490-i2c-rt5190a", pid 253, jiffies 4294859904 (age 5060.983s)
hex dump (first 32 bytes):
72 65 67 75 6c 61 74 6f 72 2e 32 38 36 38 2d 53 regulator.2868-S
55 50 50 4c 59 00 ff ff 29 00 00 00 2b 00 00 00 UPPLY...)...+...
backtrace:
[<000000009da9280d>] __kmalloc_node_track_caller+0x44/0x1b0
[<0000000025c6a4e5>] kstrdup+0x3a/0x70
[<00000000790efb69>] create_regulator+0xc0/0x4e0
[<0000000005ed203a>] regulator_resolve_supply+0x2d4/0x440
[<0000000045796214>] regulator_register+0x10b3/0x12a0
[<00000000e2f5e754>] devm_regulator_register+0x57/0xb0
[<000000008b898197>] rt5190a_probe+0x52a/0x861 [rt5190a_regulator]
After calling regulator_resolve_supply(), the 'rdev->supply' is set
by set_supply(), after this set, in the error path, the resources
need be released, so call regulator_put() to avoid the leaks.
Fixes: aea6cb9970 ("regulator: resolve supply after creating regulator")
Fixes: 8a866d527a ("regulator: core: Resolve supply name earlier to prevent double-init")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Link: https://lore.kernel.org/r/20221202025111.496402-1-yangyingliang@huawei.com
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-01-18 11:41:09 +01:00
..
2019-07-04 17:34:32 +01:00
2019-06-19 17:09:55 +02:00
2019-06-05 17:37:07 +02:00
2019-05-30 11:29:22 -07:00
2019-05-30 11:29:22 -07:00
2020-01-09 10:20:04 +01:00
2019-08-15 18:10:40 +01:00
2019-08-13 12:41:46 +01:00
2019-05-30 11:25:18 -07:00
2019-04-10 12:23:04 +01:00
2019-05-21 21:23:24 +01:00
2019-06-03 17:51:20 +01:00
2019-03-18 12:10:45 +00:00
2019-05-30 11:26:35 -07:00
2021-03-04 10:26:29 +01:00
2019-05-30 11:26:32 -07:00
2021-01-19 18:26:14 +01:00
2021-04-14 08:24:13 +02:00
2020-01-26 10:01:05 +01:00
2023-01-18 11:41:09 +01:00
2019-06-07 13:14:37 +01:00
2019-05-03 15:07:39 +09:00
2021-07-14 16:53:15 +02:00
2019-05-03 15:07:39 +09:00
2019-09-23 14:21:05 -07:00
2019-08-02 12:13:23 +01:00
2019-05-03 15:07:39 +09:00
2019-05-03 15:07:39 +09:00
2019-09-11 11:17:07 +01:00
2019-05-03 15:07:39 +09:00
2019-05-30 11:29:22 -07:00
2019-05-30 11:29:22 -07:00
2019-05-30 11:29:22 -07:00
2019-05-30 11:26:32 -07:00
2019-05-30 11:26:32 -07:00
2019-05-30 11:26:32 -07:00
2019-04-26 10:38:22 +01:00
2019-09-23 14:19:52 -07:00
2019-05-30 11:26:32 -07:00
2020-02-11 04:35:48 -08:00
2021-07-14 16:53:23 +02:00
2021-07-28 13:30:55 +02:00
2019-05-02 11:16:40 +09:00
2019-05-30 11:26:32 -07:00
2019-01-28 15:30:58 +00:00
2019-05-30 11:26:32 -07:00
2019-08-30 12:29:22 +01:00
2019-07-22 13:18:13 +01:00
2019-10-01 17:46:01 +01:00
2019-06-19 17:09:55 +02:00
2019-03-03 23:47:06 +00:00
2019-06-19 17:09:55 +02:00
2019-06-19 17:09:55 +02:00
2019-06-19 17:09:55 +02:00
2019-06-19 17:09:55 +02:00
2019-09-09 10:53:48 +01:00
2019-09-09 13:22:49 +01:00
2019-04-26 10:38:20 +01:00
2019-05-30 11:26:41 -07:00
2019-08-28 11:51:27 +01:00
2019-05-30 11:26:35 -07:00
2019-06-19 17:09:55 +02:00
2019-08-15 15:09:21 +01:00
2019-12-31 16:43:39 +01:00
2019-06-19 17:09:55 +02:00
2019-06-18 19:12:47 +01:00
2018-12-11 01:04:31 +00:00
2019-04-15 09:45:15 +01:00
2019-03-13 15:12:47 +00:00
2021-06-16 11:59:43 +02:00
2019-07-04 17:31:37 +01:00
2019-09-11 11:16:51 +01:00
2019-06-10 15:40:58 +01:00
2019-03-04 00:01:08 +00:00
2019-05-30 11:26:32 -07:00
2019-03-04 00:01:08 +00:00
2019-03-04 00:01:08 +00:00
2019-04-11 12:17:32 +01:00
2019-04-26 10:38:23 +01:00
2019-04-26 10:38:23 +01:00
2019-04-26 10:38:23 +01:00
2021-07-14 16:53:15 +02:00
2019-04-26 10:38:23 +01:00
2019-04-26 10:38:23 +01:00
2022-08-25 11:17:36 +02:00
2019-05-30 11:26:32 -07:00
2019-05-30 11:26:32 -07:00
2019-05-30 11:26:32 -07:00
2022-09-28 11:03:58 +02:00
2019-05-03 15:05:52 +09:00
2019-05-03 15:05:52 +09:00
2019-05-03 15:05:52 +09:00
2019-05-03 15:05:52 +09:00
2019-05-03 15:05:52 +09:00
2019-05-03 15:05:52 +09:00
2020-09-23 12:40:35 +02:00
2022-10-26 13:22:15 +02:00
2022-04-15 14:18:04 +02:00
2019-06-24 17:26:15 +01:00
2021-03-30 14:35:22 +02:00
2019-05-30 11:29:52 -07:00
2020-02-24 08:36:33 +01:00
2020-01-12 12:21:34 +01:00
2019-06-05 17:37:18 +02:00
2019-04-10 12:22:50 +01:00
2019-09-10 11:03:30 +01:00
2021-11-17 09:48:22 +01:00
2019-03-26 13:25:35 +00:00
2019-04-26 10:38:27 +01:00
2022-12-14 11:30:41 +01:00
2019-05-13 11:07:43 +01:00
2019-07-23 12:28:01 +01:00
2019-05-03 15:07:15 +09:00
2020-03-12 13:00:29 +01:00
2019-02-19 11:06:41 +00:00
2019-05-30 11:29:22 -07:00
2019-04-26 10:38:25 +01:00
2019-08-30 12:39:47 +01:00
2020-11-24 13:29:18 +01:00
2019-05-30 11:29:22 -07:00
2019-05-16 17:11:47 +01:00
2019-04-15 09:44:41 +01:00
2019-06-19 17:09:55 +02:00
2019-03-21 15:00:07 +00:00
2019-06-25 15:26:24 +01:00
2019-09-05 19:07:30 +01:00
2019-05-06 22:52:14 +09:00
2019-04-15 09:44:09 +01:00
2019-05-30 11:26:32 -07:00
2019-04-16 17:30:56 +01:00
2022-12-14 11:30:41 +01:00
2019-08-15 15:08:41 +01:00
2021-07-14 16:53:10 +02:00
2019-05-30 11:26:32 -07:00
2021-09-15 09:47:29 +02:00
2019-05-02 11:16:18 +09:00
2019-05-30 11:26:32 -07:00
2019-06-12 13:59:11 +01:00
2019-04-17 17:40:29 +01:00
2019-04-17 17:40:29 +01:00
2019-04-17 17:40:44 +01:00
2019-04-17 17:41:00 +01:00
2022-04-20 09:19:37 +02:00