Received: by 10.223.185.116 with SMTP id b49csp761324wrg; Fri, 16 Feb 2018 06:50:24 -0800 (PST) X-Google-Smtp-Source: AH8x225Y+efe/3LD/VZ5F976uYfq3diAHNemQw66WgpzDWjhOSt6jwVmMmcDVOiM05UjtOOecwS4 X-Received: by 2002:a17:902:6884:: with SMTP id i4-v6mr6080006plk.259.1518792624190; Fri, 16 Feb 2018 06:50:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518792624; cv=none; d=google.com; s=arc-20160816; b=FeZ5pbteBQx83PGRtfmHGQ8dSSx0MwFj+vUE8LnZJ8ot5qD1iPuXZYOq25+j6zrz3y 5HsGecdvsK4+biztdzZn+PFU5FJHaQhp4oIO77cxd39U1e3xzba/YFqEdxlybl+rzJkU wdtegw3sXWlr0Xd2BqLFqq6cUTlUmYieQS9QwbheWrBsLqEgntP1HL6DYcYPm7YTmOez X7LTfpyxlNYqIOPxIPl2OZytbs3bLmA1Gh0+yuEmGE2MbJLXiKPdHAXrf+yr0FuKccgB yxzIkIoPLPWAkuckyuWthd9z5OK4hAppb8p5E+DqXqzXeyqhvstmTl60lLaUJnpAjiBZ b+0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=2idyaWE5G/QhfDNkGSXewicSNkoUYYWZ1yx9A6IXOUk=; b=O0YOl1C4444D9B2f0cwFu+pMxPzyxBb1bL5RfMZjXannd5aPblp4SVykcnmP4GiF7q fpGXkQLUIOUJhW5QOQhlxb8KD9Th2nQneFivb0L2lU25V/rjtqOIDIGi/SZcIHM5AXCl oAGziuPqxC+W3PPs+Nqp3AVHDlF7gM1FdBj4pNMGJuAXeMWhH5J2Os9flYJyvM8Ts7aY mPDrXeQHO49WL6+OPb2mqrk8knY59XAzBE8GLYs28O1fnppfZ3s1xJqTuYybr3kUdm0G H5kP94S+eCaI/cphNwGSjfdBy89c8FsR7E009fFK/TrPAn8ogY264j9XxUsQ8ce9aDkX CLkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=dRpulLUW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f62-v6si3151738plb.297.2018.02.16.06.50.09; Fri, 16 Feb 2018 06:50:24 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=dRpulLUW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1161484AbeBOTwS (ORCPT + 99 others); Thu, 15 Feb 2018 14:52:18 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:52293 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1033808AbeBOTwO (ORCPT ); Thu, 15 Feb 2018 14:52:14 -0500 Received: by mail-wm0-f66.google.com with SMTP id t3so855995wmc.2 for ; Thu, 15 Feb 2018 11:52:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=2idyaWE5G/QhfDNkGSXewicSNkoUYYWZ1yx9A6IXOUk=; b=dRpulLUW65BarCVL//G/W9gjtfqGKP5JyaX1KD3pMYBSeiDEwIx2odxE/HnHxwDt+c w7tTXFp8FM+170Wu2u/zJwgsSF4E99zF8pRlAkFcRcV4OzepJuYi7EX+CbbtfC0JGkzC 1NEqaSGpxNkatZxajnElSxg/qoMGZMegk574k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=2idyaWE5G/QhfDNkGSXewicSNkoUYYWZ1yx9A6IXOUk=; b=D0HG/A2zeI/RBWLUu+W/AxU8/BjIeTc2vLWBUlXtVzS4Zg/jAFTb81g2n+9DYO0JJF WYF2IKpoxvnP+JHdDBDHgtIJatSdAUuswZ83EQaAFDd76o1tx15KoF/zBBzuoWhae3pA JG1/tY4qT3wlkfQ1huRqm7vjhigiXBk7fjFSMSB+1vDw7deKQ7tY9TxtMR65MnAQd6bi dwuhbP5dgsRw8rKJ0mCs+rzRJNI+8PG8XOS8gF4Rx6c6Q/T6A46zx4DrnDMP4FXL11Qk vdMaZ5FvHn7j9/qMuH0pTH5SV6KJN0mczrkRkwj7R8MWo95eWuQJcO1VMSfdKGbBGkDK JDbA== X-Gm-Message-State: APf1xPAWbv9ywfFhZ1hAkdjOwDgC9rv+82G4zwNvjNDBuHyaVkqkEprs JYnzRNT9mmf8HDuAY9GsrkDLHg== X-Received: by 10.80.144.196 with SMTP id d4mr4825096eda.164.1518724333158; Thu, 15 Feb 2018 11:52:13 -0800 (PST) Received: from prevas-ravi.waoo.dk (dhcp-5-186-126-104.cgn.ip.fibianet.dk. [5.186.126.104]) by smtp.gmail.com with ESMTPSA id i2sm5636269ede.97.2018.02.15.11.52.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 15 Feb 2018 11:52:12 -0800 (PST) From: Rasmus Villemoes To: Thomas Gleixner , Dan Williams , Will Deacon , Ingo Molnar , Rasmus Villemoes Cc: Linus Torvalds , stable@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] linux/nospec.h: allow index argument to have const-qualified type Date: Thu, 15 Feb 2018 20:52:07 +0100 Message-Id: <20180215195209.15299-1-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.15.1 In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The last expression in a statement expression need not be a bare variable, quoting gcc docs The last thing in the compound statement should be an expression followed by a semicolon; the value of this subexpression serves as the value of the entire construct. and we already use that in e.g. the min/max macros which end with a ternary expression. This way, we can allow index to have const-qualified type, which will in some cases avoid the need for introducing a local copy of index of non-const qualified type. That, in turn, can prevent readers not familiar with the internals of array_index_nospec from wondering about the seemingly redundant extra variable, and I think that's worthwhile considering how confusing the whole _nospec business is. The expression _i&_mask has type unsigned long (since that is the type of _mask, and the BUILD_BUG_ONs guarantee that _i will get promoted to that), so in order not to change the type of the whole expression, add a cast back to typeof(_i). Cc: stable@vger.kernel.org Signed-off-by: Rasmus Villemoes --- cc stable because if this is ok, there will probably be future users relying on this which also get cc'ed to -stable. include/linux/nospec.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/linux/nospec.h b/include/linux/nospec.h index fbc98e2c8228..132e3f5a2e0d 100644 --- a/include/linux/nospec.h +++ b/include/linux/nospec.h @@ -72,7 +72,6 @@ static inline unsigned long array_index_mask_nospec(unsigned long index, BUILD_BUG_ON(sizeof(_i) > sizeof(long)); \ BUILD_BUG_ON(sizeof(_s) > sizeof(long)); \ \ - _i &= _mask; \ - _i; \ + (typeof(_i)) (_i & _mask); \ }) #endif /* _LINUX_NOSPEC_H */ -- 2.15.1