* [PATCH] rhashtable: Fix safe iterator cursor substitution
@ 2026-11-21 7:24 Avi Weiss
0 siblings, 0 replies; only message in thread
From: Avi Weiss @ 2026-11-21 7:24 UTC (permalink / raw)
To: herbert; +Cc: tgraf, linux-crypto, Avi Weiss
rht_for_each_entry_safe() uses next as both a macro parameter and the
rhash_head member name. Passing a cursor with another name substitutes
that name into pos->next, producing a nonexistent struct member and a
compilation failure.
Rename the cursor parameter to _next to preserve the pos->next member
accesses regardless of the caller's variable name.
Fixes: 88d6ed15acff ("rhashtable: Convert bucket iterators to take table and index")
Signed-off-by: Avi Weiss <thnkslprpt@gmail.com>
---
Alternative approaches considered:
- Use a differently named cursor parameter such as next_node. This is
equivalent in behavior; _next keeps the change smaller.
- Remove the unused macro. That avoids the broken expansion but also
removes an existing interface potentially used outside the tree.
Validation:
- Original macro: next compiles; saved, tmp and next_entry fail.
- Corrected macro: all four names compile in the isolated source probe.
- The original next expansion is byte-identical after the correction.
- No in-tree expanding consumer was found in the tested base revision.
- Full kernel Kbuild, runtime and external consumers were not tested.
include/linux/rhashtable.h | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/include/linux/rhashtable.h b/include/linux/rhashtable.h
index 70dac9214617..00838bf88117 100644
--- a/include/linux/rhashtable.h
+++ b/include/linux/rhashtable.h
@@ -482,7 +482,7 @@ static inline void rht_assign_unlock(struct bucket_table *tbl,
* rht_for_each_entry_safe - safely iterate over hash chain of given type
* @tpos: the type * to use as a loop cursor.
* @pos: the &struct rhash_head to use as a loop cursor.
- * @next: the &struct rhash_head to use as next in loop cursor.
+ * @_next: the &struct rhash_head to use as next in loop cursor.
* @tbl: the &struct bucket_table
* @hash: the hash value / bucket index
* @member: name of the &struct rhash_head within the hashable struct.
@@ -490,13 +490,13 @@ static inline void rht_assign_unlock(struct bucket_table *tbl,
* This hash chain list-traversal primitive allows for the looped code to
* remove the loop cursor from the list.
*/
-#define rht_for_each_entry_safe(tpos, pos, next, tbl, hash, member) \
+#define rht_for_each_entry_safe(tpos, pos, _next, tbl, hash, member) \
for (pos = rht_ptr(rht_bucket(tbl, hash), tbl, hash), \
- next = !rht_is_a_nulls(pos) ? \
+ _next = !rht_is_a_nulls(pos) ? \
rht_dereference_bucket(pos->next, tbl, hash) : NULL; \
(!rht_is_a_nulls(pos)) && rht_entry(tpos, pos, member); \
- pos = next, \
- next = !rht_is_a_nulls(pos) ? \
+ pos = _next, \
+ _next = !rht_is_a_nulls(pos) ? \
rht_dereference_bucket(pos->next, tbl, hash) : NULL)
/**
base-commit: 65e4fd942f72a9dba0e4e257290c4fa1aa756854
--
2.43.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-21 7:25 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-21 7:24 [PATCH] rhashtable: Fix safe iterator cursor substitution Avi Weiss
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox