From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932704AbcFGNPE (ORCPT ); Tue, 7 Jun 2016 09:15:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37874 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932308AbcFGNPC (ORCPT ); Tue, 7 Jun 2016 09:15:02 -0400 From: Mateusz Guzik To: Peter Zijlstra Cc: linux-kernel@vger.kernel.org, tglx@linutronix.de, mingo@kernel.org, hpa@zytor.com, torvalds@linux-foundation.org Subject: [PATCH] locking/barriers: evaluate the argument to lockless_dereference only once Date: Tue, 7 Jun 2016 15:14:55 +0200 Message-Id: <1465305295-16336-1-git-send-email-mguzik@redhat.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 07 Jun 2016 13:15:01 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The commit 25841ee0e9d2a ("Validate lockless_dereference() is used on a pointer type") added a second use of the parameter to the macro. This leads to trouble with consumers which use arguments with side effects. Instead, reuse the value which was read the first time. Signed-off-by: Mateusz Guzik --- include/linux/compiler.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/compiler.h b/include/linux/compiler.h index e9c6417..06f27fd 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -551,8 +551,8 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s */ #define lockless_dereference(p) \ ({ \ - __maybe_unused const void * const _________p2 = p; \ typeof(p) _________p1 = READ_ONCE(p); \ + __maybe_unused const void * const _________p2 = _________p1; \ smp_read_barrier_depends(); /* Dependency order vs. p above. */ \ (_________p1); \ }) -- 1.8.3.1