Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp4377465rwr; Mon, 8 May 2023 07:00:03 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ62sT8LVFPwG0GwY5q2gjl+PBGfol99LXlKAX/ccSRcXg2j9aYWeetqaQr9I5cselP/gPUM X-Received: by 2002:a17:90a:fa96:b0:24e:1093:c8c0 with SMTP id cu22-20020a17090afa9600b0024e1093c8c0mr10381302pjb.7.1683554403274; Mon, 08 May 2023 07:00:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683554403; cv=none; d=google.com; s=arc-20160816; b=gLiC6P7tLf+oKmYATLAUOUmnZMLM+++AIEflct4nr4eBd7NK3CDXoY1JyWB8Dse3Cd lCFtDhjIaFHabkbim2t1AE5kIuM2DWmkxoA/CufouqXuwTuZGVs1lOPEasJKuYgrXsqC nxuCjHFUhWTIuyi+2o10k0exk0i3ovt+4h9kCOZudsntGnGaG2QkwWHEi6MpUahkxUju vJ3Vfkye1LH0C175DLaGxGZgcuT711o5/abat8eO650B3+GmTnTuxfpNbRPkb+rFgHdO q1H2fNbiuDl+ZE+ovnBkn36GWJVIwUTG0CnrCBPbmSs/RkV9rvZrquzPnNyVdr06P1vb s6+w== 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=35qOtG8mVD8tYw0NVWjxSVIF364cIx7Nuw4F+F1ju5g=; b=g4r3YVSMJ4EMRUEUysEcRBxxIEbRuagL/NpXx1HbBe6T69Tljzw4NgqIhC4xbqZ3ty QQG2V2p13Uard+27vMHhCJeFduPpV16CO9sJ/IjesgMSxGKxpq+Ng5JjUoNQ7ogh3aOC uflTkzJqtWc/Bl8bjwMz36VXO8G5c2Oxi+dpjLIfE7HB2FoGthdm5zUoJaz04/nfgvfc bGiT5F628LZ7MBHcRobuEugChbzZCpUXhBmokiVzmvdU6Zb2eVjQM3Lj2uAc6kJxM1hx kjfX0l0E32HI+GuCxdVzI0DGFlhE1BMxkZCHUAB1nyCTeaZERUzV5nQcWW+Wfr859qOv i8Ww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=smtpout1 header.b="VK/q15FG"; 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 b66-20020a633445000000b0052c74f7adfesi8981038pga.60.2023.05.08.06.59.49; Mon, 08 May 2023 07:00:03 -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="VK/q15FG"; 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 S234310AbjEHNqn (ORCPT + 99 others); Mon, 8 May 2023 09:46:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234072AbjEHNqk (ORCPT ); Mon, 8 May 2023 09:46:40 -0400 Received: from smtpout.efficios.com (smtpout.efficios.com [167.114.26.122]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8562235D94 for ; Mon, 8 May 2023 06:46:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=efficios.com; s=smtpout1; t=1683553595; bh=/cSiXhiFvMYAaJxpoDMBzGlk9C+yOlLOWY8dSayYoys=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=VK/q15FGkAiLco+KoBE8oAHJcjYFf/TtUDsNNwMI9Jl0zuau0qNTm6Vtpji4u4kD9 q+iqfdc/W1mUBH/e62WmQOJEHuvO+JRlEoIYT/6eAOe2C5+C5uwu0NRQC4NkbwVw4W zzinAn/Okanr05Jz72S/23u6n99Glvjv4w7VFrXKZowv7SxsnpmAI7NEXL4LenlKq1 0BpIarcybOrVS+MvTPQm6lKSEiD809UHwKL28sqqNb/E612JAdzJpAbk8gWKF2C6Z1 EvuziMvX+xXIqlcZY5/qKZAgkZ+yXXZHhYZEr0QPgGg2/V0pPo+tAhnSfqBNTxPbrp keFAnDS++XU+g== 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 4QFMyg522Wz12Bt; Mon, 8 May 2023 09:46:35 -0400 (EDT) Message-ID: <6971bfd0-b200-6cb8-7cd8-9973b72ef9ba@efficios.com> Date: Mon, 8 May 2023 09:46:40 -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 05/13] list.h: Fix parentheses around macro pointer parameter use Content-Language: en-US To: Andy Shevchenko Cc: Andrew Morton , linux-kernel@vger.kernel.org, Greg Kroah-Hartman , David Howells , Ricardo Martinez References: <20230504200527.1935944-1-mathieu.desnoyers@efficios.com> <20230504200527.1935944-6-mathieu.desnoyers@efficios.com> From: Mathieu Desnoyers In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,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-08 08:16, Andy Shevchenko wrote: > 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? The following case still works after removing the extra parentheses around "head" because the parentheses are present where the macro is used: LIST_HEAD(testlist); int f2(void) { return 1; } void f(void) { struct list_head *pos; list_for_each(pos, (f2(), &testlist)) { //... } } The only use I found that would break is as follows: LIST_HEAD(testlist); int f2(void) { return 1; } #define eval(...) __VA_ARGS__ void f(void) { struct list_head *pos; list_for_each(pos, eval(f2(), &testlist)) { //... } } Because "eval()" will evaluate "f(), &testlist" with comma and all, without enclosing parentheses. So the question is: do we want to support this kind-of-odd macro evaluation, considering that it requires adding parentheses around pretty much all macro parameters when used as expressions between commas? Thanks, Mathieu -- Mathieu Desnoyers EfficiOS Inc. https://www.efficios.com