From patchwork Thu May 4 20:05:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Desnoyers X-Patchwork-Id: 90226 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp597236vqo; Thu, 4 May 2023 13:46:32 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ448S2QLsIQSgTAw5xRcjpYoGOC0ZkD+ogDLWF5vE53ZogOE1mvfcQHWOgIwlJVs/YVdMzG X-Received: by 2002:a05:6a00:1a11:b0:63b:89ba:fc9c with SMTP id g17-20020a056a001a1100b0063b89bafc9cmr4303756pfv.27.1683233192041; Thu, 04 May 2023 13:46:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683233192; cv=none; d=google.com; s=arc-20160816; b=AOioLOfXyXMIFYq9LPUpHoe1P2bsA6KtXEUcdKhA8srW6mGnnAjUNAXjDdovWUI8Dw 8Y3wHsrYdgbFT9HK0/ZQ8H6cuwuZUGWKtfONe05CPXAebHgaMb4c0zlfar1Y0E012JY/ 7hZkMQqWfEqt9p3H3CxT8OEaTCrP4EKI0AUc+N7TOyH20GgdJFroL5vfPmoL3eTn3WzS XqbTE7VuU5vHgKiL4IfpehrJKSMN+fQZtg2iScqJbSk8bVgcdPEPA+5fT5Z2ZDZBtLLS TBLAi3770MRo07AGYkbkLTQXML8mL3u/6FHMfWRrkArYiVzn5IGb5OblmyMf/PrTWurO 7iaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Zti40A3E9W1uH526WPtZKO9ZOi9tS1JUTyb1/r8Eh9U=; b=YqXTFM06CwkANwx/gLVw9zvfbkoNn87HHuL4kdDEuDExogZIZhiSxWQen9dBkNBKH4 zU5/Wxe2cGkG6IcU2Ln8azVrDGplVXK6kk80JXUR/c3DmiOp/APZlURHu5FEX3pGTBat /jARw5TEh7YX8lx66Vpe5y5MX9eKa5dGg99P6esgmOxxxsrTq2sl0ngZigE7gSurg97j gCLPBQbG7o5VXlECToPS8Ou3mtzMknD2nFuPlII/wxJOXEOoybbyDlCqL174CKVg05cC /UUm1VzicIajzAyN0FSaeJS3EPTCYnDVFvFMiLlg2NEVOUXc5qTMgNJM1bSbIEhhR906 5ULA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=smtpout1 header.b="pP/WOQu2"; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a2-20020aa79702000000b0063d408c714bsi248642pfg.175.2023.05.04.13.46.19; Thu, 04 May 2023 13:46:32 -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="pP/WOQu2"; 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 S231272AbjEDUck (ORCPT + 99 others); Thu, 4 May 2023 16:32:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231137AbjEDUcU (ORCPT ); Thu, 4 May 2023 16:32:20 -0400 Received: from smtpout.efficios.com (smtpout.efficios.com [167.114.26.122]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B5EB19435; Thu, 4 May 2023 13:21:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=efficios.com; s=smtpout1; t=1683230732; bh=W9zAZi8VwGgVLnwB1Kz05im9spQ0PM5+IFpjRSSrhRE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pP/WOQu25fetQ3sRoYaQurZejTtqepJNV9c4Kuqjs22wa8BGt5gMJ25ZiFCE0l0BI GNuj7gkGiKFbAbQ341x8qDNPFhW2niVnAQxIkb16dhbJPSn1pDjCi0Uu+A3ECdpZlb 2do0i0ahDdGKtSRaoXczdV/8LKiritrQ1vxfWre/+AtgKIv+8KtkI8oPKxXd7LAJl/ 8bqzLbzBQzeaaAjSJUXVWwB8pa0bNThwR3NUSqXqNaiJapkWuYtpYLrWgxlXsvFGEV i6DkCbILWnO5e3PBAepEhC3ZeeC2QTi+RJDi/azdj5WAmFqeh4M/ZUm63LzJkdS4me CSMnHx8BkUX1g== Received: from localhost.localdomain (192-222-143-198.qc.cable.ebox.net [192.222.143.198]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4QC4Ym0sqPzxRH; Thu, 4 May 2023 16:05:32 -0400 (EDT) From: Mathieu Desnoyers To: Andrew Morton Cc: linux-kernel@vger.kernel.org, Mathieu Desnoyers , "Paul E. McKenney" , Frederic Weisbecker , Neeraj Upadhyay , Joel Fernandes , Josh Triplett , Boqun Feng , Steven Rostedt , Lai Jiangshan , Zqiang , rcu@vger.kernel.org Subject: [RFC PATCH 02/13] rculist.h: Fix parentheses around macro pointer parameter use Date: Thu, 4 May 2023 16:05:16 -0400 Message-Id: <20230504200527.1935944-3-mathieu.desnoyers@efficios.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230504200527.1935944-1-mathieu.desnoyers@efficios.com> References: <20230504200527.1935944-1-mathieu.desnoyers@efficios.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764997927844799338?= X-GMAIL-MSGID: =?utf-8?q?1764997927844799338?= Add missing parentheses around use of macro argument "pos" in those patterns to ensure operator precedence behaves as expected: - typeof(*pos) - pos->member 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_rcu((*t2), &testlist, node) { /* works */ //... } list_for_each_entry_rcu(*t2, &testlist, node) { /* broken */ //... } } The typeof(*pos) lack of parentheses around "pos" is not an issue per se in the specific macros modified here because "pos" is used as an lvalue, which should prevent use of any operator causing issue. Still add the extra parentheses for consistency. Signed-off-by: Mathieu Desnoyers Cc: "Paul E. McKenney" Cc: Andrew Morton Cc: Frederic Weisbecker Cc: Neeraj Upadhyay Cc: Joel Fernandes Cc: Josh Triplett Cc: Boqun Feng Cc: Steven Rostedt Cc: Lai Jiangshan Cc: Zqiang Cc: rcu@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- include/linux/rculist.h | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/include/linux/rculist.h b/include/linux/rculist.h index d29740be4833..d27aeff5447d 100644 --- a/include/linux/rculist.h +++ b/include/linux/rculist.h @@ -388,9 +388,9 @@ static inline void list_splice_tail_init_rcu(struct list_head *list, */ #define list_for_each_entry_rcu(pos, head, member, cond...) \ for (__list_check_rcu(dummy, ## cond, 0), \ - pos = list_entry_rcu((head)->next, typeof(*pos), member); \ - &pos->member != (head); \ - pos = list_entry_rcu(pos->member.next, typeof(*pos), member)) + pos = list_entry_rcu((head)->next, typeof(*(pos)), member);\ + &(pos)->member != (head); \ + pos = list_entry_rcu((pos)->member.next, typeof(*(pos)), member)) /** * list_for_each_entry_srcu - iterate over rcu list of given type @@ -407,9 +407,9 @@ static inline void list_splice_tail_init_rcu(struct list_head *list, */ #define list_for_each_entry_srcu(pos, head, member, cond) \ for (__list_check_srcu(cond), \ - pos = list_entry_rcu((head)->next, typeof(*pos), member); \ - &pos->member != (head); \ - pos = list_entry_rcu(pos->member.next, typeof(*pos), member)) + pos = list_entry_rcu((head)->next, typeof(*(pos)), member);\ + &(pos)->member != (head); \ + pos = list_entry_rcu((pos)->member.next, typeof(*(pos)), member)) /** * list_entry_lockless - get the struct for this entry @@ -441,9 +441,9 @@ static inline void list_splice_tail_init_rcu(struct list_head *list, * but never deleted. */ #define list_for_each_entry_lockless(pos, head, member) \ - for (pos = list_entry_lockless((head)->next, typeof(*pos), member); \ - &pos->member != (head); \ - pos = list_entry_lockless(pos->member.next, typeof(*pos), member)) + for (pos = list_entry_lockless((head)->next, typeof(*(pos)), member); \ + &(pos)->member != (head); \ + pos = list_entry_lockless((pos)->member.next, typeof(*(pos)), member)) /** * list_for_each_entry_continue_rcu - continue iteration over list of given type @@ -464,9 +464,9 @@ static inline void list_splice_tail_init_rcu(struct list_head *list, * position. */ #define list_for_each_entry_continue_rcu(pos, head, member) \ - for (pos = list_entry_rcu(pos->member.next, typeof(*pos), member); \ - &pos->member != (head); \ - pos = list_entry_rcu(pos->member.next, typeof(*pos), member)) + for (pos = list_entry_rcu((pos)->member.next, typeof(*(pos)), member); \ + &(pos)->member != (head); \ + pos = list_entry_rcu((pos)->member.next, typeof(*(pos)), member)) /** * list_for_each_entry_from_rcu - iterate over a list from current point @@ -486,8 +486,8 @@ static inline void list_splice_tail_init_rcu(struct list_head *list, * after the given position. */ #define list_for_each_entry_from_rcu(pos, head, member) \ - for (; &(pos)->member != (head); \ - pos = list_entry_rcu(pos->member.next, typeof(*(pos)), member)) + for (; &(pos)->member != (head); \ + pos = list_entry_rcu((pos)->member.next, typeof(*(pos)), member)) /** * hlist_del_rcu - deletes entry from hash list without re-initialization