Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp4284557rwr; Mon, 8 May 2023 05:49:21 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6plozAQjwJeY0RXzxIC2u/49YluPl8pBBiLZXAS9QEFzyG47dDkkwQIUOj4THOOiDlRDkL X-Received: by 2002:a17:90b:1985:b0:24e:1f8:b786 with SMTP id mv5-20020a17090b198500b0024e01f8b786mr9749337pjb.19.1683550161451; Mon, 08 May 2023 05:49:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683550161; cv=none; d=google.com; s=arc-20160816; b=DxorWn8ZpTEX9JbMqeCZwFsQggQHgRdr7ITcEUj50mdrChLLJx3NHjDqSV6BtkJK5N J1bobhvq2+hHk4OGWJOItL6Yal2gBJJRpkr/BAopSBzBT1aYCmuq+8v1r6xpKh1DrKaT y+1e1PuJjzDFh9OdEZWvEypnm4ytf19WbWzuBjE8rNFhaa/HKJ+9jeqtg2RXeMfldMKd Y+jLJg87xd6kg/j0aAlVgPYFiVhbzaAec0ndNdG71naORzUQ89wdiIwKVU5JIYSOAoZS dUf+hPiKjzZiK8Ht9yLQyBR3EhS1yYI4N7wKzhU5JWtaT+17B+Ci8Qg4jcWCaohMFbVf KxtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:organization:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=gPTpl3gxEMFEcIGM4bBiDczjvzt1ns4TQNkR12uX36k=; b=sc8+jUUtmycd3uTF3PSpGJesIM+7LfxBQwofBGxkVc02Ag7/OH4WNkkQcHNRBE+EKp J6QI+6/rxDY2BXrmtsi4qWM82gHMMqeXXesbkSg04qbuZn6/LWuE29LZ84URccc7jQhC 4AYESpLd82/YYXhgx7GoZr/YplIqC1GFjiQfsavQysNSFwlfqdmsGKyCnvgfH6PirLHq OrJKhOHBbK1DGqeY5vx0J+Ea/DubJIpEHjn0EOKKC1xVVA3Unk9uwZLk2nucf+CIGuci pw3QtNGoLJpwBOtUwOG2WOn4zpwRPG4+GgTPqgbETGwnuqAwLr8zrXD1e1kGoOZ30lI0 bzgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=UZyVFuCV; 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=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u11-20020a6540cb000000b00528de9650b9si8126568pgp.696.2023.05.08.05.49.05; Mon, 08 May 2023 05:49:21 -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=@intel.com header.s=Intel header.b=UZyVFuCV; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233831AbjEHMQr (ORCPT + 99 others); Mon, 8 May 2023 08:16:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233792AbjEHMQn (ORCPT ); Mon, 8 May 2023 08:16:43 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24B6E37C4C for ; Mon, 8 May 2023 05:16:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1683548202; x=1715084202; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=1TRcGmemRzctXjRrFvBetfH0znJQWjfV8lCXlG5tDDQ=; b=UZyVFuCVZWRCK/cC68QjNf3N19tQswu+mIcQf8r6yoV7vsSxHi5MmYM6 ytcLnaLynZsamBW7Hv71hlSL/PIATH8JYpODzY76mOqJvobzIh5MPXHzi 0TARZzpWs17i9l+2qB+KdCWpSK9C2Y8HH2DZ9fRm4QHft4HQTZWgSIoj5 Xh3C1SdMjoVxyDRm5CDPzP3zakCz0bCjZ1ZFb1G1igEDLmUzy+ROJdX4V 9UNKOCo7M0srsq5IgH6qCKZafDua+BZ0l4h+x9Ue6utns0YafNntDL7r+ igC7JMVtLENeOB3MGhBxa7ef4ejeJN0bgxV5piQBqpiKR3HVNw8P2wvhM w==; X-IronPort-AV: E=McAfee;i="6600,9927,10703"; a="349660209" X-IronPort-AV: E=Sophos;i="5.99,259,1677571200"; d="scan'208";a="349660209" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 May 2023 05:16:41 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10703"; a="788075011" X-IronPort-AV: E=Sophos;i="5.99,258,1677571200"; d="scan'208";a="788075011" Received: from smile.fi.intel.com ([10.237.72.54]) by FMSMGA003.fm.intel.com with ESMTP; 08 May 2023 05:16:40 -0700 Received: from andy by smile.fi.intel.com with local (Exim 4.96) (envelope-from ) id 1pvznC-00Aqvh-1e; Mon, 08 May 2023 15:16:38 +0300 Date: Mon, 8 May 2023 15:16:38 +0300 From: Andy Shevchenko To: Mathieu Desnoyers Cc: Andrew Morton , linux-kernel@vger.kernel.org, Greg Kroah-Hartman , David Howells , Ricardo Martinez Subject: Re: [RFC PATCH 05/13] list.h: Fix parentheses around macro pointer parameter use Message-ID: References: <20230504200527.1935944-1-mathieu.desnoyers@efficios.com> <20230504200527.1935944-6-mathieu.desnoyers@efficios.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230504200527.1935944-6-mathieu.desnoyers@efficios.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,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 Thu, May 04, 2023 at 04:05:19PM -0400, Mathieu Desnoyers wrote: > Add missing parentheses around use of macro argument "pos" in those > patterns to ensure operator precedence behaves as expected: > > - typeof(*pos) > - pos->member > - "x = y" is changed for "x = (y)", because "y" can be an expression > containing a comma if it is the result of the expansion of a macro such > as #define eval(...) __VA_ARGS__, which would cause unexpected operator > precedence. This use-case is far-fetched, but we have to choose one > way or the other (with or without parentheses) for consistency, > - x && y is changed for (x) && (y). > > Remove useless parentheses around use of macro parameter (head) in the > following pattern: > > - list_is_head(pos, (head)) > > Because comma is the lowest priority operator already, so the extra pair > of parentheses is redundant. But strictly speaking it might be something like list_...(..., (a, b)) where (a, b) is the head. No? > This corrects the following usage pattern where operator precedence is > unexpected: > > LIST_HEAD(testlist); > > struct test { > struct list_head node; > int a; > }; > > // pos->member issue > void f(void) > { > struct test *t1; > struct test **t2 = &t1; > > list_for_each_entry((*t2), &testlist, node) { /* works */ > //... > } > list_for_each_entry(*t2, &testlist, node) { /* broken */ > //... Me still in doubt. But it's up to maintainers. > } > } > > // typeof(*pos) issue > void f2(void) > { > struct test *t1 = NULL, *t2; > > t2 = list_prepare_entry((0 + t1), &testlist, node); /* works */ > t2 = list_prepare_entry(0 + t1, &testlist, node); /* broken */ > } > > Note that the macros in which "pos" is also used as an lvalue probably > don't suffer from the lack of parentheses around "pos" in typeof(*pos), > but add those nevertheless to keep everything consistent. -- With Best Regards, Andy Shevchenko