[net] net/mlx5: DR, Fix uninitialized var warning

Message ID 20221108015314.17928-1-yuehaibing@huawei.com
State New
Headers
Series [net] net/mlx5: DR, Fix uninitialized var warning |

Commit Message

Yue Haibing Nov. 8, 2022, 1:53 a.m. UTC
  Smatch warns this:

drivers/net/ethernet/mellanox/mlx5/core/steering/dr_table.c:81
 mlx5dr_table_set_miss_action() error: uninitialized symbol 'ret'.

Fix this by initializing ret with zero.

Fixes: 7838e1725394 ("net/mlx5: DR, Expose steering table functionality")
Signed-off-by: YueHaibing <yuehaibing@huawei.com>
---
 drivers/net/ethernet/mellanox/mlx5/core/steering/dr_table.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Roi Dayan Nov. 10, 2022, 8:20 a.m. UTC | #1
On 08/11/2022 3:53, YueHaibing wrote:
> Smatch warns this:
> 
> drivers/net/ethernet/mellanox/mlx5/core/steering/dr_table.c:81
>  mlx5dr_table_set_miss_action() error: uninitialized symbol 'ret'.
> 
> Fix this by initializing ret with zero.
> 
> Fixes: 7838e1725394 ("net/mlx5: DR, Expose steering table functionality")
> Signed-off-by: YueHaibing <yuehaibing@huawei.com>
> ---
>  drivers/net/ethernet/mellanox/mlx5/core/steering/dr_table.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/steering/dr_table.c b/drivers/net/ethernet/mellanox/mlx5/core/steering/dr_table.c
> index 31d443dd8386..44dea75dabde 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/steering/dr_table.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/steering/dr_table.c
> @@ -46,7 +46,7 @@ static int dr_table_set_miss_action_nic(struct mlx5dr_domain *dmn,
>  int mlx5dr_table_set_miss_action(struct mlx5dr_table *tbl,
>  				 struct mlx5dr_action *action)
>  {
> -	int ret;
> +	int ret = 0;
>  
>  	if (action && action->action_type != DR_ACTION_TYP_FT)
>  		return -EOPNOTSUPP;


In this case the default should be an error
It will be better if ret init to -EOPNOTSUPP and if
a miss action was not set and replaces ret then goto out.

 int mlx5dr_table_set_miss_action(struct mlx5dr_table *tbl,
                                 struct mlx5dr_action *action)
 {
-       int ret;
+       int ret = -EOPNOTSUPP;
 
        if (action && action->action_type != DR_ACTION_TYP_FT)
                return -EOPNOTSUPP;
@@ -67,6 +67,9 @@ int mlx5dr_table_set_miss_action(struct mlx5dr_table *tbl,
                        goto out;
        }
 
+       if (ret)
+               goto out;
+
  
Yue Haibing Nov. 10, 2022, 11:06 a.m. UTC | #2
On 2022/11/10 16:20, Roi Dayan wrote:
> 
> 
> On 08/11/2022 3:53, YueHaibing wrote:
>> Smatch warns this:
>>
>> drivers/net/ethernet/mellanox/mlx5/core/steering/dr_table.c:81
>>  mlx5dr_table_set_miss_action() error: uninitialized symbol 'ret'.
>>
>> Fix this by initializing ret with zero.
>>
>> Fixes: 7838e1725394 ("net/mlx5: DR, Expose steering table functionality")
>> Signed-off-by: YueHaibing <yuehaibing@huawei.com>
>> ---
>>  drivers/net/ethernet/mellanox/mlx5/core/steering/dr_table.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/steering/dr_table.c b/drivers/net/ethernet/mellanox/mlx5/core/steering/dr_table.c
>> index 31d443dd8386..44dea75dabde 100644
>> --- a/drivers/net/ethernet/mellanox/mlx5/core/steering/dr_table.c
>> +++ b/drivers/net/ethernet/mellanox/mlx5/core/steering/dr_table.c
>> @@ -46,7 +46,7 @@ static int dr_table_set_miss_action_nic(struct mlx5dr_domain *dmn,
>>  int mlx5dr_table_set_miss_action(struct mlx5dr_table *tbl,
>>  				 struct mlx5dr_action *action)
>>  {
>> -	int ret;
>> +	int ret = 0;
>>  
>>  	if (action && action->action_type != DR_ACTION_TYP_FT)
>>  		return -EOPNOTSUPP;
> 
> 
> In this case the default should be an error
> It will be better if ret init to -EOPNOTSUPP and if
> a miss action was not set and replaces ret then goto out.

Thanks for your review, will do that in v2.

> 
>  int mlx5dr_table_set_miss_action(struct mlx5dr_table *tbl,
>                                  struct mlx5dr_action *action)
>  {
> -       int ret;
> +       int ret = -EOPNOTSUPP;
>  
>         if (action && action->action_type != DR_ACTION_TYP_FT)
>                 return -EOPNOTSUPP;
> @@ -67,6 +67,9 @@ int mlx5dr_table_set_miss_action(struct mlx5dr_table *tbl,
>                         goto out;
>         }
>  
> +       if (ret)
> +               goto out;
> +
> 
> .
>
  

Patch

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/steering/dr_table.c b/drivers/net/ethernet/mellanox/mlx5/core/steering/dr_table.c
index 31d443dd8386..44dea75dabde 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/steering/dr_table.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/steering/dr_table.c
@@ -46,7 +46,7 @@  static int dr_table_set_miss_action_nic(struct mlx5dr_domain *dmn,
 int mlx5dr_table_set_miss_action(struct mlx5dr_table *tbl,
 				 struct mlx5dr_action *action)
 {
-	int ret;
+	int ret = 0;
 
 	if (action && action->action_type != DR_ACTION_TYP_FT)
 		return -EOPNOTSUPP;