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 812FBC25B08 for ; Fri, 5 Aug 2022 15:13:10 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 803998484F; Fri, 5 Aug 2022 17:13:08 +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="nc35ApCp"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3568E84828; Fri, 5 Aug 2022 17:13:07 +0200 (CEST) Received: from mail-qv1-xf30.google.com (mail-qv1-xf30.google.com [IPv6:2607:f8b0:4864:20::f30]) (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 3EE9E84541 for ; Fri, 5 Aug 2022 17:13:04 +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-qv1-xf30.google.com with SMTP id mk9so1923393qvb.11 for ; Fri, 05 Aug 2022 08:13:04 -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=zXiXo3FFH4xKIYF8d7fAeEsgdi1TTHGORESmDs5fCEQ=; b=nc35ApCptHzGzYhvOr/0vaOL1t5lxgxtbhbgnYmBYKuRacRcVhe3fTdHgisNwJW+I+ 7eMWeVoVM1NMg9j7NlFymh2LvVQYa/9egFl/SiVtqAPOeHkHmucmzqsjYxOEPrUs6Ajb 0j3A9SA1RAZVFuk4Bda3ghibty2tO83qK3Wdc= 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=zXiXo3FFH4xKIYF8d7fAeEsgdi1TTHGORESmDs5fCEQ=; b=WVTp1oN0LmrbLjucfIZqM63INuZvuSF+zg4C8xlEcOh2ffHOM4P1WScgcyyMBgi0BN 0fTsgXUTwaClViwcKFAke05H9TYN3lrl0jdUFoabE0jkjEz+hSQC7jzN7f/D0WkGUaF4 P86fYYMbzk4XRyZapKJnllaEom68zcesAwEDC0B5T7+XA6tvDF2sC9pLwMwEzlimTChl w5Q5kCrWqCU9sfx3wq0tuXI/3OTZtzqpCx/nQjX/xyIUKuBgXnNkFQ0vpPBXqqNJs8cT INIy3pqOi14bTVGHIh2REyozN2FwpDElRx3zPUWQDnseUgezBtpKBOFtOC8xKGbtOGzM Ot7w== X-Gm-Message-State: ACgBeo2y7DkLsoRsqmszDYSP3lpSlruNi8mxcNeA/WIGLCOTw8Pm01sa J52nd/R0otxxS403YjM4gQ1xB6oNPeNo9fuA X-Google-Smtp-Source: AA6agR4S4eFpuzFCBhZ0zmG2lZ0A6qKgXzAOwsUHx6yeh2Lz+Tp3aVSv21+ni93ysqNBHTyUuKroiQ== X-Received: by 2002:a0c:ab17:0:b0:474:8a27:ed53 with SMTP id h23-20020a0cab17000000b004748a27ed53mr5958312qvb.56.1659712382913; Fri, 05 Aug 2022 08:13:02 -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 x8-20020a05620a258800b006b5e45ff82csm3216573qko.93.2022.08.05.08.13.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Aug 2022 08:13:01 -0700 (PDT) Date: Fri, 5 Aug 2022 11:12:59 -0400 From: Tom Rini To: Rasmus Villemoes Cc: u-boot@lists.denx.de, Michal Simek , Patrice Chotard , Patrick Delaunay , Simon Glass Subject: Re: [PATCH] checkpatch.pl: Reword IS_ENABLED() warning Message-ID: <20220805151259.GY1146598@bill-the-cat> References: <20220802123313.2993824-1-trini@konsulko.com> <856c649a-7429-4f37-8e86-d6a359e6f0f2@prevas.dk> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="+0rBmyX1KM+gvH6P" Content-Disposition: inline In-Reply-To: <856c649a-7429-4f37-8e86-d6a359e6f0f2@prevas.dk> 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 --+0rBmyX1KM+gvH6P Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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_...))' for > > runtime tests, there's equally good reasons to use '#ifdef CONFIG_...' > > for build time tests. Reword this message to hopefully avoid confusion. > >=20 > > Cc: Simon Glass > > Signed-off-by: Tom Rini > > --- > > scripts/checkpatch.pl | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > >=20 > > 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' wh= ere possible\n" . $herecurr); > > + "Possible runtime #ifdef, see if using 'if (IS_ENABLED(CONFIG..= =2E))' instead is possible\n" . $herecurr); > > } >=20 > 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 the > 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: >=20 > (1) The code references fields of structs that only exist when that > CONFIG is enabled, probably to save some memory when they are not needed. 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. > (2) The code references functions which are only declared when that > CONFIG is enabled. >=20 > 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. 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. I'll keep this all in mind and come up with better wording for a v2, thanks. --=20 Tom --+0rBmyX1KM+gvH6P Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQGzBAABCgAdFiEEGjx/cOCPqxcHgJu/FHw5/5Y0tywFAmLtM3sACgkQFHw5/5Y0 tyye/gv/S8G+j3e4AnmbG6KDZ5lDRQ8+xDeZN8Syl4IEgUk2G04GuTmNHPAIttDi RPi2OtIIQczzmvdEBG7O4H23XNpIiRquZGTWYjgj7XOLFfyLjlPD1yjeDYkmdmTT 4GPfJdT7w2uuGw1Fs6cG8N3Snya1gqLQgngMBYKXxbs/tuQOt3PRdncm0p2YMIPl TGMKUe06iGxZBvAN1mRZ694zC0VQHtfLMLM/YbIXa4ZT0ECw5JqKbdisYL+N4S7W egOcz8t741jd3Ral61aUBUjm6z2G9CXQOzlU+7jSuIkdd8KzTnXfTJ5HWfCoaAnT uonpMQHBUIFUDrK9YquA9hvVPsZjiGuXUZNlekfIY8EcqtKKcAaqbrNKLEiCkyN+ kkG26liBYQbscfJcD5lFky3YEjbJX6YYmuIxNV0IArqvFJ4lmvLDE5SiuLqu9BM5 DWyPaLa1PuXRYpn9YrcJE+tgy0uxkQffMwBBCYlPNssdrqRnqYAa07m+Qxfeqe3B MYrnL3Vg =mLoq -----END PGP SIGNATURE----- --+0rBmyX1KM+gvH6P--