Will post a patch soon. Kaike > -----Original Message----- > From: linux-rdma-owner@xxxxxxxxxxxxxxx <linux-rdma- > owner@xxxxxxxxxxxxxxx> On Behalf Of ?? > Sent: Wednesday, May 06, 2020 9:41 AM > To: Dalessandro, Dennis <dennis.dalessandro@xxxxxxxxx> > Cc: Marciniszyn, Mike <mike.marciniszyn@xxxxxxxxx>; linux- > rdma@xxxxxxxxxxxxxxx > Subject: [BUG] is there a memleak in function qib_create_port_files > > 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