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 phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 88096C00140 for ; Fri, 5 Aug 2022 17:03:49 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C3D7F84841; Fri, 5 Aug 2022 19:03:47 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=konsulko.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=konsulko.com header.i=@konsulko.com header.b="V9EFUh1d"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B5B9684840; Fri, 5 Aug 2022 19:03:45 +0200 (CEST) Received: from mail-qk1-x72b.google.com (mail-qk1-x72b.google.com [IPv6:2607:f8b0:4864:20::72b]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 1D9C384839 for ; Fri, 5 Aug 2022 19:03:43 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=konsulko.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=trini@konsulko.com Received: by mail-qk1-x72b.google.com with SMTP id p4so1098054qkm.1 for ; Fri, 05 Aug 2022 10:03:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=konsulko.com; s=google; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc; bh=JqSxje5W7605bN89eMOeuPMUDraCKIE5DqTco/T3hQU=; b=V9EFUh1dn3RiLvk7OfB0cEBGprZMFyN3E1FByjCNqKeX9oxE8OxA7YnlYB0f3DHyeZ Xow7jD5ayv1pmUuabKH6FI0ihNfJYN0mTMsey+oxE82is8X8lljHa0hLqB1FMbJLUbxp LHPMEyvvINKch7Q3o7QRHj35k2Nsl0ot4OKV0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc; bh=JqSxje5W7605bN89eMOeuPMUDraCKIE5DqTco/T3hQU=; b=pOu+FzSHdUrGDWsqW3wwJZ/hSIu87V6r2K9dx7/I7I/NNfoGllXvIJZXfxm7WlHh+j YfsUa5P6UkA5GfM71Kzu7gfJ/xVKmfxEOkzpv4ab95HbjzzDCuKSH1UjEtF/P44NiMXT 8E9bTE16quu8OWCrh7SPHgDI813OZ6RNzvcaom2FXyEv73ILjFzshRF0Dfk+dOQfS6Tc LgEFU+GLuZCQ2MqNBVosKmO914QV7e0lYykjOMgThfUB4QCO0bKVleAEEWrw7DOnuija dSFt1cZCwJ4YhsYigSfcD17Qru1P/eq6nNtG7teBz03JQAZAVIyV4apT0LSQRvaPBbEZ 38xQ== X-Gm-Message-State: ACgBeo3X/r93F3rg5fGZxdRLCxL34Tt5+0l6YMIdomMoMXahVQDxHkfe EBK/JljVAhuSAwdkAwD68Bdj+w== X-Google-Smtp-Source: AA6agR7HRUBeFwAG3vHnxB8HBFFM/o3Yi+IVbtfzLjmCZG/RdB9w2ogsSRD6betbgPzMlYE9PT36Jg== X-Received: by 2002:ae9:e842:0:b0:6b8:df7f:4dee with SMTP id a63-20020ae9e842000000b006b8df7f4deemr5960139qkg.488.1659719021173; Fri, 05 Aug 2022 10:03:41 -0700 (PDT) Received: from bill-the-cat (cpe-65-184-195-139.ec.res.rr.com. [65.184.195.139]) by smtp.gmail.com with ESMTPSA id b16-20020a05622a021000b0031eddc83560sm2914086qtx.90.2022.08.05.10.03.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Aug 2022 10:03:40 -0700 (PDT) Date: Fri, 5 Aug 2022 13:03:38 -0400 From: Tom Rini To: Simon Glass Cc: Rasmus Villemoes , U-Boot Mailing List , Michal Simek , Patrice Chotard , Patrick Delaunay Subject: Re: [PATCH] checkpatch.pl: Reword IS_ENABLED() warning Message-ID: <20220805170338.GD1146598@bill-the-cat> References: <20220802123313.2993824-1-trini@konsulko.com> <856c649a-7429-4f37-8e86-d6a359e6f0f2@prevas.dk> <20220805151259.GY1146598@bill-the-cat> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="GqYweJ59sglFWLOM" Content-Disposition: inline In-Reply-To: X-Clacks-Overhead: GNU Terry Pratchett X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean --GqYweJ59sglFWLOM Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Aug 05, 2022 at 10:48:17AM -0600, Simon Glass wrote: > Hi, >=20 > On Fri, 5 Aug 2022 at 09:13, Tom Rini wrote: > > > > On Wed, Aug 03, 2022 at 09:43:00AM +0200, Rasmus Villemoes wrote: > > > On 02/08/2022 14.33, Tom Rini wrote: > > > > While there are good reasons to use 'if (IS_ENABLED(CONFIG_...))' f= or > > > > runtime tests, there's equally good reasons to use '#ifdef CONFIG_.= =2E.' > > > > for build time tests. Reword this message to hopefully avoid confu= sion. > > > > > > > > Cc: Simon Glass > > > > Signed-off-by: Tom Rini > > > > --- > > > > scripts/checkpatch.pl | 2 +- > > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > > > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl > > > > index fe13e265a3fe..2d737bdb991b 100755 > > > > --- a/scripts/checkpatch.pl > > > > +++ b/scripts/checkpatch.pl > > > > @@ -2621,7 +2621,7 @@ sub u_boot_line { > > > > # use if instead of #if > > > > if ($realfile =3D~ /\.c$/ && $line =3D~ /^\+#if.*CONFIG.*/) { > > > > WARN("PREFER_IF", > > > > - "Use 'if (IS_ENABLED(CONFIG...))' instead of '#if = or #ifdef' where possible\n" . $herecurr); > > > > + "Possible runtime #ifdef, see if using 'if (IS_ENA= BLED(CONFIG...))' instead is possible\n" . $herecurr); > > > > } > > > > > > Eh, there obviously is no such thing as a "runtime #ifdef", so I don't > > > think this is an improvement. > > > > I'm not entirely happy with it either. > > > > > Nor is the form "if (IS_ENABLED(...))" really a run-time thing anyway, > > > we certainly rely on the compiler to fold away any occurrence of > > > build-time constants inside if() and while() and similar. So also the > > > commit message is somewhat misleading. > > > > True, but if (IS_ENABLED(...)) is only useful in runtime. > > > > > The reason the if() form is preferred is to have the compiler check t= he > > > contained code for syntactic correctness, and there are two main ways > > > (that I can think of off hand) that the #if form can be necessary: > > > > > > (1) The code references fields of structs that only exist when that > > > CONFIG is enabled, probably to save some memory when they are not nee= ded. >=20 > We can do: >=20 > struct fred { > CONFIG_IS_ENABLED(MARY, (int member;)) > }; >=20 > I've been thinking of moving to this, actually, perhaps with a new > macro called CONFIG_MEMBER(MARY, int member) I think that's less readable. > > It's also for when rev A has one set of registers and rev B has another, > > but we can still use the same overall struct to talk with the device. > > There's a lot of this. >=20 > That's not very nice though. It should really happen at runtime with a > compatible string. We can see what makes sense when they come up, but I'm not sure this fits. > > > (2) The code references functions which are only declared when that > > > CONFIG is enabled. > > > > > > Now, there's usually not much to do about (1), except one could ask if > > > the memory saving is worth it (obviously if its some 4K debug array, = not > > > so obviously if it's just two extra ints that go unused when > > > !CONFIG_FOO). For (2), I believe all guards of declarations in headers > > > by #ifdefs are bugs that need to be fixed, so that the if() form can = be > > > used to elide emitting calls to such functions. The same goes for > > > guarding whole struct definitions or enums and similar. >=20 > Yes this has been my policy, at least, for quite a while. Sometimes we > need to split up a header to avoid circular dependencies. >=20 > However we often use #ifdef in the header to provide two different > versions of functions, e.g. one that is just a nop, like clk_request() >=20 > In fact I think #ifdefs should only be in header files, in the ideal case. Right, these cases are fine, but some of the old cases we still have are just guards around prototypes, which do need to be removed. > > We need guards around the functions themselves otherwise we would get > > defined but unused on static functions. There's other cases where it > > could be argued that the file itself needs to be split so that there's > > less code that might be unrelated in it. >=20 > For the first bit, __maybe_unused can help. When it's better for readability, yes. Sometimes it's not and it's better to just if out the functions. > > I'll keep this all in mind and come up with better wording for a v2, > > thanks. >=20 > Actually as well as this patch it seems we need something that > explains the #ifdef policy (and tips) in more detail. Yes, getting something put in to doc/develop/ would be good. --=20 Tom --GqYweJ59sglFWLOM Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQGzBAABCgAdFiEEGjx/cOCPqxcHgJu/FHw5/5Y0tywFAmLtTWcACgkQFHw5/5Y0 tyxYNAv+IfixTPJCU9wdoVQ/6SNFMNKTOPVTPd/dR795jPf9+XZHmqtsitEY5D4r BKdAbNqJSwOTcESiatkakr6Glu/8/+KDf4azGofp1EJTbcjdrO7n1Rm5YJbQAy3x FiDX60CEsmrKin2akmUFAcXTEfwQBT7RN3r7J/GxjMnlHsgkmGL6m4xV9dP/i6ED q4xiSx4rxtn09s13IIVnUCaXO/GRnIc7eXbxbYfC3ms280CmRt/lisJgK81VDbfP YanZKfhy4woraBS2zewKk/XK6ewyTzXvTwV9tEdABMb4wZoRve9D1sTC7MhqOk0O OTELvyjhBTDgxeymXybyFW+PEjTqJqwyPeOj37+n4JvHE+3DhCfvh9xlv+u/uzQ8 5DAla6FuhdAJEUA3YGXuS2eGRdYQh/NHUn5JiBU5m142HmK/CXobYYiPwt+FyrrO l9o7ulEaP/jHTu/2wwr7n33QkhaVKsz2Az8pTrbUg2NKt/M0m2WoRjBiNhVwFxB3 IINMYnfj =xa9o -----END PGP SIGNATURE----- --GqYweJ59sglFWLOM--