Linux-EDAC Archive on lore.kernel.org
 help / color / Atom feed
* [BUG] is there a memleak in edac_device_register_sysfs_main_kobj
@ 2020-05-06 13:04 亿一
  0 siblings, 0 replies; only message in thread
From: 亿一 @ 2020-05-06 13:04 UTC (permalink / raw)
  To: bp, mchehab, tony.luck; +Cc: linux-edac

Hi all,
I notice that most of the usage of kobject_init_and_add in drivers are
wrong, and now some drivers code has maken it right
please see commit dfb5394f804e (https://lkml.org/lkml/2020/4/11/282)
function edac_device_register_sysfs_main_kobj() in
drivers/edac/edac_device_sysfs.c may
have the similar issue and leak kobject.
if kobject_init_and_add() failed, the edac_dev->kobj may already
increased it's refcnt and allocated memory to store it's name,
so a kobject_put is need before return.

int edac_device_register_sysfs_main_kobj(struct edac_device_ctl_info *edac_dev)
{
...

/* register */
err = kobject_init_and_add(&edac_dev->kobj,
&ktype_device_ctrl,&edac_subsys->dev_root->kobj,  "%s",
edac_dev->name);
if (err) {
    edac_dbg(1, "Failed to register '.../edac/%s'\n",   edac_dev->name);
    goto err_kobj_reg;
}
kobject_uevent(&edac_dev->kobj, KOBJ_ADD);

/* At this point, to 'free' the control struct,
* edac_device_unregister_sysfs_main_kobj() must be used
*/

edac_dbg(4, "Registered '.../edac/%s' kobject\n", edac_dev->name);

return 0;

/* Error exit stack */
err_kobj_reg:
      module_put(edac_dev->owner);

err_out:
      return err;
}

Best regards,
Lin Yi

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-06 13:04 [BUG] is there a memleak in edac_device_register_sysfs_main_kobj 亿一

Linux-EDAC Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-edac/0 linux-edac/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-edac linux-edac/ https://lore.kernel.org/linux-edac \
		linux-edac@vger.kernel.org
	public-inbox-index linux-edac

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-edac


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git