* is there a memleak in function pdcs_register_pathentries
@ 2020-05-06 13:45 亿一
2020-05-06 14:25 ` Helge Deller
0 siblings, 1 reply; 2+ messages in thread
From: 亿一 @ 2020-05-06 13:45 UTC (permalink / raw)
To: James.Bottomley, deller; +Cc: linux-parisc
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 pdcs_register_pathentries() in drivers/parisc/pdc_stable.c may
have the similar issue and leak kobject.
if kobject_init_and_add() failed, the entry->kobj may already
increased it's refcnt and allocated memory to store it's name,
so a kobject_put is need before return.
static inline int __init
pdcs_register_pathentries(void)
{
..
for (i = 0; (entry = pdcspath_entries[i]); i++) {
...
entry->kobj.kset = paths_kset;
err = kobject_init_and_add(&entry->kobj, &ktype_pdcspath, NULL,
"%s", entry->name);
if (err)
return err;
/* kobject is now registered */
write_lock(&entry->rw_lock);
entry->ready = 2;
write_unlock(&entry->rw_lock);
/* Add a nice symlink to the real device */
if (entry->dev) {
err = sysfs_create_link(&entry->kobj, &entry->dev->kobj, "device");
WARN_ON(err);
}
kobject_uevent(&entry->kobj, KOBJ_ADD);
}
return 0;
}
Best regards,
Lin Yi
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: is there a memleak in function pdcs_register_pathentries
2020-05-06 13:45 is there a memleak in function pdcs_register_pathentries 亿一
@ 2020-05-06 14:25 ` Helge Deller
0 siblings, 0 replies; 2+ messages in thread
From: Helge Deller @ 2020-05-06 14:25 UTC (permalink / raw)
To: 亿一, James.Bottomley; +Cc: linux-parisc
Hello Lin Yi,
On 06.05.20 15:45, 亿一 wrote:
> 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 pdcs_register_pathentries() in drivers/parisc/pdc_stable.c may
> have the similar issue and leak kobject.
> if kobject_init_and_add() failed, the entry->kobj may already
> increased it's refcnt and allocated memory to store it's name,
> so a kobject_put is need before return.
Yes, you are correct. It's a possible leak.
Can you send a patch so I can apply it?
Helge
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-05-06 14:25 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-06 13:45 is there a memleak in function pdcs_register_pathentries 亿一
2020-05-06 14:25 ` Helge Deller
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).