linux-edac.vger.kernel.org archive mirror
 help / color / mirror / 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, other threads:[~2020-05-06 13:04 UTC | newest]

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 亿一

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).