summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2026-10-11 11:44:59 -0700
committerLinus Torvalds <torvalds@linux-foundation.org>2026-10-13 09:44:51 -0700
commitbbab563c51315a1c6dbf6e801e4237b6d2b8b81e (patch)
tree119610d58ca8865f2ba3cb18903a81ba3ad9b3be
parent2dafc9bc491da8146bf293a93ae21fd68755e370 (diff)
downloadlinux-next-assoc-array-fixes-v2.tar.gz
linux-next-assoc-array-fixes-v2.zip
assoc_array: use assoc_array_parent_link() when splitting a shortcutassoc-array-fixes-v2
assoc_array_insert_mid_shortcut() works out by hand which pointer leads to the shortcut it splits: the same cases as assoc_array_parent_link(), with a BUG() for a shortcut behind anything but a node. Use the function, and keep the check as a BUG_ON(). No functional change. Assisted-by: LLM Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Tested-by: David Howells <dhowells@redhat.com> Reviewed-by: David Howells <dhowells@redhat.com>
-rw-r--r--lib/assoc_array.c15
1 files changed, 6 insertions, 9 deletions
diff --git a/lib/assoc_array.c b/lib/assoc_array.c
index d3bc426f17af..f19888ec3e09 100644
--- a/lib/assoc_array.c
+++ b/lib/assoc_array.c
@@ -870,7 +870,7 @@ static bool assoc_array_insert_mid_shortcut(struct assoc_array_edit *edit,
struct assoc_array_walk_result *result)
{
struct assoc_array_shortcut *shortcut, *new_s0, *new_s1;
- struct assoc_array_node *node, *new_n0, *side;
+ struct assoc_array_node *new_n0, *side;
unsigned long sc_segments, dissimilarity, blank;
size_t keylen;
int level, sc_level, diff;
@@ -896,14 +896,11 @@ static bool assoc_array_insert_mid_shortcut(struct assoc_array_edit *edit,
diff += sc_level & ~ASSOC_ARRAY_KEY_CHUNK_MASK;
pr_devel("diff=%d\n", diff);
- if (!shortcut->back_pointer) {
- edit->set[0].ptr = &edit->array->root;
- } else if (assoc_array_ptr_is_node(shortcut->back_pointer)) {
- node = assoc_array_ptr_to_node(shortcut->back_pointer);
- edit->set[0].ptr = &node->slots[shortcut->parent_slot];
- } else {
- BUG();
- }
+ BUG_ON(shortcut->back_pointer &&
+ !assoc_array_ptr_is_node(shortcut->back_pointer));
+ edit->set[0].ptr = assoc_array_parent_link(edit->array,
+ shortcut->back_pointer,
+ shortcut->parent_slot);
edit->excised_meta[0] = assoc_array_shortcut_to_ptr(shortcut);