[BUG] is there a memleak in function qib_create_port_files

[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 qib_create_port_files() in /drivers/infiniband/hw/qib/qib_sysfs.c may
have the similar issue and leak kobject.
if kobject_init_and_add() failed, the ppd->pport_kobj->kobj may already
increased it's refcnt and allocated memory to store it's name,
so a kobject_put is need before return.

int qib_create_port_files(struct ib_device *ibdev, u8 port_num,
 struct kobject *kobj)
{
struct qib_pportdata *ppd;
struct qib_devdata *dd = dd_from_ibdev(ibdev);
int ret;

if (!port_num || port_num > dd->num_pports) {
    qib_dev_err(dd, "Skipping infiniband class with invalid port
%u\n", port_num);
    ret = -ENODEV;
    goto bail;
}
ppd = &dd->pport[port_num - 1];

ret = kobject_init_and_add(&ppd->pport_kobj, &qib_port_ktype, kobj,
"linkcontrol");
if (ret) {
    qib_dev_err(dd, "Skipping linkcontrol sysfs info, (err %d) port
%u\n", ret, port_num);
    goto bail;
}
...

bail:
    return ret;
}



Best regards,
Lin Yi



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

  Powered by Linux