diff mbox series

RDMA/core: fix missing release in add_port.

Message ID 20200525060656.2478-1-wu000273@umn.edu (mailing list archive)
State Changes Requested
Delegated to: Jason Gunthorpe
Headers show
Series RDMA/core: fix missing release in add_port. | expand

Commit Message

wu000273@umn.edu May 25, 2020, 6:06 a.m. UTC
From: Qiushi Wu <wu000273@umn.edu>

In function add_port(), pointer p is not released in error paths.
Fix this issue by adding a kfree(p) into the end of error path.

Signed-off-by: Qiushi Wu <wu000273@umn.edu>
---
 drivers/infiniband/core/sysfs.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Jason Gunthorpe May 25, 2020, 1:03 p.m. UTC | #1
On Mon, May 25, 2020 at 01:06:56AM -0500, wu000273@umn.edu wrote:
> From: Qiushi Wu <wu000273@umn.edu>
> 
> In function add_port(), pointer p is not released in error paths.
> Fix this issue by adding a kfree(p) into the end of error path.
> 
> Signed-off-by: Qiushi Wu <wu000273@umn.edu>
>  drivers/infiniband/core/sysfs.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/infiniband/core/sysfs.c b/drivers/infiniband/core/sysfs.c
> index 087682e6969e..04a003378dfc 100644
> +++ b/drivers/infiniband/core/sysfs.c
> @@ -1202,6 +1202,7 @@ static int add_port(struct ib_core_device *coredev, int port_num)
>  
>  err_put:
>  	kobject_put(&p->kobj);
> +	kfree(p);
>  	return ret;
>  }

Er, no, kobject_put does the kfree

There is a bug here, it is calling kfree() after kobject_init_and_add
fails, which is wrong, it should be goto err_put

Jason
diff mbox series

Patch

diff --git a/drivers/infiniband/core/sysfs.c b/drivers/infiniband/core/sysfs.c
index 087682e6969e..04a003378dfc 100644
--- a/drivers/infiniband/core/sysfs.c
+++ b/drivers/infiniband/core/sysfs.c
@@ -1202,6 +1202,7 @@  static int add_port(struct ib_core_device *coredev, int port_num)
 
 err_put:
 	kobject_put(&p->kobj);
+	kfree(p);
 	return ret;
 }