Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp985557rwr; Fri, 5 May 2023 07:40:16 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7gA3ISu/Tw6SRektDbgrfUqxGeIiOhLfcn4ZW4Il/EY8OJbmAINu+Bcl+78YH8JHlC0Jo+ X-Received: by 2002:a17:90b:100d:b0:24e:120e:30ff with SMTP id gm13-20020a17090b100d00b0024e120e30ffmr1737396pjb.14.1683297616368; Fri, 05 May 2023 07:40:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683297616; cv=none; d=google.com; s=arc-20160816; b=bb2aFdMRrqnNZKeO6FN3IATAjq/j9akdI4OZ/8vH417cVzW17Dq/BiqkBStq5gty49 GnOwEfWFrUI0feFfR2ByYOimThSNIGn1dWjUZ32cpBUK2PQmetnFE2QVFzUEPKRfkWUr W5YZUd8A1sPSLgqmbpCNIc4fUPDeYe6TqcLDwpCJyuq9CeZ25IDaR9LQnjk833xi6Br4 ytEHOWudYm+B18xPE3fzMyqkIyXLNfBt0MW21ixUOKwQN2DkuQfs6BqI3jArMfPqqn26 vRNSvW4PS4NezOcTAkNuUofrFRRIrp2xsV4CfH/CSubqaJ6B0qRbLuqeVOqprIX8YeIF 31yg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=Q3vnsOehKnnrUSTRhj0Uj1OLmgu1K8NQYfVe6ZaHV8Y=; b=eHcmwckt99SADHl45eMWD0c88VFJq345wjnfcgScruvqtrmvi9+imdgBl1Y2p6/ElX /bGrWAFwdjxq9AfpAQa58s7qQTxfTv50df4ruuun/TfxmHQh2ujMKW2zRb1iLvhxfh+p GXgCx3Oy+jrCZdXOXwmC/HjeFEplBZIfToFtN80r7SK5yPRfUOSTAMOf8g3X2iQdGNiu 7s+O+5pNuF4sIc2YEnQgYEmJEmig+HvrMHv4isjqi7LTaLpMmF/yc0YUPMk+fEkQqllu nBG3zUnzpyoQKrm8PJx/n4AEs7kRz21Fg/71nU9NKPWR+r9FmHWyhPF9ZFZjjcDlZtf8 2pjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=smtpout1 header.b=bLWyxN5j; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a190-20020a6390c7000000b0051b749eb332si2259082pge.248.2023.05.05.07.40.03; Fri, 05 May 2023 07:40:16 -0700 (PDT) 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; dkim=pass header.i=@efficios.com header.s=smtpout1 header.b=bLWyxN5j; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232867AbjEEOYA (ORCPT + 99 others); Fri, 5 May 2023 10:24:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53748 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232764AbjEEOX6 (ORCPT ); Fri, 5 May 2023 10:23:58 -0400 Received: from smtpout.efficios.com (unknown [IPv6:2607:5300:203:b2ee::31e5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46F82AD06 for ; Fri, 5 May 2023 07:23:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=efficios.com; s=smtpout1; t=1683296633; bh=rpKCtGOWe1G9O3FHGVApcIowlqKzHeUHB8vaBoR141s=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=bLWyxN5jSL4RLY3ILzkGg85mRFrQJKUdlFKcN169lL5LufRnbXoTeUMSsPC8puxZI YHCWAjxnMLmdGyuTDOC4TjnwhGHyMQn1Z8a8bvNdeetY6/s/4xkV5g5fmRMVE9tPPx 9RF1jsuOFXV15VAMHsaHYUCsO5wpGl7+YdR8UXS0M2eKooRY+3RIMgQeSaObE4VrOj jExDSPjri9WCETFmY2/1AWWnvj8rDmXpr4Wuuckbbyp+H43DiJhuvYL0yLacAw2jOe 8T7kU4NXCgYam84ue8F4tqP2aTYGFou5xnn0bSViTIke2LyF/xuAlW1miHjIWYqEZV jiqeNniY5egKQ== Received: from [172.16.0.99] (192-222-143-198.qc.cable.ebox.net [192.222.143.198]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4QCXx51pMsz11lg; Fri, 5 May 2023 10:23:53 -0400 (EDT) Message-ID: <190e5f92-f386-77a4-21c3-7f07b15ac4a3@efficios.com> Date: Fri, 5 May 2023 10:23:57 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: [RFC PATCH 4/4] llist.h: Fix parentheses around macro pointer parameter use Content-Language: en-US To: Linus Torvalds Cc: "Huang, Ying" , Andrew Morton , linux-kernel@vger.kernel.org, Peter Zijlstra References: <20230504012914.1797355-1-mathieu.desnoyers@efficios.com> <20230504012914.1797355-4-mathieu.desnoyers@efficios.com> <87pm7gd4l5.fsf@yhuang6-desk2.ccr.corp.intel.com> <8c28baa8-0945-fd77-3d1d-92c99c7bbbd1@efficios.com> From: Mathieu Desnoyers In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-5.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RDNS_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 2023-05-04 13:16, Linus Torvalds wrote: > On Thu, May 4, 2023 at 7:54 AM Mathieu Desnoyers > wrote: >> +#define list_prepare_entry(pos, head, member) \ >> + ((pos) ? : list_entry(head, typeof(*pos), member)) >> >> So even though the fact that "pos" is used as an lvalue specifically in >> llist_for_each_entry_safe() makes it so that the parentheses are not >> strictly required around "pos" in typeof(*pos), I argue that we should >> still add those for consistency. > > Ack. It may not matter in reality because of how 'pos' is supposed to > be just a local variable name, but I agree that for consistency our > macros should still follow the usual pattern. > > Of course, *because* of how 'pos' is not some random expression, and > is supposed to be that local variable, and because of how it is used, > it must always violate the whole "only use once" usual pattern,. > > Exactly the same way the member name is also typically used multiple > times because of how it's not an expression, but really a "part of the > syntax". > > So an alternative might be that we should use a different syntax for > those things and make it clear that they are not normal expressions. > Some people use upper-case names for special things like that to make > them stand out as "not normal" (kind of the same way upper-case macros > themselves were a warning that they weren't normal and might evaluate > arguments multiple times). Is a list iteration position absolutely required to be a local variable, or can it be a dereferenced pointer ? Let's say we take "list_for_each()" as example: #define list_for_each(pos, head) \ for (pos = (head)->next; !list_is_head(pos, head); pos = pos->next) and turn "pos" into "POS" to make it clearer that it is used as an lvalue: #define list_for_each(POS, head) \ for (POS = (head)->next; !list_is_head(POS, head); pos = POS->next) The following usage pattern is still broken: struct list_head list; void f(struct list_head **ppos) { list_for_each(*ppos, &list) { //... } } Because ->next has higher operator precedence than "*", which is unexpected. I would argue that even if we choose to capitalize the macro special arguments used as lvalues and as member names so they stand out, it does not eliminate the need to be careful about proper use of parentheses around those parameters when they are also used as rvalues. Thanks, Mathieu -- Mathieu Desnoyers EfficiOS Inc. https://www.efficios.com