From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Google-Smtp-Source: AG47ELtnWGJfKj1UeNqo2/hfvh5PPr58YP9ehWRLfz205WwPkk2pUS6Ih+ZK5Tp9910cWLP0EzzT ARC-Seal: i=1; a=rsa-sha256; t=1520641224; cv=none; d=google.com; s=arc-20160816; b=LyXzLzeUiJJj/aaYP/cTeLREx4qC3ujnvfIgDN9rtM61R+03zhupwKHLjethEKXzWW zE12fHLl//ysbF0JVyvQw5RTdUGEssu3GlxDu3XxvUtzGkTJ6SeItOq4/mlCPiFrsfuM 93YxOK3ZbvaHxpWHLiG44RTsd9H82z4lxWAzc9o6czM9Eay38+UhhKU2wAReNAaV8N3x QbCT9YjuQmvAVGz1jiE6jzDDp7+LwNpTM0A7Kvr3jUBSuBTY2qI9CG3fS90xg4n4hr+b 9h+/qOvUDNuVPS12oLzDDwfqOBd9XMIZ2XBAtLUgyDxPEsEpWGRmUE0AtSoSYCll9zzm aigA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=KNxcT0N7kQ57V8T3rbLNwTAhQYh72xw8Od9Ia5n7f7U=; b=JsoywzlOqiDFNGaSOwg01FiEXXzovqAt0vt9BHm1vDkQRVIOVt5NNhzNr3Lzm3HwYt Ny23DXE+yv9/qCL7bQi/8SLWd1vhnIileF+gZvk847p6dEbKfebL16R8EKcMSd+BHNlX tAwnPm3UgeejDwx4KjyLlMSI4T2o2Bh8GVIyYbXGcD1bXtZqAU7urfO0Keg9NvDSm41w 2QNHpLgbQC2A4KqmZRLvSSs7uN96iG8cyI2nBLoHUnEoRx6F1GXBttv5yGf0L0DFv/QY pDzrgvjNz2+WYeNvmPoKiUT+AL0CzEsxln9R31/jM/oSo+AYk2zZG5zgeM+zHXyAfwzb Fycg== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning gregkh@linuxfoundation.org does not designate 185.236.200.248 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning gregkh@linuxfoundation.org does not designate 185.236.200.248 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Rasmus Villemoes , Dan Williams , Linus Torvalds , Andy Lutomirski , Arjan van de Ven , Borislav Petkov , Dave Hansen , David Woodhouse , Josh Poimboeuf , Peter Zijlstra , Thomas Gleixner , Will Deacon , linux-arch@vger.kernel.org, Ingo Molnar Subject: [PATCH 4.4 08/36] nospec: Allow index argument to have const-qualified type Date: Fri, 9 Mar 2018 16:18:24 -0800 Message-Id: <20180310001807.674544545@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180310001807.213987241@linuxfoundation.org> References: <20180310001807.213987241@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-LABELS: =?utf-8?b?IlxcU2VudCI=?= X-GMAIL-THRID: =?utf-8?q?1594507892706683015?= X-GMAIL-MSGID: =?utf-8?q?1594507892706683015?= X-Mailing-List: linux-kernel@vger.kernel.org List-ID: 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Rasmus Villemoes commit b98c6a160a057d5686a8c54c79cc6c8c94a7d0c8 upstream. 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). Signed-off-by: Rasmus Villemoes Signed-off-by: Dan Williams Acked-by: Linus Torvalds Cc: Andy Lutomirski Cc: Arjan van de Ven Cc: Borislav Petkov Cc: Dave Hansen Cc: David Woodhouse Cc: Greg Kroah-Hartman Cc: Josh Poimboeuf Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Will Deacon Cc: linux-arch@vger.kernel.org Cc: stable@vger.kernel.org Link: http://lkml.kernel.org/r/151881604837.17395.10812767547837568328.stgit@dwillia2-desk3.amr.corp.intel.com Signed-off-by: Ingo Molnar Signed-off-by: Greg Kroah-Hartman --- include/linux/nospec.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) --- a/include/linux/nospec.h +++ b/include/linux/nospec.h @@ -66,7 +66,6 @@ static inline unsigned long array_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 */