From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 50FD6487BE for ; Wed, 18 Mar 2026 18:36:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773859013; cv=none; b=teLLOX6h7PqNsnKe1PHnc70Gdh0x59XoabpU3UkbMAOJP/fo6Cj32IMkwEqborBuBcT+ZSS/eQsIJQ2XLcSbgQyGFCl+T7NwXLvLpjPG9tGlke3MWQRqqbP1i+nIIy5l3dCQ8/U1JHvr07DrlgjqGlvV3TSJjH4JfsMxgJBl3cE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773859013; c=relaxed/simple; bh=yrxPEdYHQOUjoUbcJEQBhGhGRgUHbi9kecZx1wtqanw=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=NETq4d05Qc9RchPDZ2rizAF/1L4XU8vpCc+XDenpzwc/jdg2YGBWEYa4J64gGk2ZlNSXzpOMduGzCvR2QSkHC8wrlcr2lpIBoY2mRZq2ZKWaW4IKwUZXow5luENRoEn8fNpYPt8VBHa3E7dU1KhgTsyF3cTM8fgxjsmEd6781Vg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=xJLxMRCw; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="xJLxMRCw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CE362C19421; Wed, 18 Mar 2026 18:36:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1773859012; bh=yrxPEdYHQOUjoUbcJEQBhGhGRgUHbi9kecZx1wtqanw=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=xJLxMRCwTvx8jaGxSLFyQNKuxiYfeWkpmF6Enjmll9qVN7dtJTIYn1qJkwVD+Mx3v 4LqDhfF+3g+s73CaBbsHhRjJsb//hpF5j5RdLX09haKHwiHFLAvo5xfwwNA7SHhn/E bmrelf8Mdff53HSQtpLHOJPJKzqIlZKtFXKkl8Qw= Date: Wed, 18 Mar 2026 11:36:52 -0700 From: Andrew Morton To: Josh Law Cc: linux-kernel@vger.kernel.org, hlcj1234567@gmail.com Subject: Re: [PATCH] lib/assoc_array: fix stale nr_leaves_on_tree after gc Message-Id: <20260318113652.b9647a9000aaa42a014ace5d@linux-foundation.org> In-Reply-To: <540EA561-7291-4AAF-8FAD-857793B811D9@objecting.org> References: <20260318164959.85841-1-objecting@objecting.org> <20260318102319.0db807e1dc3e29fd1cde68b1@linux-foundation.org> <540EA561-7291-4AAF-8FAD-857793B811D9@objecting.org> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Wed, 18 Mar 2026 17:29:10 +0000 Josh Law 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?