On Thu, Sep 25, 2025 at 10:33:58AM -0500, Sreedevi Joshi wrote:

...

> diff --git a/drivers/net/ethernet/intel/idpf/idpf_ethtool.c 
> b/drivers/net/ethernet/intel/idpf/idpf_ethtool.c

...

> @@ -184,6 +186,29 @@ static int idpf_add_flow_steer(struct net_device *netdev,
>       if (!rule)
>               return -ENOMEM;
>  
> +     fltr = kzalloc(sizeof(*fltr), GFP_KERNEL);
> +     if (!fltr) {
> +             err = -ENOMEM;
> +             goto out_free_rule;
> +     }
> +
> +     /* detect duplicate entry and reject before adding rules */
> +     spin_lock_bh(&vport_config->flow_steer_list_lock);
> +     list_for_each_entry(f, &user_config->flow_steer_list, list) {
> +             if (f->fs.location == fsp->location) {
> +                     err = -EEXIST;
> +                     break;
> +             }
> +
> +             if (f->fs.location > fsp->location)
> +                     break;
> +             parent = f;
> +     }
> +     spin_unlock_bh(&vport_config->flow_steer_list_lock);
> +
> +     if (err)
> +             goto out;
> +
>       rule->vport_id = cpu_to_le32(vport->vport_id);
>       rule->count = cpu_to_le32(1);
>       info = &rule->rule_info[0];
> @@ -222,28 +247,20 @@ static int idpf_add_flow_steer(struct net_device 
> *netdev,
>               goto out;
>       }
>  
> -     fltr = kzalloc(sizeof(*fltr), GFP_KERNEL);
> -     if (!fltr) {
> -             err = -ENOMEM;
> -             goto out;
> -     }

Sorry, but I'm not following why the allocation of fltr is moved.
It seems that the return path, both for error and non-error cases,
would be slightly simpler without this part of this patch.

> +     /* Save a copy of the user's flow spec so ethtool can later retrieve it 
> */
> +     fltr->fs = *fsp;
>  
> -     fltr->loc = fsp->location;
> -     fltr->q_index = q_index;
>       spin_lock_bh(&vport_config->flow_steer_list_lock);
> -     list_for_each_entry(f, &user_config->flow_steer_list, list) {
> -             if (f->loc >= fltr->loc)
> -                     break;
> -             parent = f;
> -     }
> -
>       parent ? list_add(&fltr->list, &parent->list) :
>                list_add(&fltr->list, &user_config->flow_steer_list);
>  
>       user_config->num_fsteer_fltrs++;
>       spin_unlock_bh(&vport_config->flow_steer_list_lock);
> +     goto out_free_rule;
>  
>  out:
> +     kfree(fltr);
> +out_free_rule:
>       kfree(rule);
>       return err;
>  }

...

Reply via email to