diff mbox series

[v2,2/2] nfp: flower: Remove usage of the deprecated ida_simple_xxx API

Message ID 721abecd2f40bed319ab9fb3feebbea8431b73ed.1644532467.git.christophe.jaillet@wanadoo.fr (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series [v2,1/2] nfp: flower: Fix a potential leak in nfp_tunnel_add_shared_mac() | expand

Checks

Context Check Description
netdev/tree_selection success Guessing tree name failed - patch did not apply

Commit Message

Christophe JAILLET Feb. 10, 2022, 10:35 p.m. UTC
Use ida_alloc_xxx()/ida_free() instead to
ida_simple_get()/ida_simple_remove().
The latter is deprecated and more verbose.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 .../net/ethernet/netronome/nfp/flower/tunnel_conf.c    | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

Comments

Simon Horman Feb. 11, 2022, 8:13 a.m. UTC | #1
On Thu, Feb 10, 2022 at 11:35:04PM +0100, Christophe JAILLET wrote:
> Use ida_alloc_xxx()/ida_free() instead to
> ida_simple_get()/ida_simple_remove().
> The latter is deprecated and more verbose.
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

Thanks for noticing and fixing this. It is much appreciated.

Acked-by: Simon Horman <simon.horman@corigine.com>
Christophe JAILLET June 9, 2022, 5:11 a.m. UTC | #2
Le 10/02/2022 à 23:35, Christophe JAILLET a écrit :
> Use ida_alloc_xxx()/ida_free() instead to
> ida_simple_get()/ida_simple_remove().
> The latter is deprecated and more verbose.
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
>   .../net/ethernet/netronome/nfp/flower/tunnel_conf.c    | 10 +++++-----
>   1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/net/ethernet/netronome/nfp/flower/tunnel_conf.c b/drivers/net/ethernet/netronome/nfp/flower/tunnel_conf.c
> index 9244b35e3855..c71bd555f482 100644
> --- a/drivers/net/ethernet/netronome/nfp/flower/tunnel_conf.c
> +++ b/drivers/net/ethernet/netronome/nfp/flower/tunnel_conf.c
> @@ -942,8 +942,8 @@ nfp_tunnel_add_shared_mac(struct nfp_app *app, struct net_device *netdev,
>   	if (!nfp_mac_idx) {
>   		/* Assign a global index if non-repr or MAC is now shared. */
>   		if (entry || !port) {
> -			ida_idx = ida_simple_get(&priv->tun.mac_off_ids, 0,
> -						 NFP_MAX_MAC_INDEX, GFP_KERNEL);
> +			ida_idx = ida_alloc_max(&priv->tun.mac_off_ids,
> +						NFP_MAX_MAC_INDEX, GFP_KERNEL);
>   			if (ida_idx < 0)
>   				return ida_idx;
>   
> @@ -998,7 +998,7 @@ nfp_tunnel_add_shared_mac(struct nfp_app *app, struct net_device *netdev,
>   	kfree(entry);
>   err_free_ida:
>   	if (ida_idx != -1)
> -		ida_simple_remove(&priv->tun.mac_off_ids, ida_idx);
> +		ida_free(&priv->tun.mac_off_ids, ida_idx);
>   
>   	return err;
>   }
> @@ -1061,7 +1061,7 @@ nfp_tunnel_del_shared_mac(struct nfp_app *app, struct net_device *netdev,
>   		}
>   
>   		ida_idx = nfp_tunnel_get_ida_from_global_mac_idx(entry->index);
> -		ida_simple_remove(&priv->tun.mac_off_ids, ida_idx);
> +		ida_free(&priv->tun.mac_off_ids, ida_idx);
>   		entry->index = nfp_mac_idx;
>   		return 0;
>   	}
> @@ -1081,7 +1081,7 @@ nfp_tunnel_del_shared_mac(struct nfp_app *app, struct net_device *netdev,
>   	/* If MAC has global ID then extract and free the ida entry. */
>   	if (nfp_tunnel_is_mac_idx_global(nfp_mac_idx)) {
>   		ida_idx = nfp_tunnel_get_ida_from_global_mac_idx(entry->index);
> -		ida_simple_remove(&priv->tun.mac_off_ids, ida_idx);
> +		ida_free(&priv->tun.mac_off_ids, ida_idx);
>   	}
>   
>   	kfree(entry);

Hi,

This has been merged in -next in commit 432509013f66 but for some reason 
I looked at it again.


I just wanted to point out that this patch DOES change the behavior of 
the driver because ida_simple_get() is exclusive of the upper bound, 
while ida_alloc_max() is inclusive.

So, knowing that NFP_MAX_MAC_INDEX = 0xff = 255, with the previous code 
'ida_idx' was 0 ... 254.
Now it is 0 ... 255.

This still looks good to me, because NFP_MAX_MAC_INDEX is still not a 
power of 2.


But if 255 is a reserved value for whatever reason, then this patch has 
introduced a bug (apologies for it).

The change of behavior should have been mentioned in the commit 
description. So I wanted to make sure you was aware in case a follow-up 
fix is needed.

CJ
Simon Horman June 9, 2022, 7:32 a.m. UTC | #3
On Thu, Jun 09, 2022 at 07:11:14AM +0200, Christophe JAILLET wrote:
> Le 10/02/2022 à 23:35, Christophe JAILLET a écrit :
> > Use ida_alloc_xxx()/ida_free() instead to
> > ida_simple_get()/ida_simple_remove().
> > The latter is deprecated and more verbose.
> > 
> > Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> > ---
> >   .../net/ethernet/netronome/nfp/flower/tunnel_conf.c    | 10 +++++-----
> >   1 file changed, 5 insertions(+), 5 deletions(-)
> > 
> > diff --git a/drivers/net/ethernet/netronome/nfp/flower/tunnel_conf.c b/drivers/net/ethernet/netronome/nfp/flower/tunnel_conf.c
> > index 9244b35e3855..c71bd555f482 100644
> > --- a/drivers/net/ethernet/netronome/nfp/flower/tunnel_conf.c
> > +++ b/drivers/net/ethernet/netronome/nfp/flower/tunnel_conf.c
> > @@ -942,8 +942,8 @@ nfp_tunnel_add_shared_mac(struct nfp_app *app, struct net_device *netdev,
> >   	if (!nfp_mac_idx) {
> >   		/* Assign a global index if non-repr or MAC is now shared. */
> >   		if (entry || !port) {
> > -			ida_idx = ida_simple_get(&priv->tun.mac_off_ids, 0,
> > -						 NFP_MAX_MAC_INDEX, GFP_KERNEL);
> > +			ida_idx = ida_alloc_max(&priv->tun.mac_off_ids,
> > +						NFP_MAX_MAC_INDEX, GFP_KERNEL);
> >   			if (ida_idx < 0)
> >   				return ida_idx;
> > @@ -998,7 +998,7 @@ nfp_tunnel_add_shared_mac(struct nfp_app *app, struct net_device *netdev,
> >   	kfree(entry);
> >   err_free_ida:
> >   	if (ida_idx != -1)
> > -		ida_simple_remove(&priv->tun.mac_off_ids, ida_idx);
> > +		ida_free(&priv->tun.mac_off_ids, ida_idx);
> >   	return err;
> >   }
> > @@ -1061,7 +1061,7 @@ nfp_tunnel_del_shared_mac(struct nfp_app *app, struct net_device *netdev,
> >   		}
> >   		ida_idx = nfp_tunnel_get_ida_from_global_mac_idx(entry->index);
> > -		ida_simple_remove(&priv->tun.mac_off_ids, ida_idx);
> > +		ida_free(&priv->tun.mac_off_ids, ida_idx);
> >   		entry->index = nfp_mac_idx;
> >   		return 0;
> >   	}
> > @@ -1081,7 +1081,7 @@ nfp_tunnel_del_shared_mac(struct nfp_app *app, struct net_device *netdev,
> >   	/* If MAC has global ID then extract and free the ida entry. */
> >   	if (nfp_tunnel_is_mac_idx_global(nfp_mac_idx)) {
> >   		ida_idx = nfp_tunnel_get_ida_from_global_mac_idx(entry->index);
> > -		ida_simple_remove(&priv->tun.mac_off_ids, ida_idx);
> > +		ida_free(&priv->tun.mac_off_ids, ida_idx);
> >   	}
> >   	kfree(entry);
> 
> Hi,
> 
> This has been merged in -next in commit 432509013f66 but for some reason I
> looked at it again.
> 
> 
> I just wanted to point out that this patch DOES change the behavior of the
> driver because ida_simple_get() is exclusive of the upper bound, while
> ida_alloc_max() is inclusive.
> 
> So, knowing that NFP_MAX_MAC_INDEX = 0xff = 255, with the previous code
> 'ida_idx' was 0 ... 254.
> Now it is 0 ... 255.
> 
> This still looks good to me, because NFP_MAX_MAC_INDEX is still not a power
> of 2.
> 
> 
> But if 255 is a reserved value for whatever reason, then this patch has
> introduced a bug (apologies for it).
> 
> The change of behavior should have been mentioned in the commit description.
> So I wanted to make sure you was aware in case a follow-up fix is needed.

Hi Christophe,

thanks for bringing this to my attention.

When I made my initial review of the patch I did not notice this subtle
change. However, subsequently, the Corigine team did notice and our
conclusion is that it is fine: the code correctly handles all expected
values including 255.

Kind regards,
Simon
diff mbox series

Patch

diff --git a/drivers/net/ethernet/netronome/nfp/flower/tunnel_conf.c b/drivers/net/ethernet/netronome/nfp/flower/tunnel_conf.c
index 9244b35e3855..c71bd555f482 100644
--- a/drivers/net/ethernet/netronome/nfp/flower/tunnel_conf.c
+++ b/drivers/net/ethernet/netronome/nfp/flower/tunnel_conf.c
@@ -942,8 +942,8 @@  nfp_tunnel_add_shared_mac(struct nfp_app *app, struct net_device *netdev,
 	if (!nfp_mac_idx) {
 		/* Assign a global index if non-repr or MAC is now shared. */
 		if (entry || !port) {
-			ida_idx = ida_simple_get(&priv->tun.mac_off_ids, 0,
-						 NFP_MAX_MAC_INDEX, GFP_KERNEL);
+			ida_idx = ida_alloc_max(&priv->tun.mac_off_ids,
+						NFP_MAX_MAC_INDEX, GFP_KERNEL);
 			if (ida_idx < 0)
 				return ida_idx;
 
@@ -998,7 +998,7 @@  nfp_tunnel_add_shared_mac(struct nfp_app *app, struct net_device *netdev,
 	kfree(entry);
 err_free_ida:
 	if (ida_idx != -1)
-		ida_simple_remove(&priv->tun.mac_off_ids, ida_idx);
+		ida_free(&priv->tun.mac_off_ids, ida_idx);
 
 	return err;
 }
@@ -1061,7 +1061,7 @@  nfp_tunnel_del_shared_mac(struct nfp_app *app, struct net_device *netdev,
 		}
 
 		ida_idx = nfp_tunnel_get_ida_from_global_mac_idx(entry->index);
-		ida_simple_remove(&priv->tun.mac_off_ids, ida_idx);
+		ida_free(&priv->tun.mac_off_ids, ida_idx);
 		entry->index = nfp_mac_idx;
 		return 0;
 	}
@@ -1081,7 +1081,7 @@  nfp_tunnel_del_shared_mac(struct nfp_app *app, struct net_device *netdev,
 	/* If MAC has global ID then extract and free the ida entry. */
 	if (nfp_tunnel_is_mac_idx_global(nfp_mac_idx)) {
 		ida_idx = nfp_tunnel_get_ida_from_global_mac_idx(entry->index);
-		ida_simple_remove(&priv->tun.mac_off_ids, ida_idx);
+		ida_free(&priv->tun.mac_off_ids, ida_idx);
 	}
 
 	kfree(entry);