drivers/acpi/sysfs.c:a kobject memleak in acpi_sysfs_add_hotplug_profile?

[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 acpi_sysfs_add_hotplug_profile() in drivers/acpi/sysfs.c may
have the similar issue and leak kobject.
if kobject_init_and_add() failed, the hotplug->kobj may already
increased it's refcnt and allocated memory to store it's name,
so a kobject_put is need before return.
void acpi_sysfs_add_hotplug_profile(struct acpi_hotplug_profile *hotplug,
   const char *name)
{
int error;

if (!hotplug_kobj)
goto err_out;

error = kobject_init_and_add(&hotplug->kobj,
&acpi_hotplug_profile_ktype, hotplug_kobj, "%s", name);
if (error)
goto err_out;

kobject_uevent(&hotplug->kobj, KOBJ_ADD);
return;

 err_out:
pr_err(PREFIX "Unable to add hotplug profile '%s'\n", name);
}


Best regards,
Lin Yi



[Index of Archives]     [Linux IBM ACPI]     [Linux Power Management]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]     [Linux Resources]

  Powered by Linux