From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5F5C3C83F17 for ; Thu, 10 Jul 2025 18:31:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0412A6B009D; Thu, 10 Jul 2025 14:31:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F2CC96B009E; Thu, 10 Jul 2025 14:31:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E1BE66B009F; Thu, 10 Jul 2025 14:31:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id CC7A96B009D for ; Thu, 10 Jul 2025 14:31:02 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 76CDB1609AC for ; Thu, 10 Jul 2025 18:31:02 +0000 (UTC) X-FDA: 83649196764.27.5BC22B8 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf23.hostedemail.com (Postfix) with ESMTP id C4007140005 for ; Thu, 10 Jul 2025 18:31:00 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=pMXbP2GH; spf=pass (imf23.hostedemail.com: domain of alx@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=alx@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1752172260; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=lyRdOARNiPxKcJ9Sgw+OlpMDBnmziLhWvxyx39eyrL0=; b=MIUY6IoDVNnJofB5sa+uAaoDL987Sxjht2e68pN9X2NN4/B+Mv4TT3HDWcnMFYqJaqpw4v mV7tQGU0Uc7KJDCOCBIJqDTxB/K3mu13nvYIwbOV/IBApzxllX9Xfit+rVNO58a+EwhBP/ ntZaR6U5lg7LO4DxSgUIQEt3TFHYsGI= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=pMXbP2GH; spf=pass (imf23.hostedemail.com: domain of alx@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=alx@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1752172260; a=rsa-sha256; cv=none; b=FFnfOtBNDAzTUZ/OPGuf16XdHAppMMpRAas6b7bKWhM2FD5g3Etz98teCEKWXvs7AsS9ER ctRVMcdz12C57FFZCE8gviGG8AK/u89wDhRI/QocdJIvKznoUUDPq8KaSBx5XJ0HjPdZLQ rYLeHbh6gGz0i8CiLfOjvQGWCOfvZms= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id B337F5C6CCA; Thu, 10 Jul 2025 18:30:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6C7FEC4CEE3; Thu, 10 Jul 2025 18:30:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1752172259; bh=YzVPXkrWcC89iLuTuFsldR1NCSylHyBNV4ySFkjnvaE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=pMXbP2GHCcgHhusslX+Beh7WW1fk8dvET/CVI07Rw63ApetuO/mFNyW+TmKYZOBL6 /a8S2Wkh4a50yoc26Lt1L7qpGGrlVIuj0ywErcqj2hTOQb7WMjP6gv2hg9FZ/FRVV+ 0Vt2MHj+IRfV61UhugK3i41bhmURgs9T7noW87KEIqL4mACKIsSMtXGvRyCiPQnmuT Z4mDEv7uFarwzKT5WIWQc71igRgrv1ubQXGNH2nMIXg1d3N5d9mmRlwNxC1zMffckP ehqVGE7Z+Y1e0p2kg3a7Q+Ae7pRBJVF6R9BnEb3IdJ8UOgd/xb5ZeO0PWRLQ2d9cUh tiiZlIv++ExDA== Date: Thu, 10 Jul 2025 20:30:52 +0200 From: Alejandro Colomar To: Linus Torvalds Cc: linux-mm@kvack.org, linux-hardening@vger.kernel.org, Kees Cook , Christopher Bazley , shadow <~hallyn/shadow@lists.sr.ht>, linux-kernel@vger.kernel.org, Andrew Morton , kasan-dev@googlegroups.com, Dmitry Vyukov , Alexander Potapenko , Marco Elver , Christoph Lameter , David Rientjes , Vlastimil Babka , Roman Gushchin , Harry Yoo , Andrew Clayton , Rasmus Villemoes , Michal Hocko , Al Viro Subject: Re: [RFC v4 6/7] sprintf: Add [V]SPRINTF_END() Message-ID: References: <0314948eb22524d8938fab645052840eb0c20cfa.1752113247.git.alx@kernel.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="fodiyed7jhvlrxi3" Content-Disposition: inline In-Reply-To: X-Rspamd-Queue-Id: C4007140005 X-Stat-Signature: yy4bibe1545aj5aozai1gedrwpugfx34 X-Rspam-User: X-Rspamd-Server: rspam07 X-HE-Tag: 1752172260-26992 X-HE-Meta: U2FsdGVkX1+woYd4sUyZjzFosimVhiRR+D1veA5XI9St3Qn5esUWV9qSw569Q+PjSIje7EkDniWyyZ38fvUVuFad8t0tNz/wtbEg46ytJ8LAsrK8nvsjUrmh7DTkaQBqsv2WHm9xq2+jVDZ+6ZIlx81TX2qeq867pQnLgZsusqJHEjuWiJpwKEK+QJP6XbFaCAGLZhorOlDPptZP/ZMGgqERBRdhkchr9axxraH6exTKRv1t7qyfkjADhqXK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Ym8+HReXA46ao96q5O63FyNoX2yvRSjDWEpMuqt4vORgIMQ28Z1V8q0fAnqHB+BZTZpZRZ+k8m3iglRSZnq1F1fQXLZt5vJjR8i+lEbpmSaJnBttUevdvCftXF6NLFKisHF/Hvb+PZERN8+BDjwfsFC273oWfzGuHYv2nstnxbAjuaGLZcTu9PL5t3/GjFIX3K/RpxFDuau88t2z8TyF4= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: --fodiyed7jhvlrxi3 Content-Type: text/plain; protected-headers=v1; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable From: Alejandro Colomar To: Linus Torvalds Cc: linux-mm@kvack.org, linux-hardening@vger.kernel.org, Kees Cook , Christopher Bazley , shadow <~hallyn/shadow@lists.sr.ht>, linux-kernel@vger.kernel.org, Andrew Morton , kasan-dev@googlegroups.com, Dmitry Vyukov , Alexander Potapenko , Marco Elver , Christoph Lameter , David Rientjes , Vlastimil Babka , Roman Gushchin , Harry Yoo , Andrew Clayton , Rasmus Villemoes , Michal Hocko , Al Viro Subject: Re: [RFC v4 6/7] sprintf: Add [V]SPRINTF_END() References: <0314948eb22524d8938fab645052840eb0c20cfa.1752113247.git.alx@kernel.org> MIME-Version: 1.0 In-Reply-To: Hi Linus, On Thu, Jul 10, 2025 at 08:52:13AM -0700, Linus Torvalds wrote: > On Wed, 9 Jul 2025 at 19:49, Alejandro Colomar wrote: > > > > +#define SPRINTF_END(a, fmt, ...) sprintf_end(a, ENDOF(a), fmt, ##__VA= _ARGS__) > > +#define VSPRINTF_END(a, fmt, ap) vsprintf_end(a, ENDOF(a), fmt, ap) >=20 > So I like vsprintf_end() more as a name ("like more" not being "I love > it", but at least it makes me think it's a bit more self-explanatory). :-) > But I don't love screaming macros. They historically scream because > they are unsafe, but they shouldn't be unsafe in the first place. >=20 > And I don't think those [V]SPRINTF_END() and ENDOF() macros are unsafe > - they use our ARRAY_SIZE() macro which does not evaluate the > argument, only the type, and is safe to use. Yup, it's safe to use. > So honestly, this interface looks easy to use, but the screaming must sto= p. >=20 > And none of this has *anything* to do with "end" in this form anyway. That same thing happened through my head while doing it, but I didn't think of a better name. In shadow, we have many interfaces for which we have an uppercase macro version of many functions that gets array sizes and other extra safety measures where we can. (So there, the uppercase versions are indeed extra safety, instead of the historical "there be dragons". I use the uppercase to mean "this does some magic to be safer".) > IOW, why isn't this just >=20 > #define sprintf_array(a,...) snprintf(a, ARRAY_SIZE(a), __VA_ARGS__) Agree. This is a better name for the kernel. > which is simpler and more direct, doesn't use the "end" version that > is pointless (it's _literally_ about the size of the array, so > 'snprintf' is the right thing to use), I disagree with snprintf(3), but not because of the input, but rather because of the output. I think an API similar to strscpy() would be better, so it can return an error code for truncation. In fact, up to v2, I had a stprintf() (T for truncation) that did exactly that. However, I found out I could do the same with sprintf_end(), which would mean one less function to grok, which is why I dropped that part. I'll use your suggested name, as I like it. Expect v5 in a few minutes. > doesn't scream, and has a > rather self-explanatory name. >=20 > Naming matters. +1 Have a lovely day! Alex >=20 > Linus --=20 --fodiyed7jhvlrxi3 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEES7Jt9u9GbmlWADAi64mZXMKQwqkFAmhwBtYACgkQ64mZXMKQ wqmOQA//bIEhEXLVgwS7mz/jBLQAGT4v53a5yhA1vSbBvckl7+P/z4tYOhS7drGu KipZBsVxwdBQhN097m1zOT1T1T9q4vbqFOVX1uNVL7Q2R/0WyYC5APIKDHO1ijNF uXc0HmMSM7Lm0CrY0nvPsI6ZGVagYdXm7QuQ9+GfBc2NAoiJU9fGRPBOjzllradR 3ALXe1Y5c2lgE4sEPPHmAAQNK7LGIX17yx/+YlMDtbZ9/F8fYQrIyW6nkWLgoid9 BmaQ1be4FK7NNbemif5QzHXxaLiwe3OgJrEsgEEAB7cmAvSc+bTloPpFv7UErAsq BRAv7ivc/Saq5S7779xS5e4GDq8MjdCG2qSMvMnUtfAuhNB90zarK5cXAdCPKvAB oD+7JptOjM1LHBvjK+Y7ZUIZ1JzP2/4NFtam9ioZUE+Drb5iLSGdwTYjOHzfF+Pi FLmGbNNQzBMl1b8kjXnOxvmMfYeYM39/eNWUxYXxrhfZGIiRnIdh3ezJreD8t5Rp AvqHuTbMKRbZmExHJ5sQFJ+MYH1/dOwkgpXvmhFnO78EgLJQSbW05CdDnGvlCNpj NvcOhy5N+fVmC64ytcS/ALIWJk6XG/Tadns1r2Dn44oDlm1po+tt5k5nT81+cL9t 8gyc+6tp4He6Q4/zznnOCaQytRCja4eJcji3hvW3q2loFPWpzTw= =kDfd -----END PGP SIGNATURE----- --fodiyed7jhvlrxi3--