Skip to content

Commit b1f9c67

Browse files
qsnklassert
authored andcommitted
xfrm: policy: fix sparse warnings in xfrm_policy_{init,fini}
In xfrm_policy_init: add rcu_assign_pointer to fix warning: net/xfrm/xfrm_policy.c:4238:29: warning: incorrect type in assignment (different address spaces) net/xfrm/xfrm_policy.c:4238:29: expected struct hlist_head [noderef] __rcu *table net/xfrm/xfrm_policy.c:4238:29: got struct hlist_head * add rcu_dereference_protected to silence warning: net/xfrm/xfrm_policy.c:4265:36: warning: incorrect type in argument 1 (different address spaces) net/xfrm/xfrm_policy.c:4265:36: expected struct hlist_head *n net/xfrm/xfrm_policy.c:4265:36: got struct hlist_head [noderef] __rcu *table The netns is being created, no concurrent access is possible yet. In xfrm_policy_fini, net is going away, there shouldn't be any concurrent changes to the hashtables, so we can use rcu_dereference_protected to silence warnings: net/xfrm/xfrm_policy.c:4291:17: warning: incorrect type in argument 1 (different address spaces) net/xfrm/xfrm_policy.c:4291:17: expected struct hlist_head const *h net/xfrm/xfrm_policy.c:4291:17: got struct hlist_head [noderef] __rcu *table net/xfrm/xfrm_policy.c:4292:36: warning: incorrect type in argument 1 (different address spaces) net/xfrm/xfrm_policy.c:4292:36: expected struct hlist_head *n net/xfrm/xfrm_policy.c:4292:36: got struct hlist_head [noderef] __rcu *table Signed-off-by: Sabrina Dubroca <[email protected]> Reviewed-by: Simon Horman <[email protected]> Signed-off-by: Steffen Klassert <[email protected]>
1 parent 05b8673 commit b1f9c67

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

net/xfrm/xfrm_policy.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4242,7 +4242,7 @@ static int __net_init xfrm_policy_init(struct net *net)
42424242
net->xfrm.policy_count[XFRM_POLICY_MAX + dir] = 0;
42434243

42444244
htab = &net->xfrm.policy_bydst[dir];
4245-
htab->table = xfrm_hash_alloc(sz);
4245+
rcu_assign_pointer(htab->table, xfrm_hash_alloc(sz));
42464246
if (!htab->table)
42474247
goto out_bydst;
42484248
htab->hmask = hmask;
@@ -4269,7 +4269,7 @@ static int __net_init xfrm_policy_init(struct net *net)
42694269
struct xfrm_policy_hash *htab;
42704270

42714271
htab = &net->xfrm.policy_bydst[dir];
4272-
xfrm_hash_free(htab->table, sz);
4272+
xfrm_hash_free(rcu_dereference_protected(htab->table, true), sz);
42734273
}
42744274
xfrm_hash_free(net->xfrm.policy_byidx, sz);
42754275
out_byidx:
@@ -4295,8 +4295,8 @@ static void xfrm_policy_fini(struct net *net)
42954295

42964296
htab = &net->xfrm.policy_bydst[dir];
42974297
sz = (htab->hmask + 1) * sizeof(struct hlist_head);
4298-
WARN_ON(!hlist_empty(htab->table));
4299-
xfrm_hash_free(htab->table, sz);
4298+
WARN_ON(!hlist_empty(rcu_dereference_protected(htab->table, true)));
4299+
xfrm_hash_free(rcu_dereference_protected(htab->table, true), sz);
43004300
}
43014301

43024302
sz = (net->xfrm.policy_idx_hmask + 1) * sizeof(struct hlist_head);

0 commit comments

Comments
 (0)