From: Qiushi Wu <[email protected]>
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 <[email protected]>
---
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
> -----Original Message-----
> From: [email protected] <linux-rdma-
> [email protected]> On Behalf Of [email protected]
> Sent: Wednesday, May 27, 2020 10:41 PM
> To: [email protected]
> Cc: [email protected]; Dalessandro, Dennis
> <[email protected]>; Marciniszyn, Mike
> <[email protected]>; Doug Ledford <[email protected]>;
> Jason Gunthorpe <[email protected]>; [email protected]; linux-
> [email protected]
> Subject: [PATCH] RDMA/qib: Fix several reference count leak
> qib_create_port_files
>
> From: Qiushi Wu <[email protected]>
>
> 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 <[email protected]>
> ---
> 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