Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp59474pxp; Fri, 4 Mar 2022 21:25:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJyQJBl9zRcm7EtdUk1NEcUaOWKnlJnwuQiSgszTkE0HRaoOf3T6MEwPnSE7e4+9pwVYHSyY X-Received: by 2002:a63:1858:0:b0:374:b3c2:2dee with SMTP id 24-20020a631858000000b00374b3c22deemr1524399pgy.97.1646457914364; Fri, 04 Mar 2022 21:25:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646457914; cv=none; d=google.com; s=arc-20160816; b=XLrYuX/Lhxukkml0ufSgYMVMiRzwjvBLswmbXNVPP+fPW+VXHV9vd0S0wxwCDBa0tl mvVWRXPb9tUwuxvnbYfn3ciHQLOssXZhjwqmvn/h+ofkel3ooUDpHyeAl+dkUZXz0O0X yXsLBQNgjk/J4CUswV5rGjEVatRzxOjVtgzsGWXXXOyE7HInYyQGsvBE2B+O9I+L7rE0 oK6AgI7z8jLWNa/hjaFiZ1QG7x79b2he/N2C47nCxjTlRSsVkO3gJQSWpnMmdkkoRzYT iYptzR4gv1xA7Gd0CrYTEcsg+yPD35x3AjlC7hkIU1qxzrsqIJMyex7Nicysmsf/XVC9 Nxkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=bH9FUNfK94bzV6oA/NLveq8XGHYmwa6KqSeeS6X92ZY=; b=gGUe3NEzRq68ufpck/zeGYHl44wYZMa/Us43/Csxy0mNpm8FYVOCRIFajprtB0ttNJ xKUE5/BKgHko1R6pT73t5N57mzN62ie90Xnac43+F6OBsRd18DP2PS9FTzuMNkIKrFAm oer9noldMU2FP2Lq/jEw5Kuj4d41JJQsRUhDNiE8X5VDDfCjVsoM0KMeyUYwJ+v4P5mp McQ28Y79mQqixGjd1mr7mnR14XPZPEjQYVDeO+X5oGrINnmHEcEGEEyTW+OIBUjbo3d+ YFwcmhLf8C+Atmzpf4H3CBKmumzt8d6KIwyYc5Rsw8wkxdNQZUWX7jICFqzgBxRKBa16 ijXA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cv13-20020a17090afd0d00b001bd14e01f79si1328799pjb.103.2022.03.04.21.24.53; Fri, 04 Mar 2022 21:25:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230519AbiCED6x convert rfc822-to-8bit (ORCPT + 99 others); Fri, 4 Mar 2022 22:58:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230201AbiCED6w (ORCPT ); Fri, 4 Mar 2022 22:58:52 -0500 Received: from mail-yw1-f171.google.com (mail-yw1-f171.google.com [209.85.128.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B915F37A06 for ; Fri, 4 Mar 2022 19:58:02 -0800 (PST) Received: by mail-yw1-f171.google.com with SMTP id 00721157ae682-2dbfe58670cso111941067b3.3 for ; Fri, 04 Mar 2022 19:58:02 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=k/KxZWnsipa0LOVNrv/AsWXD0KCOxYbfZhWdDw0/Nm4=; b=BFqdwGgy2XlTQ/eStV24a7ZzYuvCfbpd5YieUJE4Fbr7Z04hla5zUnMcPb4TBJb3WI dbq4x+uFhODA3/TwVvdwr9YF6KpkLiKJ1Frk3y0P7E+WxHKO08tr1U9+annPdibX3PNN 4dz50UhESRbklggWq6slY5/rzJUHwE9yLndLpaiJaebR0SQs5l4mzDoDZw8zv/fTjyyt tzj/E2NaA2fHQhBd1my7wn/HTvINbG8qYz1BpV8xFE3OHIYhDIQ8EwBm4HtWfWFmqbCu XOefRywwQIn5pcif333Dl8f0qoGx5bV3R8A/ipz9+QUN9yTHxHEFFeFDkZxRV/CIIUkO YgGw== X-Gm-Message-State: AOAM530pQ9w3ZUVgRww+1eTY6GmeED3LhduFuzvnLOzpbxdU/uW0cT5b 0inVsgDjDTKmwqw2OWlEuXsqaXBYEI9/0jk72gZwgAxiyZc= X-Received: by 2002:a81:6bc6:0:b0:2db:fe24:d5ee with SMTP id g189-20020a816bc6000000b002dbfe24d5eemr1424302ywc.392.1646452681895; Fri, 04 Mar 2022 19:58:01 -0800 (PST) MIME-Version: 1.0 References: <20220303110755.24147-1-mailhol.vincent@wanadoo.fr> In-Reply-To: From: Vincent MAILHOL Date: Sat, 5 Mar 2022 12:57:50 +0900 Message-ID: Subject: Re: [PATCH] x86/bug: __WARN_FLAGS: prevent shadowing by renaming local variable f to __flags To: Nick Desaulniers Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, linux-kernel@vger.kernel.org, "H . Peter Anvin" , Alexey Dobriyan , Josh Poimboeuf Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue. 5 Mar 2022 à 04:26, Nick Desaulniers wrote: > On Thu, Mar 3, 2022 at 3:08 AM Vincent Mailhol > wrote: > > The macro __WARN_FLAGS() uses a local variable named "f". This being a > > common name, there is a risk of shadowing other variables. > > > > For example: > > > > | In file included from ./include/linux/bug.h:5, > > | from ./include/linux/cpumask.h:14, > > | from ./arch/x86/include/asm/cpumask.h:5, > > | from ./arch/x86/include/asm/msr.h:11, > > | from ./arch/x86/include/asm/processor.h:22, > > | from ./arch/x86/include/asm/timex.h:5, > > | from ./include/linux/timex.h:65, > > | from ./include/linux/time32.h:13, > > | from ./include/linux/time.h:60, > > | from ./include/linux/stat.h:19, > > | from ./include/linux/module.h:13, > > | from virt/lib/irqbypass.mod.c:1: > > | ./include/linux/rcupdate.h: In function 'rcu_head_after_call_rcu': > > | ./arch/x86/include/asm/bug.h:80:21: warning: declaration of 'f' shadows a parameter [-Wshadow] > > | 80 | __auto_type f = BUGFLAG_WARNING|(flags); \ > > | | ^ > > | ./include/asm-generic/bug.h:106:17: note: in expansion of macro '__WARN_FLAGS' > > | 106 | __WARN_FLAGS(BUGFLAG_ONCE | \ > > | | ^~~~~~~~~~~~ > > | ./include/linux/rcupdate.h:1007:9: note: in expansion of macro 'WARN_ON_ONCE' > > | 1007 | WARN_ON_ONCE(func != (rcu_callback_t)~0L); > > | | ^~~~~~~~~~~~ > > | In file included from ./include/linux/rbtree.h:24, > > | from ./include/linux/mm_types.h:11, > > | from ./include/linux/buildid.h:5, > > | from ./include/linux/module.h:14, > > | from virt/lib/irqbypass.mod.c:1: > > | ./include/linux/rcupdate.h:1001:62: note: shadowed declaration is here > > | 1001 | rcu_head_after_call_rcu(struct rcu_head *rhp, rcu_callback_t f) > > | | ~~~~~~~~~~~~~~~^ > > > > This patch renames the variable from f to __flags (with two underscore > > prefixes as suggested in the Linux kernel coding style [1]) in order > > to prevent collisions. > > > > [1] Linux kernel coding style, section 12) Macros, Enums and RTL, > > paragraph 5) namespace collisions when defining local variables in > > macros resembling functions > > https://www.kernel.org/doc/html/v4.10/process/coding-style.html#macros-enums-and-rtl Indeed! Will update this in v2 (and will also fix the Fixes: tag as pointed by Josh). > Ah, thanks for the patch. I missed that coding style recommendation. > Might want to link to a newer (or evergreen) version of the docs > though: > https://www.kernel.org/doc/html/latest/process/coding-style.html#macros-enums-and-rtl > Not sure what happens when we start shadowing variables named __flags, > but maybe we cross that bridge if/when we get there. Ack. > Thanks for the fix! > Reviewed-by: Nick Desaulniers