is there a memleak in function pdcs_register_pathentries

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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



[Index of Archives]     [Linux SoC]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux