Message ID | E1hRAg8-0004Fy-0O@gondobar |
---|---|
State | Accepted |
Delegated to: | David Miller |
Headers | show |
Series | rhashtable: Fix sparse warnings | expand |
From: Herbert Xu > Sent: 16 May 2019 08:20 > As cmpxchg is a non-RCU mechanism it will cause sparse warnings > when we use it for RCU. This patch adds explicit casts to silence > those warnings. This should probably be moved to RCU itself in > future. > ... > - if (cmpxchg(prev, NULL, ntbl) == NULL) > + if (cmpxchg((union nested_table **)prev, NULL, ntbl) == NULL) I presume these casts remove an 'rcu' marker on the variable. Is there a way of marking such casts as 'for sparse only' so that the compiler does proper type checking. (Clearly this isn't that relevant here as the cast could be (void **).) Hmmm something should be checking that the type of the argument to cmpxchg is 'pointer to "something the size of a pointer"' Adding any kind of cast subverts that test. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
On Thu, May 16, 2019 at 09:20:36AM +0000, David Laight wrote: > > I presume these casts remove an 'rcu' marker on the variable. > Is there a way of marking such casts as 'for sparse only' so > that the compiler does proper type checking. > (Clearly this isn't that relevant here as the cast could be (void **).) > > Hmmm something should be checking that the type of the argument > to cmpxchg is 'pointer to "something the size of a pointer"' > Adding any kind of cast subverts that test. If we were adding this as an RCU primitive then yes that what it should do. But it isn't relevant to this patch. Cheers,
diff --git a/lib/rhashtable.c b/lib/rhashtable.c index 7708699a5b96..935ec80f213f 100644 --- a/lib/rhashtable.c +++ b/lib/rhashtable.c @@ -131,7 +131,7 @@ static union nested_table *nested_table_alloc(struct rhashtable *ht, INIT_RHT_NULLS_HEAD(ntbl[i].bucket); } - if (cmpxchg(prev, NULL, ntbl) == NULL) + if (cmpxchg((union nested_table **)prev, NULL, ntbl) == NULL) return ntbl; /* Raced with another thread. */ kfree(ntbl); @@ -296,7 +296,8 @@ static int rhashtable_rehash_attach(struct rhashtable *ht, * rcu_assign_pointer(). */ - if (cmpxchg(&old_tbl->future_tbl, NULL, new_tbl) != NULL) + if (cmpxchg((struct bucket_table **)&old_tbl->future_tbl, NULL, + new_tbl) != NULL) return -EEXIST; return 0;
As cmpxchg is a non-RCU mechanism it will cause sparse warnings when we use it for RCU. This patch adds explicit casts to silence those warnings. This should probably be moved to RCU itself in future. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> --- lib/rhashtable.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)