Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp1339457rwr; Wed, 3 May 2023 13:45:13 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7wvsaxIHJd5u6fsJARU+ZTaPEo7i2Da5k568XX2D/zsVOxBu0QP6Qlfm7jde2/rTH7Rgi/ X-Received: by 2002:a17:902:f688:b0:1a6:4c2b:9e7f with SMTP id l8-20020a170902f68800b001a64c2b9e7fmr1509658plg.1.1683146713129; Wed, 03 May 2023 13:45:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683146713; cv=none; d=google.com; s=arc-20160816; b=XmvRkj8QEFjkpCmceu6UuHVBPjlnAzNudMwr2NBB2u8Qi8u95zv+VYyqBCrpaYYJUI Loz5PEE8f0HVxlgJBb8cLnOznruo1V+jC5oaecGEap9Ne6jqBQUiTarzampUd/0OwWIn uKDAy00x4S5J6KilTx5jwjCOWhJSttk57kc6AiziaLOTHXpjyKgB7gTb/eX/rQ123Ucl VpPEe2UyFn7K4RW3hqcp2xefORyYW5QWZh87JXZoFg47mONrxbfvQZ7QJ0clszFAq41V tF1pqBTpNLjWmiJR0eLvsmr/hxcQrbntH5HlaxNk1o/yd8yg4mCav05WpNGhBdVG6HD0 mpQQ== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=zhlVzz3iJZ2trbry6h7RrmdBmyEna9hpRb4LNAHBWTw=; b=ZWaMeeXMfpo3SSyA3ubebYt2DGR5ExotPMcNdwoQu7jEocrd7ErI7lHJ9/l5s0CvGU +eujRgL/ovdg1OjKTGkVf5OYDR7n6gBceadsYpmAygWrBNabinGa7vR5zilApqTzm8KW A5ynMhPCS6PnTriLEUIS1vvXrtNmiijFCdE/cq4QSiK1dJCJGciUrqBdtbGeykJibKmt 6XVLWvQCjzYaHWx600301Ygz+q4H8yVvS+20okhaR4BpsAOjQZnC9+nOsn1N/PeQhej9 VCdCmRx8cX0og7lWXZRhUqMTuJ4X3lu0tMsTqHqv5lsmuz643V+Ydr47MM0aVNA670PM B8Rw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=smtpout1 header.b=no1YqwIX; 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 e36-20020a635464000000b00528b5b28439si14079171pgm.124.2023.05.03.13.44.47; Wed, 03 May 2023 13:45:13 -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=no1YqwIX; 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 S229712AbjECUcs (ORCPT + 99 others); Wed, 3 May 2023 16:32:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229441AbjECUcr (ORCPT ); Wed, 3 May 2023 16:32:47 -0400 Received: from smtpout.efficios.com (unknown [IPv6:2607:5300:203:b2ee::31e5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 835E0198C for ; Wed, 3 May 2023 13:32:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=efficios.com; s=smtpout1; t=1683145963; bh=qNB6O5mVECCPuKgtGErPGROmbcclghgZAShV5yBxuaI=; h=From:To:Cc:Subject:Date:From; b=no1YqwIX/6oqGAIE4BX0MFBH9H00tUF8S1a7Rp3ST8/qqgk+RD0qNCU6dUWy7Up55 87HM522afz/NFXZUW+wWRlNHFRjoKu6wPtnzU8W79UU1ruLrptpAMrnXdurov8Afws FFpRaOOMVqHrc02dFUXt2s5GP+hlMfx04N+XtXde07EyDIH6yTeGgBnXFdjM7N/wc/ 55DXbnsj32SPXO9VdZdvQZimthqCMNyltnUfUgnUDBBCfb97PmVSZxxv9YUrX7MlBM 5QfRdpBQl/XfS1NbqH06nNOOfAcdy8e16/fhC+MM0JURh+MeIxJ4MEUVjW2cJqaOek 7akX+418JyjWg== Received: from localhost.localdomain (192-222-143-198.qc.cable.ebox.net [192.222.143.198]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4QBTCb416Dz11fW; Wed, 3 May 2023 16:32:43 -0400 (EDT) From: Mathieu Desnoyers To: "Paul E. McKenney" Cc: linux-kernel@vger.kernel.org, Mathieu Desnoyers , Joel Fernandes , Josh Triplett , Boqun Feng , Steven Rostedt , Lai Jiangshan , Zqiang Subject: [RFC PATCH] rcu: rcupdate.h: Add missing parentheses around macro pointer dereference Date: Wed, 3 May 2023 16:32:36 -0400 Message-Id: <20230503203236.1587590-1-mathieu.desnoyers@efficios.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RDNS_NONE,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=no 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 linux/rcupdate.h macros use the *p parameter without parentheses, e.g.: typeof(*p) rather than typeof(*(p)) The following test-case shows how it can generate confusion due to C operator precedence being reversed compared to the expectations: #define m(p) \ do { \ __typeof__(*p) v = 0; \ } while (0) void fct(unsigned long long *p1) { m(p1 + 1); /* works */ m(1 + p1); /* broken */ } Signed-off-by: Mathieu Desnoyers Cc: "Paul E. McKenney" Cc: Joel Fernandes Cc: Josh Triplett Cc: Boqun Feng Cc: Steven Rostedt Cc: Lai Jiangshan Cc: Zqiang --- include/linux/rcupdate.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h index dcd2cf1e8326..1565012fa47f 100644 --- a/include/linux/rcupdate.h +++ b/include/linux/rcupdate.h @@ -430,16 +430,16 @@ static inline void rcu_preempt_sleep_check(void) { } #ifdef __CHECKER__ #define rcu_check_sparse(p, space) \ - ((void)(((typeof(*p) space *)p) == p)) + ((void)(((typeof(*(p)) space *)p) == p)) #else /* #ifdef __CHECKER__ */ #define rcu_check_sparse(p, space) #endif /* #else #ifdef __CHECKER__ */ #define __unrcu_pointer(p, local) \ ({ \ - typeof(*p) *local = (typeof(*p) *__force)(p); \ + typeof(*(p)) *local = (typeof(*(p)) *__force)(p); \ rcu_check_sparse(p, __rcu); \ - ((typeof(*p) __force __kernel *)(local)); \ + ((typeof(*(p)) __force __kernel *)(local)); \ }) /** * unrcu_pointer - mark a pointer as not being RCU protected @@ -452,29 +452,29 @@ static inline void rcu_preempt_sleep_check(void) { } #define __rcu_access_pointer(p, local, space) \ ({ \ - typeof(*p) *local = (typeof(*p) *__force)READ_ONCE(p); \ + typeof(*(p)) *local = (typeof(*(p)) *__force)READ_ONCE(p); \ rcu_check_sparse(p, space); \ - ((typeof(*p) __force __kernel *)(local)); \ + ((typeof(*(p)) __force __kernel *)(local)); \ }) #define __rcu_dereference_check(p, local, c, space) \ ({ \ /* Dependency order vs. p above. */ \ - typeof(*p) *local = (typeof(*p) *__force)READ_ONCE(p); \ + typeof(*(p)) *local = (typeof(*(p)) *__force)READ_ONCE(p); \ RCU_LOCKDEP_WARN(!(c), "suspicious rcu_dereference_check() usage"); \ rcu_check_sparse(p, space); \ - ((typeof(*p) __force __kernel *)(local)); \ + ((typeof(*(p)) __force __kernel *)(local)); \ }) #define __rcu_dereference_protected(p, local, c, space) \ ({ \ RCU_LOCKDEP_WARN(!(c), "suspicious rcu_dereference_protected() usage"); \ rcu_check_sparse(p, space); \ - ((typeof(*p) __force __kernel *)(p)); \ + ((typeof(*(p)) __force __kernel *)(p)); \ }) #define __rcu_dereference_raw(p, local) \ ({ \ /* Dependency order vs. p above. */ \ typeof(p) local = READ_ONCE(p); \ - ((typeof(*p) __force __kernel *)(local)); \ + ((typeof(*(p)) __force __kernel *)(local)); \ }) #define rcu_dereference_raw(p) __rcu_dereference_raw(p, __UNIQUE_ID(rcu)) -- 2.25.1