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

From: Josh Law

Date: Thu Mar 19 2026 - 11:20:24 EST




On 19 March 2026 14:14:58 GMT, David Howells <dhowells@xxxxxxxxxx> wrote:
>Josh Law <objecting@xxxxxxxxxxxxx> wrote:
>
>> In assoc_array_gc(), assoc_array_apply_edit() publishes the new tree
>> root before nr_leaves_on_tree is updated, creating a window where the
>> tree is visible with a stale leaf count. Move the nr_leaves_on_tree
>> assignment before assoc_array_apply_edit() so the count is consistent
>> when the new root becomes visible.
>
>This just moves the window. The count is then inconsistent before the new
>root becomes visible.
>
>Note that there's no guarantee that nr_leaves_on_tree is stable if you're not
>locking against modification. Further, if you look in:
>
> Documentation/core-api/assoc_array.rst
>
>there's no mention of nr_leaves_on_tree being part of the API. Unfortunately,
>C doesn't allow me to put in a private: marker as C++ does.
>
>Note that neither assoc_array_iterate() nor assoc_array_find() make reference
>to the value.
>
>Are you actually seeing a problem stemming from this?
>
>David
>



Well, the bug actually is there, and if i made a mistake, this patch should atleast be hardening level, (As i say, better safe than sorry)


V/R


Josh Law