From: 亿一 <teroincn@gmail.com>
To: bp@alien8.de, mchehab@kernel.org, tony.luck@intel.com
Cc: linux-edac@vger.kernel.org
Subject: [BUG] is there a memleak in edac_device_register_sysfs_main_kobj
Date: Wed, 6 May 2020 21:04:02 +0800 [thread overview]
Message-ID: <CANTwqXA8_cdV9TRqRrLjTngoiaABji=XA7AfcdvV_D1GQYRYYA@mail.gmail.com> (raw)
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
reply other threads:[~2020-05-06 13:04 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CANTwqXA8_cdV9TRqRrLjTngoiaABji=XA7AfcdvV_D1GQYRYYA@mail.gmail.com' \
--to=teroincn@gmail.com \
--cc=bp@alien8.de \
--cc=linux-edac@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=tony.luck@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).