Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2672196pxj; Mon, 31 May 2021 07:56:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw+odTsc3MkIx13vJyDVrJHFaLGhGWsTQZk8JYxsD/86r5bV484ViKn1/CnjKehJNwTkLnm X-Received: by 2002:a92:d4cf:: with SMTP id o15mr341537ilm.79.1622473013872; Mon, 31 May 2021 07:56:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622473013; cv=none; d=google.com; s=arc-20160816; b=nh3fWlreqQfTwgCmZ/U9bPG6DUrmIvjCIsAjq0WCoT3GQasGQ4mMxig24MzTJf23KG 3HypSdTl0xw8vEFD6uiuazaYYsJnOHBevgd5QkPhFqLOZwxhjyAugOSOO39jumm+abY9 tn6XA4z3J4Tk/JMp6ZQbclk5slj2CVtSdowlcGFpYt3j0vfwia5/NWCMGLb+6erTvLM2 ikYUIh1YxdjYI2kKLQV54+B93EG6TwyfYzlHugbZWLWTGTPlrf9d0UQJPuYs27Ur9QpA MbdzqVt7ByMvsuSMKIK7HTTyj+adu2chqcn40aGhkjN758HSplDtKabFOc0tA3OOCQuW 8gfQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Am6xKsGOfRAMC7xc+skVBrL9EvZDmapIxegao4CEJBo=; b=CNOYEaYgT5lcVsqkfDfp0ziqwfCHc0aKLoBxBieeA4++Y8PnS4FydTiSNsnSBgmWtc Goy+dWZCgwfaGaK1vd/IYY8+26Ax03vocWi5HRkBOl8W+rcb35TT7Zbq4DGjIkOzpkRm hv8KN3coM/ETyac2bjypE9y3kGEwGtNxjDTYx8Cm7sKWa4S23m0i8vMLoxDm8TzOMra8 eTt/9KMuh7Cr/HJV3ycvtMU1c/5Q+1T5eKsKMXG3bcSm8K0/GpFsKLtdZ6Y16dZfI3Qk jNOdDf+UOoBaZx/nJUiXaMrLLRZpOSARPv4Yk7xN+4F8zUo4eaE5xw88u2d8A7RfbLl1 BMQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xXdOGvy0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k7si8659263ilh.42.2021.05.31.07.56.40; Mon, 31 May 2021 07:56:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xXdOGvy0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234105AbhEaO5q (ORCPT + 99 others); Mon, 31 May 2021 10:57:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:36394 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233424AbhEaOEw (ORCPT ); Mon, 31 May 2021 10:04:52 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0C76061406; Mon, 31 May 2021 13:38:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622468293; bh=HEYbWVopiiv8JhXlkj0mpt1+zBK4clPd/uzpkSwxRNY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xXdOGvy06AyIVHRGn+IYA61PuJbdtneRM9PzhLgoHgrD6Y9QM5GcV+5emMkuMH6zD htF6DB05VUnjviRnOp52QMUSg38n6HQasuATAFWFXxuEtZ+shnWZKdOyvjCC1YZ4Eb mrc8Zk6FwYTaEMTTUNKIXDeHqOz9YhiB7JbRkxbI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Rikard Falkeborn , Tetsuo Handa , Arnd Bergmann , Andy Shevchenko , Ard Biesheuvel , Yury Norov , Peter Zijlstra , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH 5.10 188/252] linux/bits.h: fix compilation error with GENMASK Date: Mon, 31 May 2021 15:14:13 +0200 Message-Id: <20210531130704.398247040@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130657.971257589@linuxfoundation.org> References: <20210531130657.971257589@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rikard Falkeborn [ Upstream commit f747e6667ebb2ffb8133486c9cd19800d72b0d98 ] GENMASK() has an input check which uses __builtin_choose_expr() to enable a compile time sanity check of its inputs if they are known at compile time. However, it turns out that __builtin_constant_p() does not always return a compile time constant [0]. It was thought this problem was fixed with gcc 4.9 [1], but apparently this is not the case [2]. Switch to use __is_constexpr() instead which always returns a compile time constant, regardless of its inputs. Link: https://lore.kernel.org/lkml/42b4342b-aefc-a16a-0d43-9f9c0d63ba7a@rasmusvillemoes.dk [0] Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=19449 [1] Link: https://lore.kernel.org/lkml/1ac7bbc2-45d9-26ed-0b33-bf382b8d858b@I-love.SAKURA.ne.jp [2] Link: https://lkml.kernel.org/r/20210511203716.117010-1-rikard.falkeborn@gmail.com Signed-off-by: Rikard Falkeborn Reported-by: Tetsuo Handa Acked-by: Arnd Bergmann Reviewed-by: Andy Shevchenko Cc: Ard Biesheuvel Cc: Yury Norov Cc: Peter Zijlstra Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- include/linux/bits.h | 2 +- include/linux/const.h | 8 ++++++++ include/linux/minmax.h | 10 ++-------- tools/include/linux/bits.h | 2 +- tools/include/linux/const.h | 8 ++++++++ 5 files changed, 20 insertions(+), 10 deletions(-) diff --git a/include/linux/bits.h b/include/linux/bits.h index 7f475d59a097..87d112650dfb 100644 --- a/include/linux/bits.h +++ b/include/linux/bits.h @@ -22,7 +22,7 @@ #include #define GENMASK_INPUT_CHECK(h, l) \ (BUILD_BUG_ON_ZERO(__builtin_choose_expr( \ - __builtin_constant_p((l) > (h)), (l) > (h), 0))) + __is_constexpr((l) > (h)), (l) > (h), 0))) #else /* * BUILD_BUG_ON_ZERO is not available in h files included from asm files, diff --git a/include/linux/const.h b/include/linux/const.h index 81b8aae5a855..435ddd72d2c4 100644 --- a/include/linux/const.h +++ b/include/linux/const.h @@ -3,4 +3,12 @@ #include +/* + * This returns a constant expression while determining if an argument is + * a constant expression, most importantly without evaluating the argument. + * Glory to Martin Uecker + */ +#define __is_constexpr(x) \ + (sizeof(int) == sizeof(*(8 ? ((void *)((long)(x) * 0l)) : (int *)8))) + #endif /* _LINUX_CONST_H */ diff --git a/include/linux/minmax.h b/include/linux/minmax.h index c0f57b0c64d9..5433c08fcc68 100644 --- a/include/linux/minmax.h +++ b/include/linux/minmax.h @@ -2,6 +2,8 @@ #ifndef _LINUX_MINMAX_H #define _LINUX_MINMAX_H +#include + /* * min()/max()/clamp() macros must accomplish three things: * @@ -17,14 +19,6 @@ #define __typecheck(x, y) \ (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1))) -/* - * This returns a constant expression while determining if an argument is - * a constant expression, most importantly without evaluating the argument. - * Glory to Martin Uecker - */ -#define __is_constexpr(x) \ - (sizeof(int) == sizeof(*(8 ? ((void *)((long)(x) * 0l)) : (int *)8))) - #define __no_side_effects(x, y) \ (__is_constexpr(x) && __is_constexpr(y)) diff --git a/tools/include/linux/bits.h b/tools/include/linux/bits.h index 7f475d59a097..87d112650dfb 100644 --- a/tools/include/linux/bits.h +++ b/tools/include/linux/bits.h @@ -22,7 +22,7 @@ #include #define GENMASK_INPUT_CHECK(h, l) \ (BUILD_BUG_ON_ZERO(__builtin_choose_expr( \ - __builtin_constant_p((l) > (h)), (l) > (h), 0))) + __is_constexpr((l) > (h)), (l) > (h), 0))) #else /* * BUILD_BUG_ON_ZERO is not available in h files included from asm files, diff --git a/tools/include/linux/const.h b/tools/include/linux/const.h index 81b8aae5a855..435ddd72d2c4 100644 --- a/tools/include/linux/const.h +++ b/tools/include/linux/const.h @@ -3,4 +3,12 @@ #include +/* + * This returns a constant expression while determining if an argument is + * a constant expression, most importantly without evaluating the argument. + * Glory to Martin Uecker + */ +#define __is_constexpr(x) \ + (sizeof(int) == sizeof(*(8 ? ((void *)((long)(x) * 0l)) : (int *)8))) + #endif /* _LINUX_CONST_H */ -- 2.30.2