RE: [PATCH] RDMA/qib: Fix several reference count leak qib_create_port_files

From: Wan, Kaike
Date: Thu May 28 2020 - 08:06:31 EST


> -----Original Message-----
> From: linux-rdma-owner@xxxxxxxxxxxxxxx <linux-rdma-
> owner@xxxxxxxxxxxxxxx> On Behalf Of wu000273@xxxxxxx
> Sent: Wednesday, May 27, 2020 10:41 PM
> To: kjlu@xxxxxxx
> Cc: wu000273@xxxxxxx; Dalessandro, Dennis
> <dennis.dalessandro@xxxxxxxxx>; Marciniszyn, Mike
> <mike.marciniszyn@xxxxxxxxx>; Doug Ledford <dledford@xxxxxxxxxx>;
> Jason Gunthorpe <jgg@xxxxxxxx>; linux-rdma@xxxxxxxxxxxxxxx; linux-
> kernel@xxxxxxxxxxxxxxx
> Subject: [PATCH] RDMA/qib: Fix several reference count leak
> qib_create_port_files
>
> From: Qiushi Wu <wu000273@xxxxxxx>
>
> kobject_init_and_add() takes reference even when it fails.
> If this function returns an error, kobject_put() must be called to properly
> clean up the memory associated with the object. To fix these issues, we
> correct the jump targets when the calls of
> kobject_init_and_add() fail, to make sure they can be handled by
> kobject_put(). Previous commit "b8eb718348b8" fixed a similar problem.
>
> Signed-off-by: Qiushi Wu <wu000273@xxxxxxx>
> ---
> drivers/infiniband/hw/qib/qib_sysfs.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/infiniband/hw/qib/qib_sysfs.c
> b/drivers/infiniband/hw/qib/qib_sysfs.c
> index 568b21eb6ea1..017ed82070f9 100644
> --- a/drivers/infiniband/hw/qib/qib_sysfs.c
> +++ b/drivers/infiniband/hw/qib/qib_sysfs.c
> @@ -760,7 +760,7 @@ int qib_create_port_files(struct ib_device *ibdev, u8
> port_num,
> qib_dev_err(dd,
> "Skipping linkcontrol sysfs info, (err %d) port %u\n",
> ret, port_num);
> - goto bail;
> + goto bail_link;
> }
> kobject_uevent(&ppd->pport_kobj, KOBJ_ADD);
>
> @@ -770,7 +770,7 @@ int qib_create_port_files(struct ib_device *ibdev, u8
> port_num,
> qib_dev_err(dd,
> "Skipping sl2vl sysfs info, (err %d) port %u\n",
> ret, port_num);
> - goto bail_link;
> + goto bail_sl;
> }
> kobject_uevent(&ppd->sl2vl_kobj, KOBJ_ADD);
>
> @@ -780,7 +780,7 @@ int qib_create_port_files(struct ib_device *ibdev, u8
> port_num,
> qib_dev_err(dd,
> "Skipping diag_counters sysfs info, (err %d)
> port %u\n",
> ret, port_num);
> - goto bail_sl;
> + goto bail_diagc;
> }
> kobject_uevent(&ppd->diagc_kobj, KOBJ_ADD);
>
> @@ -793,7 +793,7 @@ int qib_create_port_files(struct ib_device *ibdev, u8
> port_num,
> qib_dev_err(dd,
> "Skipping Congestion Control sysfs info, (err %d) port %u\n",
> ret, port_num);
> - goto bail_diagc;
> + goto bail_cc;
> }
>
> kobject_uevent(&ppd->pport_cc_kobj, KOBJ_ADD);
> --
> 2.17.1
Already fixed:

https://marc.info/?l=linux-rdma&m=158925321102485&w=2

Kaike