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 0A3F029A2 for ; Mon, 22 Dec 2025 23:21:21 +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=1766445682; cv=none; b=PmZ3j4A6L0+lgjsc7hOclokGecvLjBXFJS3dlh3SM79NsmgyL8NUdKK3ZdyM/d7gkdf7tzEcING1azNVCqYyVUrzAFJH4dtMhstgVo5kTXdIWXYltrZjoSYGeAmcy4xOGDLUvmOh2LORQZ3RANvXstyOGTqUiEsmpfDhnF9F65I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766445682; c=relaxed/simple; bh=AfPLPIAPUMIERCMsImUahHDBvM54AwOISAeBvFuxmYM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=I7oRyuOb1GTVz1fhG/4I9nupxl7XQemidITXVSN8JIKdBVQtYm2X4EHZQiA9xOxZsyY2oONn6VeDfxXhFZUPpKgqr8IlicXyMbP4AB3E+uag/lphYNksSqmF9i5DUfcgbPSeFche186Fot/ZNKZc+cvrm5VTO5f3OmYdlAjy71s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aXe7FVYi; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="aXe7FVYi" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7EF51C4CEF1; Mon, 22 Dec 2025 23:21:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1766445681; bh=AfPLPIAPUMIERCMsImUahHDBvM54AwOISAeBvFuxmYM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=aXe7FVYi6NfpMW5sS7HfATIJ9ci/IdbSAeMbUgTyPiLlOwgzfELHJpwNg4uiHnEm0 Wp2Fh9zx8shAA/MJYRg5Vys+6xmjDk9ujklAUD1zNOIGmeGOSOfk7iL4GSAzowhLZu HzNj1LuQjhAN+dKsdVlRfk6y4IgeI/8ZJB484GVBzlZdCD2fT3PNB3WdErxpcwvnDB hBzVWU8YIM4h90x1rwc168ceMXao6MmkeWWyVOwvA62HR7YWOoPC7nYIdthQ+hzmUt Qhhnqkzzd9WNiO9VQptVmyw6PZM/zNyDP4C0QXvjbZ0Hg6IslepgKVV8MnwBIm9ToZ TZoYTuCM+dWiQ== Date: Mon, 22 Dec 2025 15:21:21 -0800 From: Kees Cook To: Alejandro Colomar Cc: Andrew Morton , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Christopher Bazley , Rasmus Villemoes , Marco Elver , Michal Hocko , Linus Torvalds , Al Viro , Alexander Potapenko , Dmitry Vyukov , Jann Horn , "Maciej W. Rozycki" Subject: Re: [PATCH v5 4/4] mm: Use ARRAY_END() instead of open-coding it Message-ID: <202512221517.E1B039879E@keescook> References: <202512101736.DE24BE89@keescook> 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-Disposition: inline In-Reply-To: On Sun, Dec 21, 2025 at 03:07:14PM +0100, Alejandro Colomar wrote: > Hi Kees, Andrew, > > On Wed, Dec 10, 2025 at 05:37:13PM -0800, Kees Cook wrote: > > > > Are there other open-coded instances that could be replaced? This seems like a great task for a coccinelle script. > > > > > > There are many, but I wanted to keep them out of this initial patch set, > > > to make it easy to apply. When this one is applied, I could work on a > > > second round that replaces more of them with coccinelle. This is just > > > for showing that this is beneficial, and to make sure that you ask for > > > more. :) > > > > > > Also, it's easier if there are few maintainers that would block an > > > initial patch set. If restrict the patch set to a few files, I don't > > > have to deal with many of them. Once I get used to this, I'll deal with > > > all of them. > > > > Sounds good! > > Now that the first patch set has been merged, I'm working on a second > round. > > I've written a semantic patch: > > $ cat src/spatch/array_end.sp > @@ > expression a; > @@ > > - a + ARRAY_SIZE(a) > + ARRAY_END(a) > > @@ > expression a; > @@ > > - ARRAY_SIZE(a) + a > + ARRAY_END(a) I think you can add parens which will be silently removed but gain you the commutative behavior: @@ expression a; @@ - (ARRAY_SIZE(a) + a) + ARRAY_END(a) I *think* that'll cover "a + ARRAY_SIZE(a)" too. Anyway, looks good! You could send it directly to Linus at the end of the next rc1, and he may take it. If not, you'll want to split the patch up and send to subsystems after ARRAY_END is in Linus's tree. I use this tool to split a large single patch into per-subsystem patches: https://github.com/kees/kernel-tools/blob/trunk/split-on-maintainer -- Kees Cook