diff mbox

[v2] IB/mlx5: fix debugfs cleanup

Message ID 1505734128-21708-1-git-send-email-sudip.mukherjee@codethink.co.uk (mailing list archive)
State Accepted
Headers show

Commit Message

Sudip Mukherjee Sept. 18, 2017, 11:28 a.m. UTC
From: Sudip Mukherjee <sudipm.mukherjee@gmail.com>

If delay_drop_debugfs_init() fails in any of the operations to create
debugfs, it is calling delay_drop_debugfs_cleanup() as part of its
cleanup. But delay_drop_debugfs_cleanup() checks for 'dbg' and since
we have not yet pointed 'dbg' to the debugfs we need to cleanup, the
cleanup fails and we are left with stray debugfs elements and also a
memory leak.

Fixes: 4a5fd5d2965c ("IB/mlx5: Add necessary delay drop assignment")
Signed-off-by: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
---
 drivers/infiniband/hw/mlx5/main.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Leon Romanovsky Sept. 18, 2017, 11:49 a.m. UTC | #1
On Mon, Sep 18, 2017 at 12:28:48PM +0100, Sudip Mukherjee wrote:
> From: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
>
> If delay_drop_debugfs_init() fails in any of the operations to create
> debugfs, it is calling delay_drop_debugfs_cleanup() as part of its
> cleanup. But delay_drop_debugfs_cleanup() checks for 'dbg' and since
> we have not yet pointed 'dbg' to the debugfs we need to cleanup, the
> cleanup fails and we are left with stray debugfs elements and also a
> memory leak.
>
> Fixes: 4a5fd5d2965c ("IB/mlx5: Add necessary delay drop assignment")
> Signed-off-by: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
> ---
>  drivers/infiniband/hw/mlx5/main.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/infiniband/hw/mlx5/main.c b/drivers/infiniband/hw/mlx5/main.c
> index ab3c562..05fb4bd 100644
> --- a/drivers/infiniband/hw/mlx5/main.c
> +++ b/drivers/infiniband/hw/mlx5/main.c
> @@ -3837,11 +3837,13 @@ static int delay_drop_debugfs_init(struct mlx5_ib_dev *dev)
>  	if (!dbg)
>  		return -ENOMEM;
>
> +	dev->delay_drop.dbg = dbg;
> +
>  	dbg->dir_debugfs =
>  		debugfs_create_dir("delay_drop",
>  				   dev->mdev->priv.dbg_root);
>  	if (!dbg->dir_debugfs)
> -		return -ENOMEM;
> +		goto out_debugfs;
>

Thanks,
Acked-by: Leon Romanovsky <leonro@mellanox.com>
Doug Ledford Sept. 22, 2017, 5:18 p.m. UTC | #2
On Mon, 2017-09-18 at 12:28 +0100, Sudip Mukherjee wrote:
> From: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
> 
> If delay_drop_debugfs_init() fails in any of the operations to create
> debugfs, it is calling delay_drop_debugfs_cleanup() as part of its
> cleanup. But delay_drop_debugfs_cleanup() checks for 'dbg' and since
> we have not yet pointed 'dbg' to the debugfs we need to cleanup, the
> cleanup fails and we are left with stray debugfs elements and also a
> memory leak.
> 
> Fixes: 4a5fd5d2965c ("IB/mlx5: Add necessary delay drop assignment")
> Signed-off-by: Sudip Mukherjee <sudipm.mukherjee@gmail.com>

Thanks, applied to rc.
diff mbox

Patch

diff --git a/drivers/infiniband/hw/mlx5/main.c b/drivers/infiniband/hw/mlx5/main.c
index ab3c562..05fb4bd 100644
--- a/drivers/infiniband/hw/mlx5/main.c
+++ b/drivers/infiniband/hw/mlx5/main.c
@@ -3837,11 +3837,13 @@  static int delay_drop_debugfs_init(struct mlx5_ib_dev *dev)
 	if (!dbg)
 		return -ENOMEM;
 
+	dev->delay_drop.dbg = dbg;
+
 	dbg->dir_debugfs =
 		debugfs_create_dir("delay_drop",
 				   dev->mdev->priv.dbg_root);
 	if (!dbg->dir_debugfs)
-		return -ENOMEM;
+		goto out_debugfs;
 
 	dbg->events_cnt_debugfs =
 		debugfs_create_atomic_t("num_timeout_events", 0400,
@@ -3865,8 +3867,6 @@  static int delay_drop_debugfs_init(struct mlx5_ib_dev *dev)
 	if (!dbg->timeout_debugfs)
 		goto out_debugfs;
 
-	dev->delay_drop.dbg = dbg;
-
 	return 0;
 
 out_debugfs: