Skip to content

Commit cffa4b2

Browse files
xiaoleiwang123456broonie
authored andcommitted
regmap: debugfs: Fix a memory leak when calling regmap_attach_dev
After initializing the regmap through syscon_regmap_lookup_by_compatible, then regmap_attach_dev to the device, because the debugfs_name has been allocated, there is no need to redistribute it again unreferenced object 0xd8399b80 (size 64): comm "swapper/0", pid 1, jiffies 4294937641 (age 278.590s) hex dump (first 32 bytes): 64 75 6d 6d 79 2d 69 6f 6d 75 78 63 2d 67 70 72 dummy-iomuxc-gpr 40 32 30 65 34 30 30 30 00 7f 52 5b d8 7e 42 69 @20e4000..R[.~Bi backtrace: [<ca384d6f>] kasprintf+0x2c/0x54 [<6ad3bbc2>] regmap_debugfs_init+0xdc/0x2fc [<bc4181da>] __regmap_init+0xc38/0xd88 [<1f7e0609>] of_syscon_register+0x168/0x294 [<735e8766>] device_node_get_regmap+0x6c/0x98 [<d96c8982>] imx6ul_init_machine+0x20/0x88 [<0456565b>] customize_machine+0x1c/0x30 [<d07393d8>] do_one_initcall+0x80/0x3ac [<7e584867>] kernel_init_freeable+0x170/0x1f0 [<80074741>] kernel_init+0x8/0x120 [<285d6f28>] ret_from_fork+0x14/0x20 [<00000000>] 0x0 Fixes: 9b947a1 ("regmap: use debugfs even when no device") Signed-off-by: Xiaolei Wang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 5c8fe58 commit cffa4b2

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

drivers/base/regmap/regmap-debugfs.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,18 +582,25 @@ void regmap_debugfs_init(struct regmap *map)
582582
devname = dev_name(map->dev);
583583

584584
if (name) {
585-
map->debugfs_name = kasprintf(GFP_KERNEL, "%s-%s",
585+
if (!map->debugfs_name) {
586+
map->debugfs_name = kasprintf(GFP_KERNEL, "%s-%s",
586587
devname, name);
588+
if (!map->debugfs_name)
589+
return;
590+
}
587591
name = map->debugfs_name;
588592
} else {
589593
name = devname;
590594
}
591595

592596
if (!strcmp(name, "dummy")) {
593-
kfree(map->debugfs_name);
597+
if (!map->debugfs_name)
598+
kfree(map->debugfs_name);
594599

595600
map->debugfs_name = kasprintf(GFP_KERNEL, "dummy%d",
596601
dummy_index);
602+
if (!map->debugfs_name)
603+
return;
597604
name = map->debugfs_name;
598605
dummy_index++;
599606
}

0 commit comments

Comments
 (0)