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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5E402C433F5 for ; Sun, 6 Mar 2022 14:34:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233628AbiCFOex (ORCPT ); Sun, 6 Mar 2022 09:34:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232853AbiCFOex (ORCPT ); Sun, 6 Mar 2022 09:34:53 -0500 Received: from bedivere.hansenpartnership.com (bedivere.hansenpartnership.com [IPv6:2607:fcd0:100:8a00::2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85487546AC; Sun, 6 Mar 2022 06:34:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=hansenpartnership.com; s=20151216; t=1646577238; bh=gj0xg4o/jelATStNvl7Ejbgin7X2OTavQUPcfcC0oOg=; h=Message-ID:Subject:From:To:Date:In-Reply-To:References:From; b=rWOQ0+Od8Jzq6RvBnjveKNMh+2TMiuJNWeZIXQ/i60V95Hcn3LcbppE+z2qn/kYT4 bbCkNG9niKu4vUi2QSZwZuKf+HePVYZ9XBidq8241PGwJBnHigQon3oR8waHNO2ikD flc4g5yehg4vACix+Fl6uZb7S+AJmRkR+E1DvlaY= Received: from localhost (localhost [127.0.0.1]) by bedivere.hansenpartnership.com (Postfix) with ESMTP id CE7D7128111C; Sun, 6 Mar 2022 09:33:58 -0500 (EST) Received: from bedivere.hansenpartnership.com ([127.0.0.1]) by localhost (bedivere.hansenpartnership.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Ic5liuxIESJe; Sun, 6 Mar 2022 09:33:58 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=hansenpartnership.com; s=20151216; t=1646577238; bh=gj0xg4o/jelATStNvl7Ejbgin7X2OTavQUPcfcC0oOg=; h=Message-ID:Subject:From:To:Date:In-Reply-To:References:From; b=rWOQ0+Od8Jzq6RvBnjveKNMh+2TMiuJNWeZIXQ/i60V95Hcn3LcbppE+z2qn/kYT4 bbCkNG9niKu4vUi2QSZwZuKf+HePVYZ9XBidq8241PGwJBnHigQon3oR8waHNO2ikD flc4g5yehg4vACix+Fl6uZb7S+AJmRkR+E1DvlaY= Received: from jarvis.int.hansenpartnership.com (unknown [IPv6:2601:5c4:4300:c551::527]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bedivere.hansenpartnership.com (Postfix) with ESMTPSA id B04BD12810DA; Sun, 6 Mar 2022 09:33:57 -0500 (EST) Message-ID: Subject: Re: [PATCH 2/6] list: add new MACROs to make iterator invisiable outside the loop From: James Bottomley To: Xiaomeng Tong Cc: arnd@arndb.de, gregkh@linuxfoundation.org, jakobkoschel@gmail.com, jannh@google.com, keescook@chromium.org, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, torvalds@linux-foundation.org Date: Sun, 06 Mar 2022 09:33:56 -0500 In-Reply-To: <20220303033122.10028-1-xiam0nd.tong@gmail.com> References: <20220303033122.10028-1-xiam0nd.tong@gmail.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.34.4 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org On Thu, 2022-03-03 at 11:31 +0800, Xiaomeng Tong wrote: > On Wed, 02 Mar 2022 08:02:23 -0500, James Bottomley > wrote: > > pos shouldn't be an input to the macro since it's being declared > > inside > > it. All that will do will set up confusion about the shadowing of > > pos. > > The macro should still work as > > > > #define list_for_each_entry_inside(type, head, member) \ > > ... > > > > For safety, you could > > > > #define POS __UNIQUE_ID(pos) > > > > and use POS as the loop variable .. you'll have to go through an > > intermediate macro to get it to be stable. There are examples in > > linux/rcupdate.h > > The outer "pos" variable is no longer needed and thus the declare > statement before the loop is removed, see the demostration in PATCH > 3~6. Now, there is only one inner "pos" variable left. Thus, there > should be no such *shadow* problem. So why is pos in the signature of your #define then? Because that means it expands to whatever goes in the first field of list_for_each_entry_inside(). If someone needs to specify a unique name to avoid shadowing an existing variable, then hide pos and use UNIQUE_ID instead was the whole thrust of this comment. James