Re: [PATCH] lib/assoc_array: fix stale nr_leaves_on_tree after gc

Josh Law
2026-03-18T18:43:07Z

On 18 March 2026 18:36:52 GMT, Andrew Morton <akpm@linux-foundation.org> wrote:
>On Wed, 18 Mar 2026 17:29:10 +0000 Josh Law <objecting@objecting.org> wrote:
>
>> >
>> >But assoc_array_apply_edit() alters array->nr_leaves_on_tree and now we
>> >immediately overwrite that alteration?
>>
>>
>> Hi Andrew,
>>
>> It probably doesn't overwrite it in this specific case.
>>
>>
>> In assoc_array_gc(), the edit script is zero-initialized, meaning edit->adjust_count_on is NULL. Because of this (and since array->root isn't NULL), assoc_array_apply_edit() safely skips the block that modifies nr_leaves_on_tree.
>
>wordwrapping, please.
>
>> Since apply_edit() doesn't touch the count here, the explicit assignment right after is necessary to record the newly calculated post-GC count.
>
>How about asking the author of this code?

+ CC: dhowells@redhat.com (file author)

Sorry Andrew, my email client isn't the best (Thunderbird mobile), I'm away from my laptop right now for a little bit..

V/R

Josh Law