Message ID | 20210115122010.175920983@linuxfoundation.org |
---|---|
State | New |
Headers | show |
Series | None | expand |
Hi! > From: Xiaolei Wang <xiaolei.wang@windriver.com> > > commit cffa4b2122f5f3e53cf3d529bbc74651f95856d5 upstream. > > 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 ? redistribute? Anyway, this patch is clearly buggy: > > if (!strcmp(name, "dummy")) { > - kfree(map->debugfs_name); > + if (!map->debugfs_name) > + kfree(map->debugfs_name); > It runs kfree only if the variable is NULL. That's clearly useless, kfree(NULL) is NOP, and this causes memory leak. Best regards, Pavel
On Fri, Jan 15, 2021 at 09:18:19PM +0100, Pavel Machek wrote: > Hi! > > > From: Xiaolei Wang <xiaolei.wang@windriver.com> > > > > commit cffa4b2122f5f3e53cf3d529bbc74651f95856d5 upstream. > > > > 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 > > ? redistribute? > > Anyway, this patch is clearly buggy: > > > > > if (!strcmp(name, "dummy")) { > > - kfree(map->debugfs_name); > > + if (!map->debugfs_name) > > + kfree(map->debugfs_name); > > > > It runs kfree only if the variable is NULL. That's clearly useless, > kfree(NULL) is NOP, and this causes memory leak. Fixed by commit f6bcb4c7f366 ("regmap: debugfs: Fix a reversed if statement in regmap_debugfs_init()") in mainline. Cheers, Nathan
--- a/drivers/base/regmap/regmap-debugfs.c +++ b/drivers/base/regmap/regmap-debugfs.c @@ -582,18 +582,25 @@ void regmap_debugfs_init(struct regmap * devname = dev_name(map->dev); if (name) { - map->debugfs_name = kasprintf(GFP_KERNEL, "%s-%s", + if (!map->debugfs_name) { + map->debugfs_name = kasprintf(GFP_KERNEL, "%s-%s", devname, name); + if (!map->debugfs_name) + return; + } name = map->debugfs_name; } else { name = devname; } if (!strcmp(name, "dummy")) { - kfree(map->debugfs_name); + if (!map->debugfs_name) + kfree(map->debugfs_name); map->debugfs_name = kasprintf(GFP_KERNEL, "dummy%d", dummy_index); + if (!map->debugfs_name) + return; name = map->debugfs_name; dummy_index++; }