[PATCH] vdpa/mlx5: simplfy error handler in mlx5_vdpa_dev_add()

trix@redhat.com posted 1 patch 4 years, 5 months ago
drivers/vdpa/mlx5/net/mlx5_vnet.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
[PATCH] vdpa/mlx5: simplfy error handler in mlx5_vdpa_dev_add()
Posted by trix@redhat.com 4 years, 5 months ago
From: Tom Rix <trix@redhat.com>

The use of pfmdev is protected by two calls to is_zero_ether_add().
The second call in the error handler can be replaced by
checking if pfmdev was set as part of the earlier call.

Signed-off-by: Tom Rix <trix@redhat.com>
---
 drivers/vdpa/mlx5/net/mlx5_vnet.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
index 37220f6db7ad7..2d38b8fe9305e 100644
--- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
+++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
@@ -2530,7 +2530,7 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,
 {
 	struct mlx5_vdpa_mgmtdev *mgtdev = container_of(v_mdev, struct mlx5_vdpa_mgmtdev, mgtdev);
 	struct virtio_net_config *config;
-	struct mlx5_core_dev *pfmdev;
+	struct mlx5_core_dev *pfmdev = NULL;
 	struct mlx5_vdpa_dev *mvdev;
 	struct mlx5_vdpa_net *ndev;
 	struct mlx5_core_dev *mdev;
@@ -2654,7 +2654,7 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,
 err_res:
 	mlx5_vdpa_free_resources(&ndev->mvdev);
 err_mpfs:
-	if (!is_zero_ether_addr(config->mac))
+	if (pfmdev)
 		mlx5_mpfs_del_mac(pfmdev, config->mac);
 err_mtu:
 	mutex_destroy(&ndev->reslock);
-- 
2.26.3

Re: [PATCH] vdpa/mlx5: simplfy error handler in mlx5_vdpa_dev_add()
Posted by Eli Cohen 4 years, 5 months ago
On Sun, Jan 09, 2022 at 05:24:22AM -0800, trix@redhat.com wrote:
> From: Tom Rix <trix@redhat.com>
> 
> The use of pfmdev is protected by two calls to is_zero_ether_add().
> The second call in the error handler can be replaced by
> checking if pfmdev was set as part of the earlier call.
> 
> Signed-off-by: Tom Rix <trix@redhat.com>
> ---

It's not fixing anything, right? Maybe add justification for this change
by e.g. showing the code size had decreased or so?

>  drivers/vdpa/mlx5/net/mlx5_vnet.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> index 37220f6db7ad7..2d38b8fe9305e 100644
> --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
> +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> @@ -2530,7 +2530,7 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,
>  {
>  	struct mlx5_vdpa_mgmtdev *mgtdev = container_of(v_mdev, struct mlx5_vdpa_mgmtdev, mgtdev);
>  	struct virtio_net_config *config;
> -	struct mlx5_core_dev *pfmdev;
> +	struct mlx5_core_dev *pfmdev = NULL;
>  	struct mlx5_vdpa_dev *mvdev;
>  	struct mlx5_vdpa_net *ndev;
>  	struct mlx5_core_dev *mdev;
> @@ -2654,7 +2654,7 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,
>  err_res:
>  	mlx5_vdpa_free_resources(&ndev->mvdev);
>  err_mpfs:
> -	if (!is_zero_ether_addr(config->mac))
> +	if (pfmdev)
>  		mlx5_mpfs_del_mac(pfmdev, config->mac);
>  err_mtu:
>  	mutex_destroy(&ndev->reslock);
> -- 
> 2.26.3
> 
Re: [PATCH] vdpa/mlx5: simplfy error handler in mlx5_vdpa_dev_add()
Posted by Tom Rix 4 years, 5 months ago
On 1/9/22 6:12 AM, Eli Cohen wrote:
> On Sun, Jan 09, 2022 at 05:24:22AM -0800, trix@redhat.com wrote:
>> From: Tom Rix <trix@redhat.com>
>>
>> The use of pfmdev is protected by two calls to is_zero_ether_add().
>> The second call in the error handler can be replaced by
>> checking if pfmdev was set as part of the earlier call.
>>
>> Signed-off-by: Tom Rix <trix@redhat.com>
>> ---
> It's not fixing anything, right?
Correct, or I would have added a Fixes: tag
> Maybe add justification for this change
> by e.g. showing the code size had decreased or so?

Sorry, I thought I had done that.  Generally removing any function call 
is a win and the worst case is a tie.

Tom

>>   drivers/vdpa/mlx5/net/mlx5_vnet.c | 4 ++--
>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
>> index 37220f6db7ad7..2d38b8fe9305e 100644
>> --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
>> +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
>> @@ -2530,7 +2530,7 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,
>>   {
>>   	struct mlx5_vdpa_mgmtdev *mgtdev = container_of(v_mdev, struct mlx5_vdpa_mgmtdev, mgtdev);
>>   	struct virtio_net_config *config;
>> -	struct mlx5_core_dev *pfmdev;
>> +	struct mlx5_core_dev *pfmdev = NULL;
>>   	struct mlx5_vdpa_dev *mvdev;
>>   	struct mlx5_vdpa_net *ndev;
>>   	struct mlx5_core_dev *mdev;
>> @@ -2654,7 +2654,7 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,
>>   err_res:
>>   	mlx5_vdpa_free_resources(&ndev->mvdev);
>>   err_mpfs:
>> -	if (!is_zero_ether_addr(config->mac))
>> +	if (pfmdev)
>>   		mlx5_mpfs_del_mac(pfmdev, config->mac);
>>   err_mtu:
>>   	mutex_destroy(&ndev->reslock);
>> -- 
>> 2.26.3
>>