linux-rdma.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] net/mlx4_core: Fix error handling in mlx4_init_port_info.
@ 2018-05-13 23:38 Tarick Bedeir
  2018-05-14  6:21 ` Leon Romanovsky
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Tarick Bedeir @ 2018-05-13 23:38 UTC (permalink / raw)
  To: tariqt; +Cc: Greg Thelen, netdev, linux-rdma, linux-kernel, Tarick Bedeir

Avoid exiting the function with a lingering sysfs file (if the first
call to device_create_file() fails while the second succeeds), and avoid
calling devlink_port_unregister() twice.

In other words, either mlx4_init_port_info() succeeds and returns zero, or
it fails, returns non-zero, and requires no cleanup.

Fixes: 096335b3f983 ("mlx4_core: Allow dynamic MTU configuration for IB
ports")
Signed-off-by: Tarick Bedeir <tarick@google.com>
---
v1 -> v2: Added "Fixes" tag.
---
 drivers/net/ethernet/mellanox/mlx4/main.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c
index 4d84cab77105..e8a3a45d0b53 100644
--- a/drivers/net/ethernet/mellanox/mlx4/main.c
+++ b/drivers/net/ethernet/mellanox/mlx4/main.c
@@ -3007,6 +3007,7 @@ static int mlx4_init_port_info(struct mlx4_dev *dev, int port)
 		mlx4_err(dev, "Failed to create file for port %d\n", port);
 		devlink_port_unregister(&info->devlink_port);
 		info->port = -1;
+		return err;
 	}
 
 	sprintf(info->dev_mtu_name, "mlx4_port%d_mtu", port);
@@ -3028,9 +3029,10 @@ static int mlx4_init_port_info(struct mlx4_dev *dev, int port)
 				   &info->port_attr);
 		devlink_port_unregister(&info->devlink_port);
 		info->port = -1;
+		return err;
 	}
 
-	return err;
+	return 0;
 }
 
 static void mlx4_cleanup_port_info(struct mlx4_port_info *info)
-- 
2.17.0.441.gb46fe60e1d-goog

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

* Re: [PATCH v2] net/mlx4_core: Fix error handling in mlx4_init_port_info.
  2018-05-13 23:38 [PATCH v2] net/mlx4_core: Fix error handling in mlx4_init_port_info Tarick Bedeir
@ 2018-05-14  6:21 ` Leon Romanovsky
  2018-05-14  9:08 ` Tariq Toukan
  2018-05-14 20:29 ` David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: Leon Romanovsky @ 2018-05-14  6:21 UTC (permalink / raw)
  To: Tarick Bedeir; +Cc: tariqt, gthelen, netdev, linux-rdma, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 709 bytes --]

On Sun, May 13, 2018 at 04:38:45PM -0700, Tarick Bedeir wrote:
> Avoid exiting the function with a lingering sysfs file (if the first
> call to device_create_file() fails while the second succeeds), and avoid
> calling devlink_port_unregister() twice.
>
> In other words, either mlx4_init_port_info() succeeds and returns zero, or
> it fails, returns non-zero, and requires no cleanup.
>
> Fixes: 096335b3f983 ("mlx4_core: Allow dynamic MTU configuration for IB
> ports")

Please don't break "Fixes" lines, it complicates "grep".

IMHO, general cleanup exit point is needed in this function (goto ...),
but your fix is good enough too. Thanks for doing it.

Reviewed-by: Leon Romanovsky <leonro@mellanox.com>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

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

* Re: [PATCH v2] net/mlx4_core: Fix error handling in mlx4_init_port_info.
  2018-05-13 23:38 [PATCH v2] net/mlx4_core: Fix error handling in mlx4_init_port_info Tarick Bedeir
  2018-05-14  6:21 ` Leon Romanovsky
@ 2018-05-14  9:08 ` Tariq Toukan
  2018-05-14 20:29 ` David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: Tariq Toukan @ 2018-05-14  9:08 UTC (permalink / raw)
  To: Tarick Bedeir, tariqt, gthelen, netdev, linux-rdma, linux-kernel,
	David Miller



On 14/05/2018 2:38 AM, Tarick Bedeir wrote:
> Avoid exiting the function with a lingering sysfs file (if the first
> call to device_create_file() fails while the second succeeds), and avoid
> calling devlink_port_unregister() twice.
> 
> In other words, either mlx4_init_port_info() succeeds and returns zero, or
> it fails, returns non-zero, and requires no cleanup.
> 
> Fixes: 096335b3f983 ("mlx4_core: Allow dynamic MTU configuration for IB
> ports")
> Signed-off-by: Tarick Bedeir <tarick@google.com>
> ---
> v1 -> v2: Added "Fixes" tag.
> ---
>   drivers/net/ethernet/mellanox/mlx4/main.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c
> index 4d84cab77105..e8a3a45d0b53 100644
> --- a/drivers/net/ethernet/mellanox/mlx4/main.c
> +++ b/drivers/net/ethernet/mellanox/mlx4/main.c
> @@ -3007,6 +3007,7 @@ static int mlx4_init_port_info(struct mlx4_dev *dev, int port)
>   		mlx4_err(dev, "Failed to create file for port %d\n", port);
>   		devlink_port_unregister(&info->devlink_port);
>   		info->port = -1;
> +		return err;
>   	}
>   
>   	sprintf(info->dev_mtu_name, "mlx4_port%d_mtu", port);
> @@ -3028,9 +3029,10 @@ static int mlx4_init_port_info(struct mlx4_dev *dev, int port)
>   				   &info->port_attr);
>   		devlink_port_unregister(&info->devlink_port);
>   		info->port = -1;
> +		return err;
>   	}
>   
> -	return err;
> +	return 0;
>   }
>   
>   static void mlx4_cleanup_port_info(struct mlx4_port_info *info)
> 

Thanks for you patch.
Reviewed-by: Tariq Toukan <tariqt@mellanox.com>

Dave, please queue for -stable.

Best,
Tariq

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

* Re: [PATCH v2] net/mlx4_core: Fix error handling in mlx4_init_port_info.
  2018-05-13 23:38 [PATCH v2] net/mlx4_core: Fix error handling in mlx4_init_port_info Tarick Bedeir
  2018-05-14  6:21 ` Leon Romanovsky
  2018-05-14  9:08 ` Tariq Toukan
@ 2018-05-14 20:29 ` David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2018-05-14 20:29 UTC (permalink / raw)
  To: tarick; +Cc: tariqt, gthelen, netdev, linux-rdma, linux-kernel

From: Tarick Bedeir <tarick@google.com>
Date: Sun, 13 May 2018 16:38:45 -0700

> Avoid exiting the function with a lingering sysfs file (if the first
> call to device_create_file() fails while the second succeeds), and avoid
> calling devlink_port_unregister() twice.
> 
> In other words, either mlx4_init_port_info() succeeds and returns zero, or
> it fails, returns non-zero, and requires no cleanup.
> 
> Fixes: 096335b3f983 ("mlx4_core: Allow dynamic MTU configuration for IB
> ports")
> Signed-off-by: Tarick Bedeir <tarick@google.com>
> ---
> v1 -> v2: Added "Fixes" tag.

Applied and queued up for -stable.

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

end of thread, other threads:[~2018-05-14 20:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-13 23:38 [PATCH v2] net/mlx4_core: Fix error handling in mlx4_init_port_info Tarick Bedeir
2018-05-14  6:21 ` Leon Romanovsky
2018-05-14  9:08 ` Tariq Toukan
2018-05-14 20:29 ` David Miller

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).