linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] RDMA/qib: Fix several reference count leak qib_create_port_files
@ 2020-05-28  2:40 wu000273
  2020-05-28 12:05 ` Wan, Kaike
  0 siblings, 1 reply; 2+ messages in thread
From: wu000273 @ 2020-05-28  2:40 UTC (permalink / raw)
  To: kjlu
  Cc: wu000273, Dennis Dalessandro, Mike Marciniszyn, Doug Ledford,
	Jason Gunthorpe, linux-rdma, linux-kernel

From: Qiushi Wu <wu000273@umn.edu>

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@umn.edu>
---
 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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* RE: [PATCH] RDMA/qib: Fix several reference count leak qib_create_port_files
  2020-05-28  2:40 [PATCH] RDMA/qib: Fix several reference count leak qib_create_port_files wu000273
@ 2020-05-28 12:05 ` Wan, Kaike
  0 siblings, 0 replies; 2+ messages in thread
From: Wan, Kaike @ 2020-05-28 12:05 UTC (permalink / raw)
  To: wu000273, kjlu
  Cc: Dalessandro, Dennis, Marciniszyn, Mike, Doug Ledford,
	Jason Gunthorpe, linux-rdma, linux-kernel

> -----Original Message-----
> From: linux-rdma-owner@vger.kernel.org <linux-rdma-
> owner@vger.kernel.org> On Behalf Of wu000273@umn.edu
> Sent: Wednesday, May 27, 2020 10:41 PM
> To: kjlu@umn.edu
> Cc: wu000273@umn.edu; Dalessandro, Dennis
> <dennis.dalessandro@intel.com>; Marciniszyn, Mike
> <mike.marciniszyn@intel.com>; Doug Ledford <dledford@redhat.com>;
> Jason Gunthorpe <jgg@ziepe.ca>; linux-rdma@vger.kernel.org; linux-
> kernel@vger.kernel.org
> Subject: [PATCH] RDMA/qib: Fix several reference count leak
> qib_create_port_files
> 
> From: Qiushi Wu <wu000273@umn.edu>
> 
> 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@umn.edu>
> ---
>  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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-05-28 12:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-28  2:40 [PATCH] RDMA/qib: Fix several reference count leak qib_create_port_files wu000273
2020-05-28 12:05 ` Wan, Kaike

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).