diff mbox series

[net-next,2/3] ipv6: broadly use fib6_info_hold() helper

Message ID 20190423013503.217729-3-edumazet@google.com
State Accepted
Delegated to: David Miller
Headers show
Series ipv6: fib6_ref conversion to refcount_t | expand

Commit Message

Eric Dumazet April 23, 2019, 1:35 a.m. UTC
Instead of using atomic_inc(), prefer fib6_info_hold()
so that upcoming refcount_t conversion is simpler.

Only fib6_info_alloc() is using atomic_set() since we
just allocated a new object.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Wei Wang <weiwan@google.com>
---
 net/ipv6/ip6_fib.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

Comments

Wei Wang April 23, 2019, 4:31 p.m. UTC | #1
On Mon, Apr 22, 2019 at 6:35 PM Eric Dumazet <edumazet@google.com> wrote:
>
> Instead of using atomic_inc(), prefer fib6_info_hold()
> so that upcoming refcount_t conversion is simpler.
>
> Only fib6_info_alloc() is using atomic_set() since we
> just allocated a new object.
>
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Cc: Wei Wang <weiwan@google.com>
> ---

Acked-by: Wei Wang <weiwan@google.com>

>  net/ipv6/ip6_fib.c | 16 ++++++++--------
>  1 file changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c
> index 55193859152969794dab3df02637217a7f21016f..a5e83593e0e45c2762eca85d04757f9d8e118e0f 100644
> --- a/net/ipv6/ip6_fib.c
> +++ b/net/ipv6/ip6_fib.c
> @@ -162,7 +162,7 @@ struct fib6_info *fib6_info_alloc(gfp_t gfp_flags)
>         }
>
>         INIT_LIST_HEAD(&f6i->fib6_siblings);
> -       atomic_inc(&f6i->fib6_ref);
> +       atomic_set(&f6i->fib6_ref, 1);
>
>         return f6i;
>  }
> @@ -846,8 +846,8 @@ static struct fib6_node *fib6_add_1(struct net *net,
>
>                 RCU_INIT_POINTER(in->parent, pn);
>                 in->leaf = fn->leaf;
> -               atomic_inc(&rcu_dereference_protected(in->leaf,
> -                               lockdep_is_held(&table->tb6_lock))->fib6_ref);
> +               fib6_info_hold(rcu_dereference_protected(in->leaf,
> +                               lockdep_is_held(&table->tb6_lock)));
>
>                 /* update parent pointer */
>                 if (dir)
> @@ -942,7 +942,7 @@ static void fib6_purge_rt(struct fib6_info *rt, struct fib6_node *fn,
>                         struct fib6_info *new_leaf;
>                         if (!(fn->fn_flags & RTN_RTINFO) && leaf == rt) {
>                                 new_leaf = fib6_find_prefix(net, table, fn);
> -                               atomic_inc(&new_leaf->fib6_ref);
> +                               fib6_info_hold(new_leaf);
>
>                                 rcu_assign_pointer(fn->leaf, new_leaf);
>                                 fib6_info_release(rt);
> @@ -1108,7 +1108,7 @@ static int fib6_add_rt2node(struct fib6_node *fn, struct fib6_info *rt,
>                         return err;
>
>                 rcu_assign_pointer(rt->fib6_next, iter);
> -               atomic_inc(&rt->fib6_ref);
> +               fib6_info_hold(rt);
>                 rcu_assign_pointer(rt->fib6_node, fn);
>                 rcu_assign_pointer(*ins, rt);
>                 if (!info->skip_notify)
> @@ -1136,7 +1136,7 @@ static int fib6_add_rt2node(struct fib6_node *fn, struct fib6_info *rt,
>                 if (err)
>                         return err;
>
> -               atomic_inc(&rt->fib6_ref);
> +               fib6_info_hold(rt);
>                 rcu_assign_pointer(rt->fib6_node, fn);
>                 rt->fib6_next = iter->fib6_next;
>                 rcu_assign_pointer(*ins, rt);
> @@ -1278,7 +1278,7 @@ int fib6_add(struct fib6_node *root, struct fib6_info *rt,
>                         if (!sfn)
>                                 goto failure;
>
> -                       atomic_inc(&info->nl_net->ipv6.fib6_null_entry->fib6_ref);
> +                       fib6_info_hold(info->nl_net->ipv6.fib6_null_entry);
>                         rcu_assign_pointer(sfn->leaf,
>                                            info->nl_net->ipv6.fib6_null_entry);
>                         sfn->fn_flags = RTN_ROOT;
> @@ -1321,7 +1321,7 @@ int fib6_add(struct fib6_node *root, struct fib6_info *rt,
>                                 rcu_assign_pointer(fn->leaf,
>                                             info->nl_net->ipv6.fib6_null_entry);
>                         } else {
> -                               atomic_inc(&rt->fib6_ref);
> +                               fib6_info_hold(rt);
>                                 rcu_assign_pointer(fn->leaf, rt);
>                         }
>                 }
> --
> 2.21.0.593.g511ec345e18-goog
>
David Ahern April 23, 2019, 4:36 p.m. UTC | #2
On 4/22/19 7:35 PM, Eric Dumazet wrote:
> Instead of using atomic_inc(), prefer fib6_info_hold()
> so that upcoming refcount_t conversion is simpler.
> 
> Only fib6_info_alloc() is using atomic_set() since we
> just allocated a new object.
> 
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Cc: Wei Wang <weiwan@google.com>
> ---
>  net/ipv6/ip6_fib.c | 16 ++++++++--------
>  1 file changed, 8 insertions(+), 8 deletions(-)
> 

Reviewed-by: David Ahern <dsahern@gmail.com>
diff mbox series

Patch

diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c
index 55193859152969794dab3df02637217a7f21016f..a5e83593e0e45c2762eca85d04757f9d8e118e0f 100644
--- a/net/ipv6/ip6_fib.c
+++ b/net/ipv6/ip6_fib.c
@@ -162,7 +162,7 @@  struct fib6_info *fib6_info_alloc(gfp_t gfp_flags)
 	}
 
 	INIT_LIST_HEAD(&f6i->fib6_siblings);
-	atomic_inc(&f6i->fib6_ref);
+	atomic_set(&f6i->fib6_ref, 1);
 
 	return f6i;
 }
@@ -846,8 +846,8 @@  static struct fib6_node *fib6_add_1(struct net *net,
 
 		RCU_INIT_POINTER(in->parent, pn);
 		in->leaf = fn->leaf;
-		atomic_inc(&rcu_dereference_protected(in->leaf,
-				lockdep_is_held(&table->tb6_lock))->fib6_ref);
+		fib6_info_hold(rcu_dereference_protected(in->leaf,
+				lockdep_is_held(&table->tb6_lock)));
 
 		/* update parent pointer */
 		if (dir)
@@ -942,7 +942,7 @@  static void fib6_purge_rt(struct fib6_info *rt, struct fib6_node *fn,
 			struct fib6_info *new_leaf;
 			if (!(fn->fn_flags & RTN_RTINFO) && leaf == rt) {
 				new_leaf = fib6_find_prefix(net, table, fn);
-				atomic_inc(&new_leaf->fib6_ref);
+				fib6_info_hold(new_leaf);
 
 				rcu_assign_pointer(fn->leaf, new_leaf);
 				fib6_info_release(rt);
@@ -1108,7 +1108,7 @@  static int fib6_add_rt2node(struct fib6_node *fn, struct fib6_info *rt,
 			return err;
 
 		rcu_assign_pointer(rt->fib6_next, iter);
-		atomic_inc(&rt->fib6_ref);
+		fib6_info_hold(rt);
 		rcu_assign_pointer(rt->fib6_node, fn);
 		rcu_assign_pointer(*ins, rt);
 		if (!info->skip_notify)
@@ -1136,7 +1136,7 @@  static int fib6_add_rt2node(struct fib6_node *fn, struct fib6_info *rt,
 		if (err)
 			return err;
 
-		atomic_inc(&rt->fib6_ref);
+		fib6_info_hold(rt);
 		rcu_assign_pointer(rt->fib6_node, fn);
 		rt->fib6_next = iter->fib6_next;
 		rcu_assign_pointer(*ins, rt);
@@ -1278,7 +1278,7 @@  int fib6_add(struct fib6_node *root, struct fib6_info *rt,
 			if (!sfn)
 				goto failure;
 
-			atomic_inc(&info->nl_net->ipv6.fib6_null_entry->fib6_ref);
+			fib6_info_hold(info->nl_net->ipv6.fib6_null_entry);
 			rcu_assign_pointer(sfn->leaf,
 					   info->nl_net->ipv6.fib6_null_entry);
 			sfn->fn_flags = RTN_ROOT;
@@ -1321,7 +1321,7 @@  int fib6_add(struct fib6_node *root, struct fib6_info *rt,
 				rcu_assign_pointer(fn->leaf,
 					    info->nl_net->ipv6.fib6_null_entry);
 			} else {
-				atomic_inc(&rt->fib6_ref);
+				fib6_info_hold(rt);
 				rcu_assign_pointer(fn->leaf, rt);
 			}
 		}