[next,v2,2/5] minmax: Allow min()/max()/clamp() if the arguments have the same signedness.
Message ID | bf92800b0c5445e2b2ca8c88e1f5e90f@AcuMS.aculab.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp516450vqg; Fri, 28 Jul 2023 08:33:58 -0700 (PDT) X-Google-Smtp-Source: APBJJlFEDphYFq2pS2Dl71LlQZ9YScpWvAA5kKJsamzKiBkg/W74AvGDPATp2giUu/vS8WUdxItW X-Received: by 2002:a17:906:7691:b0:993:f744:d230 with SMTP id o17-20020a170906769100b00993f744d230mr2434545ejm.16.1690558438555; Fri, 28 Jul 2023 08:33:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690558438; cv=none; d=google.com; s=arc-20160816; b=i2r615gmJXV0N2fM4lbyHsyqWZ9aUgt1BNKmxT/fIzqKVqugulenn1Z0PT/+CF03DH lVwzACqkjFlxm4Y0GengnCZXpCeY8RS1ixHxEsNhftYRRiDxNRtffXyB773IGx3kUQcN //wZtgfylL1IBp1qaxTOPnx/E/OBj/2XJjjFlaMdWVae73Ikdp6pUOuz9CVW3zmD0n4k y/PSrui3vlJRm0+neEOEq5JKdmqJfZ8VY9+fU6S7eM/7FsPbz1UuIA0iuRXToYoSn3ZF tx6qCWqy1gvvXasW+c1dE02NgRh+G8fGctUVxg1kbPRY1magjS+nzX+gnJKHKuJu0ptN 8UpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:accept-language:in-reply-to:references:message-id:date :thread-index:thread-topic:subject:to:from; bh=+eCZ0vJa708GYuOeNm6lFZIYsO0mbJRmL360CrrMmcM=; fh=lQu0FQMQB/KijsOLYPBSZ4oPXp6gJVSgtvs90PKCM00=; b=xtmytz6BdjKSjH8cf6veX1vQQii8HeNMYry/rFQgfSukTZ0eq1Ejij85Sdd0YGyym5 juP3unz/BMMCWhujT0XNtpFbO9FANyl6u9LsgWx0f2PO54d9cIAueZS9+CulVThccUj9 pfo+f9KteesZRwzsbWq0E0FoOf1QdVBOoZObwAzRIv2B/SK+mn7OdJaQSXS3ah7T5tWq v8186ejNCjwz3ra8+z86FPDGfwYZHJAsx0HSvEccSp8UapBylm9ga+Qj677jqMPPpnh1 ndrvSYNoGurVam5AzeesChJg1EUjbc7SbzRd3ME1BdzcYLpM6jzwEan2jxaab7HmZN0k R7hw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id xo24-20020a170907bb9800b0099316721725si2863614ejc.1044.2023.07.28.08.33.27; Fri, 28 Jul 2023 08:33:58 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237158AbjG1Ovi convert rfc822-to-8bit (ORCPT <rfc822;hanasaki@gmail.com> + 99 others); Fri, 28 Jul 2023 10:51:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235782AbjG1Ovh (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 28 Jul 2023 10:51:37 -0400 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.85.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F093D3AAC for <linux-kernel@vger.kernel.org>; Fri, 28 Jul 2023 07:51:35 -0700 (PDT) Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with both STARTTLS and AUTH (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mta-164-1bOz5sKbO1qpSU8I0AgW3A-1; Fri, 28 Jul 2023 15:51:33 +0100 X-MC-Unique: 1bOz5sKbO1qpSU8I0AgW3A-1 Received: from AcuMS.Aculab.com (10.202.163.4) by AcuMS.aculab.com (10.202.163.4) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Fri, 28 Jul 2023 15:51:31 +0100 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Fri, 28 Jul 2023 15:51:31 +0100 From: David Laight <David.Laight@ACULAB.COM> To: "'linux-kernel@vger.kernel.org'" <linux-kernel@vger.kernel.org>, "'Andy Shevchenko'" <andriy.shevchenko@linux.intel.com>, 'Andrew Morton' <akpm@linux-foundation.org>, "'Matthew Wilcox (Oracle)'" <willy@infradead.org>, 'Christoph Hellwig' <hch@infradead.org>, "'Jason A. Donenfeld'" <Jason@zx2c4.com> Subject: [PATCH next v2 2/5] minmax: Allow min()/max()/clamp() if the arguments have the same signedness. Thread-Topic: [PATCH next v2 2/5] minmax: Allow min()/max()/clamp() if the arguments have the same signedness. Thread-Index: AdnBYvtzc0TxoNEXQSCZpxDmi1SwuQ== Date: Fri, 28 Jul 2023 14:51:31 +0000 Message-ID: <bf92800b0c5445e2b2ca8c88e1f5e90f@AcuMS.aculab.com> References: <bde3d2dc933848bbaceeb9b7102f6f4c@AcuMS.aculab.com> In-Reply-To: <bde3d2dc933848bbaceeb9b7102f6f4c@AcuMS.aculab.com> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772679005541512687 X-GMAIL-MSGID: 1772679005541512687 |
Series |
minmax: Relax type checks in min() and max().
|
|
Commit Message
David Laight
July 28, 2023, 2:51 p.m. UTC
The type-check in min()/max() is there to stop unexpected results if a
negative value gets converted to a large unsigned value.
However it also rejects 'unsigned int' v 'unsigned long' compares
which are common and never problematc.
Replace the 'same type' check with a 'same signedness' check.
The new test isn't itself a compile time error, so use static_assert()
to report the error and give a meaningful error message.
Due to the way builtin_choose_expr() works detecting the error in the
'non-constant' side (where static_assert() can be used) also detects
errors when the arguments are constant.
Signed-off-by: David Laight <david.laight@aculab.com>
---
Changes for v2:
- #include <linux/build_bug.h> to fix 'um' build.
This matches a separate commit from Andy.
- Do not delete __typecheck() - used outside this file.
- Use __builtin_choose_expr() in __clamp_once() to fix clang builds.
include/linux/minmax.h | 60 +++++++++++++++++++++---------------------
1 file changed, 30 insertions(+), 30 deletions(-)
Comments
Hi David, kernel test robot noticed the following build errors: [auto build test ERROR on akpm-mm/mm-everything] [also build test ERROR on linus/master crng-random/master v6.5-rc3 next-20230728] [cannot apply to next-20230728] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/David-Laight/minmax-Add-min_unsigned-a-b-and-max_unsigned-a-b/20230728-225439 base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything patch link: https://lore.kernel.org/r/bf92800b0c5445e2b2ca8c88e1f5e90f%40AcuMS.aculab.com patch subject: [PATCH next v2 2/5] minmax: Allow min()/max()/clamp() if the arguments have the same signedness. config: s390-randconfig-r044-20230728 (https://download.01.org/0day-ci/archive/20230729/202307290943.ODVeyeK6-lkp@intel.com/config) compiler: clang version 15.0.7 (https://github.com/llvm/llvm-project.git 8dfdcc7b7bf66834a761bd8de445840ef68e4d1a) reproduce: (https://download.01.org/0day-ci/archive/20230729/202307290943.ODVeyeK6-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202307290943.ODVeyeK6-lkp@intel.com/ All errors (new ones prefixed by >>): In file included from mm/percpu.c:73: In file included from include/linux/memblock.h:13: In file included from arch/s390/include/asm/dma.h:5: In file included from include/linux/io.h:13: In file included from arch/s390/include/asm/io.h:78: include/asm-generic/io.h:547:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] val = __raw_readb(PCI_IOBASE + addr); ~~~~~~~~~~ ^ include/asm-generic/io.h:560:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr)); ~~~~~~~~~~ ^ include/uapi/linux/byteorder/big_endian.h:37:59: note: expanded from macro '__le16_to_cpu' #define __le16_to_cpu(x) __swab16((__force __u16)(__le16)(x)) ^ include/uapi/linux/swab.h:102:54: note: expanded from macro '__swab16' #define __swab16(x) (__u16)__builtin_bswap16((__u16)(x)) ^ In file included from mm/percpu.c:73: In file included from include/linux/memblock.h:13: In file included from arch/s390/include/asm/dma.h:5: In file included from include/linux/io.h:13: In file included from arch/s390/include/asm/io.h:78: include/asm-generic/io.h:573:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr)); ~~~~~~~~~~ ^ include/uapi/linux/byteorder/big_endian.h:35:59: note: expanded from macro '__le32_to_cpu' #define __le32_to_cpu(x) __swab32((__force __u32)(__le32)(x)) ^ include/uapi/linux/swab.h:115:54: note: expanded from macro '__swab32' #define __swab32(x) (__u32)__builtin_bswap32((__u32)(x)) ^ In file included from mm/percpu.c:73: In file included from include/linux/memblock.h:13: In file included from arch/s390/include/asm/dma.h:5: In file included from include/linux/io.h:13: In file included from arch/s390/include/asm/io.h:78: include/asm-generic/io.h:584:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] __raw_writeb(value, PCI_IOBASE + addr); ~~~~~~~~~~ ^ include/asm-generic/io.h:594:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] __raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr); ~~~~~~~~~~ ^ include/asm-generic/io.h:604:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] __raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr); ~~~~~~~~~~ ^ include/asm-generic/io.h:692:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] readsb(PCI_IOBASE + addr, buffer, count); ~~~~~~~~~~ ^ include/asm-generic/io.h:700:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] readsw(PCI_IOBASE + addr, buffer, count); ~~~~~~~~~~ ^ include/asm-generic/io.h:708:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] readsl(PCI_IOBASE + addr, buffer, count); ~~~~~~~~~~ ^ include/asm-generic/io.h:717:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] writesb(PCI_IOBASE + addr, buffer, count); ~~~~~~~~~~ ^ include/asm-generic/io.h:726:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] writesw(PCI_IOBASE + addr, buffer, count); ~~~~~~~~~~ ^ include/asm-generic/io.h:735:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] writesl(PCI_IOBASE + addr, buffer, count); ~~~~~~~~~~ ^ >> mm/percpu.c:3102:10: error: static assertion expression is not an integral constant expression base = min(ptr, base); ^~~~~~~~~~~~~~ include/linux/minmax.h:67:19: note: expanded from macro 'min' #define min(x, y) __careful_cmp(min, x, y) ^~~~~~~~~~~~~~~~~~~~~~~~ include/linux/minmax.h:40:3: note: expanded from macro '__careful_cmp' __cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y))) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/minmax.h:33:17: note: expanded from macro '__cmp_once' static_assert(__types_ok(x, y), \ ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/minmax.h:23:2: note: expanded from macro '__types_ok' (is_signed_type(typeof(x)) == is_signed_type(typeof(y))) ^ include/linux/build_bug.h:77:50: note: expanded from macro 'static_assert' #define static_assert(expr, ...) __static_assert(expr, ##__VA_ARGS__, #expr) ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/build_bug.h:78:56: note: expanded from macro '__static_assert' #define __static_assert(expr, msg, ...) _Static_assert(expr, msg) ^~~~ mm/percpu.c:3102:10: note: cast that performs the conversions of a reinterpret_cast is not allowed in a constant expression include/linux/minmax.h:67:19: note: expanded from macro 'min' #define min(x, y) __careful_cmp(min, x, y) ^ include/linux/minmax.h:40:3: note: expanded from macro '__careful_cmp' __cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y))) ^ include/linux/minmax.h:33:17: note: expanded from macro '__cmp_once' static_assert(__types_ok(x, y), \ ^ include/linux/minmax.h:23:3: note: expanded from macro '__types_ok' (is_signed_type(typeof(x)) == is_signed_type(typeof(y))) ^ include/linux/compiler.h:237:32: note: expanded from macro 'is_signed_type' #define is_signed_type(type) (((type)(-1)) < (__force type)1) ^ 12 warnings and 1 error generated. -- In file included from mm/kmemleak.c:86: In file included from include/linux/memblock.h:13: In file included from arch/s390/include/asm/dma.h:5: In file included from include/linux/io.h:13: In file included from arch/s390/include/asm/io.h:78: include/asm-generic/io.h:547:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] val = __raw_readb(PCI_IOBASE + addr); ~~~~~~~~~~ ^ include/asm-generic/io.h:560:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr)); ~~~~~~~~~~ ^ include/uapi/linux/byteorder/big_endian.h:37:59: note: expanded from macro '__le16_to_cpu' #define __le16_to_cpu(x) __swab16((__force __u16)(__le16)(x)) ^ include/uapi/linux/swab.h:102:54: note: expanded from macro '__swab16' #define __swab16(x) (__u16)__builtin_bswap16((__u16)(x)) ^ In file included from mm/kmemleak.c:86: In file included from include/linux/memblock.h:13: In file included from arch/s390/include/asm/dma.h:5: In file included from include/linux/io.h:13: In file included from arch/s390/include/asm/io.h:78: include/asm-generic/io.h:573:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr)); ~~~~~~~~~~ ^ include/uapi/linux/byteorder/big_endian.h:35:59: note: expanded from macro '__le32_to_cpu' #define __le32_to_cpu(x) __swab32((__force __u32)(__le32)(x)) ^ include/uapi/linux/swab.h:115:54: note: expanded from macro '__swab32' #define __swab32(x) (__u32)__builtin_bswap32((__u32)(x)) ^ In file included from mm/kmemleak.c:86: In file included from include/linux/memblock.h:13: In file included from arch/s390/include/asm/dma.h:5: In file included from include/linux/io.h:13: In file included from arch/s390/include/asm/io.h:78: include/asm-generic/io.h:584:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] __raw_writeb(value, PCI_IOBASE + addr); ~~~~~~~~~~ ^ include/asm-generic/io.h:594:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] __raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr); ~~~~~~~~~~ ^ include/asm-generic/io.h:604:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] __raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr); ~~~~~~~~~~ ^ include/asm-generic/io.h:692:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] readsb(PCI_IOBASE + addr, buffer, count); ~~~~~~~~~~ ^ include/asm-generic/io.h:700:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] readsw(PCI_IOBASE + addr, buffer, count); ~~~~~~~~~~ ^ include/asm-generic/io.h:708:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] readsl(PCI_IOBASE + addr, buffer, count); ~~~~~~~~~~ ^ include/asm-generic/io.h:717:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] writesb(PCI_IOBASE + addr, buffer, count); ~~~~~~~~~~ ^ include/asm-generic/io.h:726:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] writesw(PCI_IOBASE + addr, buffer, count); ~~~~~~~~~~ ^ include/asm-generic/io.h:735:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] writesl(PCI_IOBASE + addr, buffer, count); ~~~~~~~~~~ ^ >> mm/kmemleak.c:1389:10: error: static assertion expression is not an integral constant expression next = min(start + MAX_SCAN_SIZE, end); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/minmax.h:67:19: note: expanded from macro 'min' #define min(x, y) __careful_cmp(min, x, y) ^~~~~~~~~~~~~~~~~~~~~~~~ include/linux/minmax.h:40:3: note: expanded from macro '__careful_cmp' __cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y))) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/minmax.h:33:17: note: expanded from macro '__cmp_once' static_assert(__types_ok(x, y), \ ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/minmax.h:23:2: note: expanded from macro '__types_ok' (is_signed_type(typeof(x)) == is_signed_type(typeof(y))) ^ include/linux/build_bug.h:77:50: note: expanded from macro 'static_assert' #define static_assert(expr, ...) __static_assert(expr, ##__VA_ARGS__, #expr) ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/build_bug.h:78:56: note: expanded from macro '__static_assert' #define __static_assert(expr, msg, ...) _Static_assert(expr, msg) ^~~~ mm/kmemleak.c:1389:10: note: cast that performs the conversions of a reinterpret_cast is not allowed in a constant expression include/linux/minmax.h:67:19: note: expanded from macro 'min' #define min(x, y) __careful_cmp(min, x, y) ^ include/linux/minmax.h:40:3: note: expanded from macro '__careful_cmp' __cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y))) ^ include/linux/minmax.h:33:17: note: expanded from macro '__cmp_once' static_assert(__types_ok(x, y), \ ^ include/linux/minmax.h:23:3: note: expanded from macro '__types_ok' (is_signed_type(typeof(x)) == is_signed_type(typeof(y))) ^ include/linux/compiler.h:237:32: note: expanded from macro 'is_signed_type' #define is_signed_type(type) (((type)(-1)) < (__force type)1) ^ mm/kmemleak.c:1429:11: error: static assertion expression is not an integral constant expression next = min(start + MAX_SCAN_SIZE, end); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/minmax.h:67:19: note: expanded from macro 'min' #define min(x, y) __careful_cmp(min, x, y) ^~~~~~~~~~~~~~~~~~~~~~~~ include/linux/minmax.h:40:3: note: expanded from macro '__careful_cmp' __cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y))) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/minmax.h:33:17: note: expanded from macro '__cmp_once' static_assert(__types_ok(x, y), \ ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/minmax.h:23:2: note: expanded from macro '__types_ok' (is_signed_type(typeof(x)) == is_signed_type(typeof(y))) ^ include/linux/build_bug.h:77:50: note: expanded from macro 'static_assert' #define static_assert(expr, ...) __static_assert(expr, ##__VA_ARGS__, #expr) ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/build_bug.h:78:56: note: expanded from macro '__static_assert' #define __static_assert(expr, msg, ...) _Static_assert(expr, msg) ^~~~ mm/kmemleak.c:1429:11: note: cast that performs the conversions of a reinterpret_cast is not allowed in a constant expression include/linux/minmax.h:67:19: note: expanded from macro 'min' #define min(x, y) __careful_cmp(min, x, y) ^ include/linux/minmax.h:40:3: note: expanded from macro '__careful_cmp' __cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y))) ^ include/linux/minmax.h:33:17: note: expanded from macro '__cmp_once' static_assert(__types_ok(x, y), \ ^ include/linux/minmax.h:23:3: note: expanded from macro '__types_ok' (is_signed_type(typeof(x)) == is_signed_type(typeof(y))) ^ include/linux/compiler.h:237:32: note: expanded from macro 'is_signed_type' #define is_signed_type(type) (((type)(-1)) < (__force type)1) ^ 12 warnings and 2 errors generated. -- In file included from crypto/skcipher.c:15: In file included from include/crypto/scatterwalk.h:18: In file included from include/linux/scatterlist.h:9: In file included from arch/s390/include/asm/io.h:78: include/asm-generic/io.h:547:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] val = __raw_readb(PCI_IOBASE + addr); ~~~~~~~~~~ ^ include/asm-generic/io.h:560:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr)); ~~~~~~~~~~ ^ include/uapi/linux/byteorder/big_endian.h:37:59: note: expanded from macro '__le16_to_cpu' #define __le16_to_cpu(x) __swab16((__force __u16)(__le16)(x)) ^ include/uapi/linux/swab.h:102:54: note: expanded from macro '__swab16' #define __swab16(x) (__u16)__builtin_bswap16((__u16)(x)) ^ In file included from crypto/skcipher.c:15: In file included from include/crypto/scatterwalk.h:18: In file included from include/linux/scatterlist.h:9: In file included from arch/s390/include/asm/io.h:78: include/asm-generic/io.h:573:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr)); ~~~~~~~~~~ ^ include/uapi/linux/byteorder/big_endian.h:35:59: note: expanded from macro '__le32_to_cpu' #define __le32_to_cpu(x) __swab32((__force __u32)(__le32)(x)) ^ include/uapi/linux/swab.h:115:54: note: expanded from macro '__swab32' #define __swab32(x) (__u32)__builtin_bswap32((__u32)(x)) ^ In file included from crypto/skcipher.c:15: In file included from include/crypto/scatterwalk.h:18: In file included from include/linux/scatterlist.h:9: In file included from arch/s390/include/asm/io.h:78: include/asm-generic/io.h:584:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] __raw_writeb(value, PCI_IOBASE + addr); ~~~~~~~~~~ ^ include/asm-generic/io.h:594:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] __raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr); ~~~~~~~~~~ ^ include/asm-generic/io.h:604:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] __raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr); ~~~~~~~~~~ ^ include/asm-generic/io.h:692:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] readsb(PCI_IOBASE + addr, buffer, count); ~~~~~~~~~~ ^ include/asm-generic/io.h:700:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] readsw(PCI_IOBASE + addr, buffer, count); ~~~~~~~~~~ ^ include/asm-generic/io.h:708:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] readsl(PCI_IOBASE + addr, buffer, count); ~~~~~~~~~~ ^ include/asm-generic/io.h:717:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] writesb(PCI_IOBASE + addr, buffer, count); ~~~~~~~~~~ ^ include/asm-generic/io.h:726:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] writesw(PCI_IOBASE + addr, buffer, count); ~~~~~~~~~~ ^ include/asm-generic/io.h:735:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] writesl(PCI_IOBASE + addr, buffer, count); ~~~~~~~~~~ ^ >> crypto/skcipher.c:80:9: error: static assertion expression is not an integral constant expression return max(start, end_page); ^~~~~~~~~~~~~~~~~~~~ include/linux/minmax.h:74:19: note: expanded from macro 'max' #define max(x, y) __careful_cmp(max, x, y) ^~~~~~~~~~~~~~~~~~~~~~~~ include/linux/minmax.h:40:3: note: expanded from macro '__careful_cmp' __cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y))) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/minmax.h:33:17: note: expanded from macro '__cmp_once' static_assert(__types_ok(x, y), \ ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/minmax.h:23:2: note: expanded from macro '__types_ok' (is_signed_type(typeof(x)) == is_signed_type(typeof(y))) ^ include/linux/build_bug.h:77:50: note: expanded from macro 'static_assert' #define static_assert(expr, ...) __static_assert(expr, ##__VA_ARGS__, #expr) ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/build_bug.h:78:56: note: expanded from macro '__static_assert' #define __static_assert(expr, msg, ...) _Static_assert(expr, msg) ^~~~ crypto/skcipher.c:80:9: note: cast that performs the conversions of a reinterpret_cast is not allowed in a constant expression include/linux/minmax.h:74:19: note: expanded from macro 'max' #define max(x, y) __careful_cmp(max, x, y) ^ include/linux/minmax.h:40:3: note: expanded from macro '__careful_cmp' __cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y))) ^ include/linux/minmax.h:33:17: note: expanded from macro '__cmp_once' static_assert(__types_ok(x, y), \ ^ include/linux/minmax.h:23:3: note: expanded from macro '__types_ok' (is_signed_type(typeof(x)) == is_signed_type(typeof(y))) ^ include/linux/compiler.h:237:32: note: expanded from macro 'is_signed_type' #define is_signed_type(type) (((type)(-1)) < (__force type)1) ^ 12 warnings and 1 error generated. .. vim +3102 mm/percpu.c 3c9a024fde58b08 Tejun Heo 2010-09-09 3022 3c9a024fde58b08 Tejun Heo 2010-09-09 3023 #if defined(BUILD_EMBED_FIRST_CHUNK) 66c3a75772247c3 Tejun Heo 2009-03-10 3024 /** 66c3a75772247c3 Tejun Heo 2009-03-10 3025 * pcpu_embed_first_chunk - embed the first percpu chunk into bootmem 66c3a75772247c3 Tejun Heo 2009-03-10 3026 * @reserved_size: the size of reserved percpu area in bytes 4ba6ce250e406b2 Tejun Heo 2010-06-27 3027 * @dyn_size: minimum free size for dynamic allocation in bytes c8826dd538602d7 Tejun Heo 2009-08-14 3028 * @atom_size: allocation atom size c8826dd538602d7 Tejun Heo 2009-08-14 3029 * @cpu_distance_fn: callback to determine distance between cpus, optional 1ca3fb3abd2b615 Kefeng Wang 2022-01-19 3030 * @cpu_to_nd_fn: callback to convert cpu to it's node, optional 66c3a75772247c3 Tejun Heo 2009-03-10 3031 * 66c3a75772247c3 Tejun Heo 2009-03-10 3032 * This is a helper to ease setting up embedded first percpu chunk and 66c3a75772247c3 Tejun Heo 2009-03-10 3033 * can be called where pcpu_setup_first_chunk() is expected. 66c3a75772247c3 Tejun Heo 2009-03-10 3034 * 66c3a75772247c3 Tejun Heo 2009-03-10 3035 * If this function is used to setup the first chunk, it is allocated 23f917169ef157a Kefeng Wang 2022-01-19 3036 * by calling pcpu_fc_alloc and used as-is without being mapped into c8826dd538602d7 Tejun Heo 2009-08-14 3037 * vmalloc area. Allocations are always whole multiples of @atom_size c8826dd538602d7 Tejun Heo 2009-08-14 3038 * aligned to @atom_size. c8826dd538602d7 Tejun Heo 2009-08-14 3039 * c8826dd538602d7 Tejun Heo 2009-08-14 3040 * This enables the first chunk to piggy back on the linear physical c8826dd538602d7 Tejun Heo 2009-08-14 3041 * mapping which often uses larger page size. Please note that this c8826dd538602d7 Tejun Heo 2009-08-14 3042 * can result in very sparse cpu->unit mapping on NUMA machines thus c8826dd538602d7 Tejun Heo 2009-08-14 3043 * requiring large vmalloc address space. Don't use this allocator if c8826dd538602d7 Tejun Heo 2009-08-14 3044 * vmalloc space is not orders of magnitude larger than distances c8826dd538602d7 Tejun Heo 2009-08-14 3045 * between node memory addresses (ie. 32bit NUMA machines). 66c3a75772247c3 Tejun Heo 2009-03-10 3046 * 4ba6ce250e406b2 Tejun Heo 2010-06-27 3047 * @dyn_size specifies the minimum dynamic area size. 66c3a75772247c3 Tejun Heo 2009-03-10 3048 * 66c3a75772247c3 Tejun Heo 2009-03-10 3049 * If the needed size is smaller than the minimum or specified unit 23f917169ef157a Kefeng Wang 2022-01-19 3050 * size, the leftover is returned using pcpu_fc_free. 66c3a75772247c3 Tejun Heo 2009-03-10 3051 * 66c3a75772247c3 Tejun Heo 2009-03-10 3052 * RETURNS: fb435d5233f8b6f Tejun Heo 2009-08-14 3053 * 0 on success, -errno on failure. 66c3a75772247c3 Tejun Heo 2009-03-10 3054 */ 4ba6ce250e406b2 Tejun Heo 2010-06-27 3055 int __init pcpu_embed_first_chunk(size_t reserved_size, size_t dyn_size, c8826dd538602d7 Tejun Heo 2009-08-14 3056 size_t atom_size, c8826dd538602d7 Tejun Heo 2009-08-14 3057 pcpu_fc_cpu_distance_fn_t cpu_distance_fn, 23f917169ef157a Kefeng Wang 2022-01-19 3058 pcpu_fc_cpu_to_node_fn_t cpu_to_nd_fn) 66c3a75772247c3 Tejun Heo 2009-03-10 3059 { c8826dd538602d7 Tejun Heo 2009-08-14 3060 void *base = (void *)ULONG_MAX; c8826dd538602d7 Tejun Heo 2009-08-14 3061 void **areas = NULL; fd1e8a1fe2b54df Tejun Heo 2009-08-14 3062 struct pcpu_alloc_info *ai; 93c76b6b2faaad7 zijun_hu 2016-10-05 3063 size_t size_sum, areas_size; 93c76b6b2faaad7 zijun_hu 2016-10-05 3064 unsigned long max_distance; 163fa23435cc9c7 Kefeng Wang 2019-07-03 3065 int group, i, highest_group, rc = 0; 66c3a75772247c3 Tejun Heo 2009-03-10 3066 c8826dd538602d7 Tejun Heo 2009-08-14 3067 ai = pcpu_build_alloc_info(reserved_size, dyn_size, atom_size, c8826dd538602d7 Tejun Heo 2009-08-14 3068 cpu_distance_fn); fd1e8a1fe2b54df Tejun Heo 2009-08-14 3069 if (IS_ERR(ai)) fd1e8a1fe2b54df Tejun Heo 2009-08-14 3070 return PTR_ERR(ai); 66c3a75772247c3 Tejun Heo 2009-03-10 3071 fd1e8a1fe2b54df Tejun Heo 2009-08-14 3072 size_sum = ai->static_size + ai->reserved_size + ai->dyn_size; c8826dd538602d7 Tejun Heo 2009-08-14 3073 areas_size = PFN_ALIGN(ai->nr_groups * sizeof(void *)); fa8a7094ba1679b Tejun Heo 2009-06-22 3074 26fb3dae0a1ec78 Mike Rapoport 2019-03-11 3075 areas = memblock_alloc(areas_size, SMP_CACHE_BYTES); c8826dd538602d7 Tejun Heo 2009-08-14 3076 if (!areas) { fb435d5233f8b6f Tejun Heo 2009-08-14 3077 rc = -ENOMEM; c8826dd538602d7 Tejun Heo 2009-08-14 3078 goto out_free; fa8a7094ba1679b Tejun Heo 2009-06-22 3079 } 66c3a75772247c3 Tejun Heo 2009-03-10 3080 9b7396624a7b503 zijun_hu 2016-10-05 3081 /* allocate, copy and determine base address & max_distance */ 9b7396624a7b503 zijun_hu 2016-10-05 3082 highest_group = 0; c8826dd538602d7 Tejun Heo 2009-08-14 3083 for (group = 0; group < ai->nr_groups; group++) { c8826dd538602d7 Tejun Heo 2009-08-14 3084 struct pcpu_group_info *gi = &ai->groups[group]; c8826dd538602d7 Tejun Heo 2009-08-14 3085 unsigned int cpu = NR_CPUS; c8826dd538602d7 Tejun Heo 2009-08-14 3086 void *ptr; c8826dd538602d7 Tejun Heo 2009-08-14 3087 c8826dd538602d7 Tejun Heo 2009-08-14 3088 for (i = 0; i < gi->nr_units && cpu == NR_CPUS; i++) c8826dd538602d7 Tejun Heo 2009-08-14 3089 cpu = gi->cpu_map[i]; c8826dd538602d7 Tejun Heo 2009-08-14 3090 BUG_ON(cpu == NR_CPUS); c8826dd538602d7 Tejun Heo 2009-08-14 3091 c8826dd538602d7 Tejun Heo 2009-08-14 3092 /* allocate space for the whole group */ 23f917169ef157a Kefeng Wang 2022-01-19 3093 ptr = pcpu_fc_alloc(cpu, gi->nr_units * ai->unit_size, atom_size, cpu_to_nd_fn); c8826dd538602d7 Tejun Heo 2009-08-14 3094 if (!ptr) { c8826dd538602d7 Tejun Heo 2009-08-14 3095 rc = -ENOMEM; c8826dd538602d7 Tejun Heo 2009-08-14 3096 goto out_free_areas; c8826dd538602d7 Tejun Heo 2009-08-14 3097 } f528f0b8e53d73b Catalin Marinas 2011-09-26 3098 /* kmemleak tracks the percpu allocations separately */ a317ebccaa36099 Patrick Wang 2022-07-05 3099 kmemleak_ignore_phys(__pa(ptr)); c8826dd538602d7 Tejun Heo 2009-08-14 3100 areas[group] = ptr; c8826dd538602d7 Tejun Heo 2009-08-14 3101 c8826dd538602d7 Tejun Heo 2009-08-14 @3102 base = min(ptr, base); 9b7396624a7b503 zijun_hu 2016-10-05 3103 if (ptr > areas[highest_group]) 9b7396624a7b503 zijun_hu 2016-10-05 3104 highest_group = group; 9b7396624a7b503 zijun_hu 2016-10-05 3105 } 9b7396624a7b503 zijun_hu 2016-10-05 3106 max_distance = areas[highest_group] - base; 9b7396624a7b503 zijun_hu 2016-10-05 3107 max_distance += ai->unit_size * ai->groups[highest_group].nr_units; 9b7396624a7b503 zijun_hu 2016-10-05 3108 9b7396624a7b503 zijun_hu 2016-10-05 3109 /* warn if maximum distance is further than 75% of vmalloc space */ 9b7396624a7b503 zijun_hu 2016-10-05 3110 if (max_distance > VMALLOC_TOTAL * 3 / 4) { 9b7396624a7b503 zijun_hu 2016-10-05 3111 pr_warn("max_distance=0x%lx too large for vmalloc space 0x%lx\n", 9b7396624a7b503 zijun_hu 2016-10-05 3112 max_distance, VMALLOC_TOTAL); 9b7396624a7b503 zijun_hu 2016-10-05 3113 #ifdef CONFIG_NEED_PER_CPU_PAGE_FIRST_CHUNK 9b7396624a7b503 zijun_hu 2016-10-05 3114 /* and fail if we have fallback */ 9b7396624a7b503 zijun_hu 2016-10-05 3115 rc = -EINVAL; 9b7396624a7b503 zijun_hu 2016-10-05 3116 goto out_free_areas; 9b7396624a7b503 zijun_hu 2016-10-05 3117 #endif 42b64281453249d Tejun Heo 2012-04-27 3118 } 42b64281453249d Tejun Heo 2012-04-27 3119 42b64281453249d Tejun Heo 2012-04-27 3120 /* 42b64281453249d Tejun Heo 2012-04-27 3121 * Copy data and free unused parts. This should happen after all 42b64281453249d Tejun Heo 2012-04-27 3122 * allocations are complete; otherwise, we may end up with 42b64281453249d Tejun Heo 2012-04-27 3123 * overlapping groups. 42b64281453249d Tejun Heo 2012-04-27 3124 */ 42b64281453249d Tejun Heo 2012-04-27 3125 for (group = 0; group < ai->nr_groups; group++) { 42b64281453249d Tejun Heo 2012-04-27 3126 struct pcpu_group_info *gi = &ai->groups[group]; 42b64281453249d Tejun Heo 2012-04-27 3127 void *ptr = areas[group]; 66c3a75772247c3 Tejun Heo 2009-03-10 3128 c8826dd538602d7 Tejun Heo 2009-08-14 3129 for (i = 0; i < gi->nr_units; i++, ptr += ai->unit_size) { c8826dd538602d7 Tejun Heo 2009-08-14 3130 if (gi->cpu_map[i] == NR_CPUS) { c8826dd538602d7 Tejun Heo 2009-08-14 3131 /* unused unit, free whole */ 23f917169ef157a Kefeng Wang 2022-01-19 3132 pcpu_fc_free(ptr, ai->unit_size); c8826dd538602d7 Tejun Heo 2009-08-14 3133 continue; c8826dd538602d7 Tejun Heo 2009-08-14 3134 } c8826dd538602d7 Tejun Heo 2009-08-14 3135 /* copy and return the unused part */ fd1e8a1fe2b54df Tejun Heo 2009-08-14 3136 memcpy(ptr, __per_cpu_load, ai->static_size); 23f917169ef157a Kefeng Wang 2022-01-19 3137 pcpu_fc_free(ptr + size_sum, ai->unit_size - size_sum); c8826dd538602d7 Tejun Heo 2009-08-14 3138 } 66c3a75772247c3 Tejun Heo 2009-03-10 3139 } 66c3a75772247c3 Tejun Heo 2009-03-10 3140 c8826dd538602d7 Tejun Heo 2009-08-14 3141 /* base address is now known, determine group base offsets */ 6ea529a2037ce66 Tejun Heo 2009-09-24 3142 for (group = 0; group < ai->nr_groups; group++) { c8826dd538602d7 Tejun Heo 2009-08-14 3143 ai->groups[group].base_offset = areas[group] - base; 6ea529a2037ce66 Tejun Heo 2009-09-24 3144 } c8826dd538602d7 Tejun Heo 2009-08-14 3145 00206a69ee32f03 Matteo Croce 2019-03-18 3146 pr_info("Embedded %zu pages/cpu s%zu r%zu d%zu u%zu\n", 00206a69ee32f03 Matteo Croce 2019-03-18 3147 PFN_DOWN(size_sum), ai->static_size, ai->reserved_size, fd1e8a1fe2b54df Tejun Heo 2009-08-14 3148 ai->dyn_size, ai->unit_size); 66c3a75772247c3 Tejun Heo 2009-03-10 3149 163fa23435cc9c7 Kefeng Wang 2019-07-03 3150 pcpu_setup_first_chunk(ai, base); c8826dd538602d7 Tejun Heo 2009-08-14 3151 goto out_free; c8826dd538602d7 Tejun Heo 2009-08-14 3152 c8826dd538602d7 Tejun Heo 2009-08-14 3153 out_free_areas: c8826dd538602d7 Tejun Heo 2009-08-14 3154 for (group = 0; group < ai->nr_groups; group++) f851c8d8583891a Michael Holzheu 2013-09-17 3155 if (areas[group]) 23f917169ef157a Kefeng Wang 2022-01-19 3156 pcpu_fc_free(areas[group], c8826dd538602d7 Tejun Heo 2009-08-14 3157 ai->groups[group].nr_units * ai->unit_size); c8826dd538602d7 Tejun Heo 2009-08-14 3158 out_free: fd1e8a1fe2b54df Tejun Heo 2009-08-14 3159 pcpu_free_alloc_info(ai); c8826dd538602d7 Tejun Heo 2009-08-14 3160 if (areas) 4421cca0a3e4833 Mike Rapoport 2021-11-05 3161 memblock_free(areas, areas_size); fb435d5233f8b6f Tejun Heo 2009-08-14 3162 return rc; fa8a7094ba1679b Tejun Heo 2009-06-22 3163 } 3c9a024fde58b08 Tejun Heo 2010-09-09 3164 #endif /* BUILD_EMBED_FIRST_CHUNK */ d4b95f80399471e Tejun Heo 2009-07-04 3165
From: kernel test robot > Sent: 29 July 2023 03:01 > > kernel test robot noticed the following build errors: > ...) > compiler: clang version 15.0.7 (https://github.com/llvm/llvm-project.git > 8dfdcc7b7bf66834a761bd8de445840ef68e4d1a) > reproduce: (https://download.01.org/0day-ci/archive/20230729/202307290943.ODVeyeK6- > lkp@intel.com/reproduce) > ... > >> mm/percpu.c:3102:10: error: static assertion expression is not an integral constant expression > base = min(ptr, base); > ^~~~~~~~~~~~~~ ... ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~ > include/linux/minmax.h:23:2: note: expanded from macro '__types_ok' > (is_signed_type(typeof(x)) == is_signed_type(typeof(y))) > ^ ... > mm/percpu.c:3102:10: note: cast that performs the conversions of a reinterpret_cast is not allowed > in a constant expression That is a C++ error that seems to have crept into C. The relevant definition is: #define is_signed_type(type) (((type)(-1)) < (type)1) This seems to have been fixed in clang 16.0.0. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
On Sun, Jul 30, 2023 at 02:55:50PM +0000, David Laight wrote: > From: kernel test robot > > Sent: 29 July 2023 03:01 > > > > kernel test robot noticed the following build errors: > > > ...) > > compiler: clang version 15.0.7 (https://github.com/llvm/llvm-project.git > > 8dfdcc7b7bf66834a761bd8de445840ef68e4d1a) > > reproduce: (https://download.01.org/0day-ci/archive/20230729/202307290943.ODVeyeK6- > > lkp@intel.com/reproduce) > > > ... > > >> mm/percpu.c:3102:10: error: static assertion expression is not an integral constant expression > > base = min(ptr, base); > > ^~~~~~~~~~~~~~ > ... ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~ > > include/linux/minmax.h:23:2: note: expanded from macro '__types_ok' > > (is_signed_type(typeof(x)) == is_signed_type(typeof(y))) > > ^ > ... > > mm/percpu.c:3102:10: note: cast that performs the conversions of a reinterpret_cast is not allowed > > in a constant expression > > That is a C++ error that seems to have crept into C. > The relevant definition is: > > #define is_signed_type(type) (((type)(-1)) < (type)1) > > This seems to have been fixed in clang 16.0.0. Indeed, it looks like https://github.com/llvm/llvm-project/commit/a181de452df311d7647329120d05f4eb9c158b6c fixed this as a result of the discussion at https://github.com/llvm/llvm-project/issues/57687, which certainly makes sense. Cheers, Nathan
From: Nathan Chancellor > Sent: 30 July 2023 18:06 > > On Sun, Jul 30, 2023 at 02:55:50PM +0000, David Laight wrote: > > From: kernel test robot > > > Sent: 29 July 2023 03:01 > > > > > > kernel test robot noticed the following build errors: > > > > > ...) > > > compiler: clang version 15.0.7 (https://github.com/llvm/llvm-project.git > > > 8dfdcc7b7bf66834a761bd8de445840ef68e4d1a) > > > reproduce: (https://download.01.org/0day-ci/archive/20230729/202307290943.ODVeyeK6- > > > lkp@intel.com/reproduce) > > > > > ... > > > >> mm/percpu.c:3102:10: error: static assertion expression is not an integral constant expression > > > base = min(ptr, base); > > > ^~~~~~~~~~~~~~ > > ... ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~ > > > include/linux/minmax.h:23:2: note: expanded from macro '__types_ok' > > > (is_signed_type(typeof(x)) == is_signed_type(typeof(y))) > > > ^ > > ... > > > mm/percpu.c:3102:10: note: cast that performs the conversions of a reinterpret_cast is not allowed > > > in a constant expression > > > > That is a C++ error that seems to have crept into C. > > The relevant definition is: > > > > #define is_signed_type(type) (((type)(-1)) < (type)1) > > > > This seems to have been fixed in clang 16.0.0. > > Indeed, it looks like > > https://github.com/llvm/llvm-project/commit/a181de452df311d7647329120d05f4eb9c158b6c > > fixed this as a result of the discussion at > > https://github.com/llvm/llvm-project/issues/57687, which certainly makes > sense. Annoyingly it also isn't a 'proper' compile time constant for pointers. Wrapping as: __builtin_choose_expr(__is_constexpr(is_signed(type(x)), is_signed_type(x), 0) fixes it for old clang and is also needed to fix the >= 0 check in 5/5. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
Hi David,
kernel test robot noticed the following build errors:
[auto build test ERROR on akpm-mm/mm-everything]
[also build test ERROR on linus/master crng-random/master v6.5-rc4 next-20230731]
[cannot apply to next-20230728]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/David-Laight/minmax-Add-min_unsigned-a-b-and-max_unsigned-a-b/20230728-225439
base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
patch link: https://lore.kernel.org/r/bf92800b0c5445e2b2ca8c88e1f5e90f%40AcuMS.aculab.com
patch subject: [PATCH next v2 2/5] minmax: Allow min()/max()/clamp() if the arguments have the same signedness.
config: powerpc-mpc5200_defconfig (https://download.01.org/0day-ci/archive/20230801/202308010559.SEtfkzQU-lkp@intel.com/config)
compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project.git f28c006a5895fc0e329fe15fead81e37457cb1d1)
reproduce: (https://download.01.org/0day-ci/archive/20230801/202308010559.SEtfkzQU-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202308010559.SEtfkzQU-lkp@intel.com/
All errors (new ones prefixed by >>):
^
arch/powerpc/include/asm/io.h:610:56: note: expanded from macro '__do_insw'
#define __do_insw(p, b, n) readsw((PCI_IO_ADDR)_IO_BASE+(p), (b), (n))
~~~~~~~~~~~~~~~~~~~~~^
In file included from drivers/gpu/drm/drm_modes.c:35:
In file included from include/linux/fb.h:6:
In file included from include/linux/kgdb.h:19:
In file included from include/linux/kprobes.h:28:
In file included from include/linux/ftrace.h:10:
In file included from include/linux/trace_recursion.h:5:
In file included from include/linux/interrupt.h:11:
In file included from include/linux/hardirq.h:11:
In file included from arch/powerpc/include/asm/hardirq.h:6:
In file included from include/linux/irq.h:20:
In file included from include/linux/io.h:13:
In file included from arch/powerpc/include/asm/io.h:672:
arch/powerpc/include/asm/io-defs.h:47:1: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
DEF_PCI_AC_NORET(insl, (unsigned long p, void *b, unsigned long c),
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
arch/powerpc/include/asm/io.h:669:3: note: expanded from macro 'DEF_PCI_AC_NORET'
__do_##name al; \
^~~~~~~~~~~~~~
<scratch space>:101:1: note: expanded from here
__do_insl
^
arch/powerpc/include/asm/io.h:611:56: note: expanded from macro '__do_insl'
#define __do_insl(p, b, n) readsl((PCI_IO_ADDR)_IO_BASE+(p), (b), (n))
~~~~~~~~~~~~~~~~~~~~~^
In file included from drivers/gpu/drm/drm_modes.c:35:
In file included from include/linux/fb.h:6:
In file included from include/linux/kgdb.h:19:
In file included from include/linux/kprobes.h:28:
In file included from include/linux/ftrace.h:10:
In file included from include/linux/trace_recursion.h:5:
In file included from include/linux/interrupt.h:11:
In file included from include/linux/hardirq.h:11:
In file included from arch/powerpc/include/asm/hardirq.h:6:
In file included from include/linux/irq.h:20:
In file included from include/linux/io.h:13:
In file included from arch/powerpc/include/asm/io.h:672:
arch/powerpc/include/asm/io-defs.h:49:1: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
DEF_PCI_AC_NORET(outsb, (unsigned long p, const void *b, unsigned long c),
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
arch/powerpc/include/asm/io.h:669:3: note: expanded from macro 'DEF_PCI_AC_NORET'
__do_##name al; \
^~~~~~~~~~~~~~
<scratch space>:103:1: note: expanded from here
__do_outsb
^
arch/powerpc/include/asm/io.h:612:58: note: expanded from macro '__do_outsb'
#define __do_outsb(p, b, n) writesb((PCI_IO_ADDR)_IO_BASE+(p),(b),(n))
~~~~~~~~~~~~~~~~~~~~~^
In file included from drivers/gpu/drm/drm_modes.c:35:
In file included from include/linux/fb.h:6:
In file included from include/linux/kgdb.h:19:
In file included from include/linux/kprobes.h:28:
In file included from include/linux/ftrace.h:10:
In file included from include/linux/trace_recursion.h:5:
In file included from include/linux/interrupt.h:11:
In file included from include/linux/hardirq.h:11:
In file included from arch/powerpc/include/asm/hardirq.h:6:
In file included from include/linux/irq.h:20:
In file included from include/linux/io.h:13:
In file included from arch/powerpc/include/asm/io.h:672:
arch/powerpc/include/asm/io-defs.h:51:1: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
DEF_PCI_AC_NORET(outsw, (unsigned long p, const void *b, unsigned long c),
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
arch/powerpc/include/asm/io.h:669:3: note: expanded from macro 'DEF_PCI_AC_NORET'
__do_##name al; \
^~~~~~~~~~~~~~
<scratch space>:105:1: note: expanded from here
__do_outsw
^
arch/powerpc/include/asm/io.h:613:58: note: expanded from macro '__do_outsw'
#define __do_outsw(p, b, n) writesw((PCI_IO_ADDR)_IO_BASE+(p),(b),(n))
~~~~~~~~~~~~~~~~~~~~~^
In file included from drivers/gpu/drm/drm_modes.c:35:
In file included from include/linux/fb.h:6:
In file included from include/linux/kgdb.h:19:
In file included from include/linux/kprobes.h:28:
In file included from include/linux/ftrace.h:10:
In file included from include/linux/trace_recursion.h:5:
In file included from include/linux/interrupt.h:11:
In file included from include/linux/hardirq.h:11:
In file included from arch/powerpc/include/asm/hardirq.h:6:
In file included from include/linux/irq.h:20:
In file included from include/linux/io.h:13:
In file included from arch/powerpc/include/asm/io.h:672:
arch/powerpc/include/asm/io-defs.h:53:1: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
DEF_PCI_AC_NORET(outsl, (unsigned long p, const void *b, unsigned long c),
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
arch/powerpc/include/asm/io.h:669:3: note: expanded from macro 'DEF_PCI_AC_NORET'
__do_##name al; \
^~~~~~~~~~~~~~
<scratch space>:107:1: note: expanded from here
__do_outsl
^
arch/powerpc/include/asm/io.h:614:58: note: expanded from macro '__do_outsl'
#define __do_outsl(p, b, n) writesl((PCI_IO_ADDR)_IO_BASE+(p),(b),(n))
~~~~~~~~~~~~~~~~~~~~~^
>> drivers/gpu/drm/drm_modes.c:2474:15: error: static_assert expression is not an integral constant expression
extra_ptr = max(bpp_end_ptr, refresh_end_ptr);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/minmax.h:74:19: note: expanded from macro 'max'
#define max(x, y) __careful_cmp(max, x, y)
^~~~~~~~~~~~~~~~~~~~~~~~
include/linux/minmax.h:40:3: note: expanded from macro '__careful_cmp'
__cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y)))
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/minmax.h:33:17: note: expanded from macro '__cmp_once'
static_assert(__types_ok(x, y), \
~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/minmax.h:23:2: note: expanded from macro '__types_ok'
(is_signed_type(typeof(x)) == is_signed_type(typeof(y)))
^
include/linux/build_bug.h:77:50: note: expanded from macro 'static_assert'
#define static_assert(expr, ...) __static_assert(expr, ##__VA_ARGS__, #expr)
~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/build_bug.h:78:56: note: expanded from macro '__static_assert'
#define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
^~~~
drivers/gpu/drm/drm_modes.c:2474:15: note: cast that performs the conversions of a reinterpret_cast is not allowed in a constant expression
include/linux/minmax.h:74:19: note: expanded from macro 'max'
#define max(x, y) __careful_cmp(max, x, y)
^
include/linux/minmax.h:40:3: note: expanded from macro '__careful_cmp'
__cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y)))
^
include/linux/minmax.h:33:17: note: expanded from macro '__cmp_once'
static_assert(__types_ok(x, y), \
^
include/linux/minmax.h:23:3: note: expanded from macro '__types_ok'
(is_signed_type(typeof(x)) == is_signed_type(typeof(y)))
^
include/linux/compiler.h:237:32: note: expanded from macro 'is_signed_type'
#define is_signed_type(type) (((type)(-1)) < (__force type)1)
^
6 warnings and 1 error generated.
vim +2474 drivers/gpu/drm/drm_modes.c
a631bf30eb914a Maxime Ripard 2022-11-14 2334
1794d257fa7bab Chris Wilson 2011-04-17 2335 /**
f5aabb978d1dcd Daniel Vetter 2014-01-23 2336 * drm_mode_parse_command_line_for_connector - parse command line modeline for connector
f5aabb978d1dcd Daniel Vetter 2014-01-23 2337 * @mode_option: optional per connector mode option
f5aabb978d1dcd Daniel Vetter 2014-01-23 2338 * @connector: connector to parse modeline for
f5aabb978d1dcd Daniel Vetter 2014-01-23 2339 * @mode: preallocated drm_cmdline_mode structure to fill out
1794d257fa7bab Chris Wilson 2011-04-17 2340 *
f5aabb978d1dcd Daniel Vetter 2014-01-23 2341 * This parses @mode_option command line modeline for modes and options to
1e84dadb2762cd Thomas Zimmermann 2023-02-09 2342 * configure the connector.
f5aabb978d1dcd Daniel Vetter 2014-01-23 2343 *
f5aabb978d1dcd Daniel Vetter 2014-01-23 2344 * This uses the same parameters as the fb modedb.c, except for an extra
dbd124f013a23d Daniel Vetter 2018-02-19 2345 * force-enable, force-enable-digital and force-disable bit at the end::
1794d257fa7bab Chris Wilson 2011-04-17 2346 *
1794d257fa7bab Chris Wilson 2011-04-17 2347 * <xres>x<yres>[M][R][-<bpp>][@<refresh>][i][m][eDd]
1794d257fa7bab Chris Wilson 2011-04-17 2348 *
1bf4e09227c345 Maxime Ripard 2019-06-19 2349 * Additionals options can be provided following the mode, using a comma to
1bf4e09227c345 Maxime Ripard 2019-06-19 2350 * separate each option. Valid options can be found in
bff9e34c678552 Mauro Carvalho Chehab 2019-07-15 2351 * Documentation/fb/modedb.rst.
1bf4e09227c345 Maxime Ripard 2019-06-19 2352 *
f5aabb978d1dcd Daniel Vetter 2014-01-23 2353 * The intermediate drm_cmdline_mode structure is required to store additional
2a97acd6376922 Yannick Guerrini 2015-03-04 2354 * options from the command line modline like the force-enable/disable flag.
f5aabb978d1dcd Daniel Vetter 2014-01-23 2355 *
f5aabb978d1dcd Daniel Vetter 2014-01-23 2356 * Returns:
f5aabb978d1dcd Daniel Vetter 2014-01-23 2357 * True if a valid modeline has been parsed, false otherwise.
1794d257fa7bab Chris Wilson 2011-04-17 2358 */
1794d257fa7bab Chris Wilson 2011-04-17 2359 bool drm_mode_parse_command_line_for_connector(const char *mode_option,
c0898fca3fce00 Arnd Bergmann 2019-06-28 2360 const struct drm_connector *connector,
1794d257fa7bab Chris Wilson 2011-04-17 2361 struct drm_cmdline_mode *mode)
1794d257fa7bab Chris Wilson 2011-04-17 2362 {
1794d257fa7bab Chris Wilson 2011-04-17 2363 const char *name;
7b1cce760afe38 Hans de Goede 2019-11-18 2364 bool freestanding = false, parse_extras = false;
1bf4e09227c345 Maxime Ripard 2019-06-19 2365 unsigned int bpp_off = 0, refresh_off = 0, options_off = 0;
e08ab74bd4c7a5 Maxime Ripard 2019-06-19 2366 unsigned int mode_end = 0;
83e14ea3a64f00 Hans de Goede 2019-11-18 2367 const char *bpp_ptr = NULL, *refresh_ptr = NULL, *extra_ptr = NULL;
83e14ea3a64f00 Hans de Goede 2019-11-18 2368 const char *options_ptr = NULL;
e08ab74bd4c7a5 Maxime Ripard 2019-06-19 2369 char *bpp_end_ptr = NULL, *refresh_end_ptr = NULL;
a631bf30eb914a Maxime Ripard 2022-11-14 2370 int len, ret;
1794d257fa7bab Chris Wilson 2011-04-17 2371
d1fe276b5115f0 Hans de Goede 2019-11-18 2372 memset(mode, 0, sizeof(*mode));
4e7a4a6fbdc669 Hans de Goede 2019-11-18 2373 mode->panel_orientation = DRM_MODE_PANEL_ORIENTATION_UNKNOWN;
4e7a4a6fbdc669 Hans de Goede 2019-11-18 2374
d1fe276b5115f0 Hans de Goede 2019-11-18 2375 if (!mode_option)
1794d257fa7bab Chris Wilson 2011-04-17 2376 return false;
1794d257fa7bab Chris Wilson 2011-04-17 2377
1794d257fa7bab Chris Wilson 2011-04-17 2378 name = mode_option;
04fee895ef98ff Rolf Eike Beer 2011-06-15 2379
90c258ba4a36f6 Maxime Ripard 2022-09-29 2380 /* Locate the start of named options */
90c258ba4a36f6 Maxime Ripard 2022-09-29 2381 options_ptr = strchr(name, ',');
90c258ba4a36f6 Maxime Ripard 2022-09-29 2382 if (options_ptr)
90c258ba4a36f6 Maxime Ripard 2022-09-29 2383 options_off = options_ptr - name;
90c258ba4a36f6 Maxime Ripard 2022-09-29 2384 else
90c258ba4a36f6 Maxime Ripard 2022-09-29 2385 options_off = strlen(name);
90c258ba4a36f6 Maxime Ripard 2022-09-29 2386
e08ab74bd4c7a5 Maxime Ripard 2019-06-19 2387 /* Try to locate the bpp and refresh specifiers, if any */
90c258ba4a36f6 Maxime Ripard 2022-09-29 2388 bpp_ptr = strnchr(name, options_off, '-');
8b6e28ea0a51a7 Geert Uytterhoeven 2022-09-29 2389 while (bpp_ptr && !isdigit(bpp_ptr[1]))
8b6e28ea0a51a7 Geert Uytterhoeven 2022-09-29 2390 bpp_ptr = strnchr(bpp_ptr + 1, options_off, '-');
6a2d163756545a Hans de Goede 2019-11-18 2391 if (bpp_ptr)
e08ab74bd4c7a5 Maxime Ripard 2019-06-19 2392 bpp_off = bpp_ptr - name;
e08ab74bd4c7a5 Maxime Ripard 2019-06-19 2393
90c258ba4a36f6 Maxime Ripard 2022-09-29 2394 refresh_ptr = strnchr(name, options_off, '@');
7b1cce760afe38 Hans de Goede 2019-11-18 2395 if (refresh_ptr)
e08ab74bd4c7a5 Maxime Ripard 2019-06-19 2396 refresh_off = refresh_ptr - name;
04fee895ef98ff Rolf Eike Beer 2011-06-15 2397
e08ab74bd4c7a5 Maxime Ripard 2019-06-19 2398 /* Locate the end of the name / resolution, and parse it */
1bf4e09227c345 Maxime Ripard 2019-06-19 2399 if (bpp_ptr) {
e08ab74bd4c7a5 Maxime Ripard 2019-06-19 2400 mode_end = bpp_off;
e08ab74bd4c7a5 Maxime Ripard 2019-06-19 2401 } else if (refresh_ptr) {
e08ab74bd4c7a5 Maxime Ripard 2019-06-19 2402 mode_end = refresh_off;
1bf4e09227c345 Maxime Ripard 2019-06-19 2403 } else if (options_ptr) {
1bf4e09227c345 Maxime Ripard 2019-06-19 2404 mode_end = options_off;
cfb0881b8f621b Hans de Goede 2019-11-18 2405 parse_extras = true;
e08ab74bd4c7a5 Maxime Ripard 2019-06-19 2406 } else {
e08ab74bd4c7a5 Maxime Ripard 2019-06-19 2407 mode_end = strlen(name);
e08ab74bd4c7a5 Maxime Ripard 2019-06-19 2408 parse_extras = true;
04fee895ef98ff Rolf Eike Beer 2011-06-15 2409 }
04fee895ef98ff Rolf Eike Beer 2011-06-15 2410
a631bf30eb914a Maxime Ripard 2022-11-14 2411 if (!mode_end)
a631bf30eb914a Maxime Ripard 2022-11-14 2412 return false;
3764137906a5ac Maxime Ripard 2019-08-27 2413
a631bf30eb914a Maxime Ripard 2022-11-14 2414 ret = drm_mode_parse_cmdline_named_mode(name, mode_end, mode);
a631bf30eb914a Maxime Ripard 2022-11-14 2415 if (ret < 0)
a631bf30eb914a Maxime Ripard 2022-11-14 2416 return false;
a631bf30eb914a Maxime Ripard 2022-11-14 2417
a631bf30eb914a Maxime Ripard 2022-11-14 2418 /*
a631bf30eb914a Maxime Ripard 2022-11-14 2419 * Having a mode that starts by a letter (and thus is named) and
a631bf30eb914a Maxime Ripard 2022-11-14 2420 * an at-sign (used to specify a refresh rate) is disallowed.
a631bf30eb914a Maxime Ripard 2022-11-14 2421 */
a631bf30eb914a Maxime Ripard 2022-11-14 2422 if (ret && refresh_ptr)
a631bf30eb914a Maxime Ripard 2022-11-14 2423 return false;
3764137906a5ac Maxime Ripard 2019-08-27 2424
7b1cce760afe38 Hans de Goede 2019-11-18 2425 /* No named mode? Check for a normal mode argument, e.g. 1024x768 */
7b1cce760afe38 Hans de Goede 2019-11-18 2426 if (!mode->specified && isdigit(name[0])) {
e08ab74bd4c7a5 Maxime Ripard 2019-06-19 2427 ret = drm_mode_parse_cmdline_res_mode(name, mode_end,
e08ab74bd4c7a5 Maxime Ripard 2019-06-19 2428 parse_extras,
e08ab74bd4c7a5 Maxime Ripard 2019-06-19 2429 connector,
e08ab74bd4c7a5 Maxime Ripard 2019-06-19 2430 mode);
e08ab74bd4c7a5 Maxime Ripard 2019-06-19 2431 if (ret)
e08ab74bd4c7a5 Maxime Ripard 2019-06-19 2432 return false;
7b1cce760afe38 Hans de Goede 2019-11-18 2433
1794d257fa7bab Chris Wilson 2011-04-17 2434 mode->specified = true;
7b1cce760afe38 Hans de Goede 2019-11-18 2435 }
7b1cce760afe38 Hans de Goede 2019-11-18 2436
7b1cce760afe38 Hans de Goede 2019-11-18 2437 /* No mode? Check for freestanding extras and/or options */
7b1cce760afe38 Hans de Goede 2019-11-18 2438 if (!mode->specified) {
7b1cce760afe38 Hans de Goede 2019-11-18 2439 unsigned int len = strlen(mode_option);
7b1cce760afe38 Hans de Goede 2019-11-18 2440
7b1cce760afe38 Hans de Goede 2019-11-18 2441 if (bpp_ptr || refresh_ptr)
7b1cce760afe38 Hans de Goede 2019-11-18 2442 return false; /* syntax error */
7b1cce760afe38 Hans de Goede 2019-11-18 2443
7b1cce760afe38 Hans de Goede 2019-11-18 2444 if (len == 1 || (len >= 2 && mode_option[1] == ','))
7b1cce760afe38 Hans de Goede 2019-11-18 2445 extra_ptr = mode_option;
7b1cce760afe38 Hans de Goede 2019-11-18 2446 else
7b1cce760afe38 Hans de Goede 2019-11-18 2447 options_ptr = mode_option - 1;
7b1cce760afe38 Hans de Goede 2019-11-18 2448
7b1cce760afe38 Hans de Goede 2019-11-18 2449 freestanding = true;
7b1cce760afe38 Hans de Goede 2019-11-18 2450 }
e08ab74bd4c7a5 Maxime Ripard 2019-06-19 2451
e08ab74bd4c7a5 Maxime Ripard 2019-06-19 2452 if (bpp_ptr) {
e08ab74bd4c7a5 Maxime Ripard 2019-06-19 2453 ret = drm_mode_parse_cmdline_bpp(bpp_ptr, &bpp_end_ptr, mode);
e08ab74bd4c7a5 Maxime Ripard 2019-06-19 2454 if (ret)
e08ab74bd4c7a5 Maxime Ripard 2019-06-19 2455 return false;
6a2d163756545a Hans de Goede 2019-11-18 2456
6a2d163756545a Hans de Goede 2019-11-18 2457 mode->bpp_specified = true;
1794d257fa7bab Chris Wilson 2011-04-17 2458 }
1794d257fa7bab Chris Wilson 2011-04-17 2459
e08ab74bd4c7a5 Maxime Ripard 2019-06-19 2460 if (refresh_ptr) {
e08ab74bd4c7a5 Maxime Ripard 2019-06-19 2461 ret = drm_mode_parse_cmdline_refresh(refresh_ptr,
e08ab74bd4c7a5 Maxime Ripard 2019-06-19 2462 &refresh_end_ptr, mode);
e08ab74bd4c7a5 Maxime Ripard 2019-06-19 2463 if (ret)
e08ab74bd4c7a5 Maxime Ripard 2019-06-19 2464 return false;
6a2d163756545a Hans de Goede 2019-11-18 2465
6a2d163756545a Hans de Goede 2019-11-18 2466 mode->refresh_specified = true;
1794d257fa7bab Chris Wilson 2011-04-17 2467 }
1794d257fa7bab Chris Wilson 2011-04-17 2468
e08ab74bd4c7a5 Maxime Ripard 2019-06-19 2469 /*
e08ab74bd4c7a5 Maxime Ripard 2019-06-19 2470 * Locate the end of the bpp / refresh, and parse the extras
e08ab74bd4c7a5 Maxime Ripard 2019-06-19 2471 * if relevant
e08ab74bd4c7a5 Maxime Ripard 2019-06-19 2472 */
e08ab74bd4c7a5 Maxime Ripard 2019-06-19 2473 if (bpp_ptr && refresh_ptr)
e08ab74bd4c7a5 Maxime Ripard 2019-06-19 @2474 extra_ptr = max(bpp_end_ptr, refresh_end_ptr);
e08ab74bd4c7a5 Maxime Ripard 2019-06-19 2475 else if (bpp_ptr)
e08ab74bd4c7a5 Maxime Ripard 2019-06-19 2476 extra_ptr = bpp_end_ptr;
e08ab74bd4c7a5 Maxime Ripard 2019-06-19 2477 else if (refresh_ptr)
e08ab74bd4c7a5 Maxime Ripard 2019-06-19 2478 extra_ptr = refresh_end_ptr;
e08ab74bd4c7a5 Maxime Ripard 2019-06-19 2479
c2ed3e94190181 Hans de Goede 2019-11-18 2480 if (extra_ptr) {
c2ed3e94190181 Hans de Goede 2019-11-18 2481 if (options_ptr)
c2ed3e94190181 Hans de Goede 2019-11-18 2482 len = options_ptr - extra_ptr;
c2ed3e94190181 Hans de Goede 2019-11-18 2483 else
c2ed3e94190181 Hans de Goede 2019-11-18 2484 len = strlen(extra_ptr);
3aeeb13d899627 Maxime Ripard 2019-06-19 2485
7b1cce760afe38 Hans de Goede 2019-11-18 2486 ret = drm_mode_parse_cmdline_extra(extra_ptr, len, freestanding,
3aeeb13d899627 Maxime Ripard 2019-06-19 2487 connector, mode);
3aeeb13d899627 Maxime Ripard 2019-06-19 2488 if (ret)
3aeeb13d899627 Maxime Ripard 2019-06-19 2489 return false;
1bf4e09227c345 Maxime Ripard 2019-06-19 2490 }
e08ab74bd4c7a5 Maxime Ripard 2019-06-19 2491
1bf4e09227c345 Maxime Ripard 2019-06-19 2492 if (options_ptr) {
739b200c2edcaa Hans de Goede 2019-11-18 2493 ret = drm_mode_parse_cmdline_options(options_ptr + 1,
7b1cce760afe38 Hans de Goede 2019-11-18 2494 freestanding,
1bf4e09227c345 Maxime Ripard 2019-06-19 2495 connector, mode);
1bf4e09227c345 Maxime Ripard 2019-06-19 2496 if (ret)
e08ab74bd4c7a5 Maxime Ripard 2019-06-19 2497 return false;
1794d257fa7bab Chris Wilson 2011-04-17 2498 }
1794d257fa7bab Chris Wilson 2011-04-17 2499
1794d257fa7bab Chris Wilson 2011-04-17 2500 return true;
1794d257fa7bab Chris Wilson 2011-04-17 2501 }
1794d257fa7bab Chris Wilson 2011-04-17 2502 EXPORT_SYMBOL(drm_mode_parse_command_line_for_connector);
1794d257fa7bab Chris Wilson 2011-04-17 2503
From: kernel test robot > Sent: 31 July 2023 22:44 > > kernel test robot noticed the following build errors: > > [auto build test ERROR on akpm-mm/mm-everything] > [also build test ERROR on linus/master crng-random/master v6.5-rc4 next-20230731] > [cannot apply to next-20230728] ... > compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project.git > f28c006a5895fc0e329fe15fead81e37457cb1d1) > reproduce: (https://download.01.org/0day-ci/archive/20230801/202308010559.SEtfkzQU- > lkp@intel.com/reproduce) > .... > >> drivers/gpu/drm/drm_modes.c:2474:15: error: static_assert expression is not an integral constant > expression > extra_ptr = max(bpp_end_ptr, refresh_end_ptr); > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This is really a bug in clang - fixed in 16.0.0. In C (but probably not C++) '(void *)1' should be a compile-time constant. Will be fixed in v3 of the patch. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
diff --git a/include/linux/minmax.h b/include/linux/minmax.h index 531860e9cc55..cb126853f2be 100644 --- a/include/linux/minmax.h +++ b/include/linux/minmax.h @@ -2,6 +2,7 @@ #ifndef _LINUX_MINMAX_H #define _LINUX_MINMAX_H +#include <linux/build_bug.h> #include <linux/const.h> /* @@ -9,9 +10,8 @@ * * - avoid multiple evaluations of the arguments (so side-effects like * "x++" happen only once) when non-constant. - * - perform strict type-checking (to generate warnings instead of - * nasty runtime surprises). See the "unnecessary" pointer comparison - * in __typecheck(). + * - perform signed v unsigned type-checking (to generate compile + * errors instead of nasty runtime surprises). * - retain result as a constant expressions when called with only * constant expressions (to avoid tripping VLA warnings in stack * allocation usage). @@ -19,23 +19,25 @@ #define __typecheck(x, y) \ (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1))) -#define __no_side_effects(x, y) \ - (__is_constexpr(x) && __is_constexpr(y)) +#define __types_ok(x, y) \ + (is_signed_type(typeof(x)) == is_signed_type(typeof(y))) -#define __safe_cmp(x, y) \ - (__typecheck(x, y) && __no_side_effects(x, y)) +#define __cmp_op_min < +#define __cmp_op_max > -#define __cmp(x, y, op) ((x) op (y) ? (x) : (y)) +#define __cmp(op, x, y) ((x) __cmp_op_##op (y) ? (x) : (y)) -#define __cmp_once(x, y, unique_x, unique_y, op) ({ \ +#define __cmp_once(op, x, y, unique_x, unique_y) ({ \ typeof(x) unique_x = (x); \ typeof(y) unique_y = (y); \ - __cmp(unique_x, unique_y, op); }) + static_assert(__types_ok(x, y), \ + #op "(" #x ", " #y ") signedness error, fix types or consider " #op "_unsigned() before " #op "_t()"); \ + __cmp(op, unique_x, unique_y); }) -#define __careful_cmp(x, y, op) \ - __builtin_choose_expr(__safe_cmp(x, y), \ - __cmp(x, y, op), \ - __cmp_once(x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y), op)) +#define __careful_cmp(op, x, y) \ + __builtin_choose_expr(__is_constexpr((x) - (y)), \ + __cmp(op, x, y), \ + __cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y))) #define __clamp(val, lo, hi) \ ((val) >= (hi) ? (hi) : ((val) <= (lo) ? (lo) : (val))) @@ -44,17 +46,15 @@ typeof(val) unique_val = (val); \ typeof(lo) unique_lo = (lo); \ typeof(hi) unique_hi = (hi); \ + static_assert(__builtin_choose_expr(__is_constexpr((lo) > (hi)), \ + (lo) <= (hi), true), \ + "clamp() low limit " #lo " greater than high limit " #hi); \ + static_assert(__types_ok(val, lo), "clamp() 'lo' signedness error"); \ + static_assert(__types_ok(val, hi), "clamp() 'hi' signedness error"); \ __clamp(unique_val, unique_lo, unique_hi); }) -#define __clamp_input_check(lo, hi) \ - (BUILD_BUG_ON_ZERO(__builtin_choose_expr( \ - __is_constexpr((lo) > (hi)), (lo) > (hi), false))) - #define __careful_clamp(val, lo, hi) ({ \ - __clamp_input_check(lo, hi) + \ - __builtin_choose_expr(__typecheck(val, lo) && __typecheck(val, hi) && \ - __typecheck(hi, lo) && __is_constexpr(val) && \ - __is_constexpr(lo) && __is_constexpr(hi), \ + __builtin_choose_expr(__is_constexpr((val) - (lo) + (hi)), \ __clamp(val, lo, hi), \ __clamp_once(val, lo, hi, __UNIQUE_ID(__val), \ __UNIQUE_ID(__lo), __UNIQUE_ID(__hi))); }) @@ -64,14 +64,14 @@ * @x: first value * @y: second value */ -#define min(x, y) __careful_cmp(x, y, <) +#define min(x, y) __careful_cmp(min, x, y) /** * max - return maximum of two values of the same or compatible types * @x: first value * @y: second value */ -#define max(x, y) __careful_cmp(x, y, >) +#define max(x, y) __careful_cmp(max, x, y) /** * min_unsigned - return minimum of two non-negative values @@ -79,16 +79,16 @@ * @x: first value * @y: second value */ -#define min_unsigned(x, y) \ - __careful_cmp((x) + 0u + 0ul + 0ull, (y) + 0u + 0ul + 0ull, <) +#define min_unsigned(x, y) \ + __careful_cmp(min, (x) + 0u + 0ul + 0ull, (y) + 0u + 0ul + 0ull) /** * max_unsigned - return maximum of two non-negative values * @x: first value * @y: second value */ -#define max_unsigned(x, y) \ - __careful_cmp((x) + 0u + 0ul + 0ull, (y) + 0u + 0ul + 0ull, >) +#define max_unsigned(x, y) \ + __careful_cmp(max, (x) + 0u + 0ul + 0ull, (y) + 0u + 0ul + 0ull) /** * min3 - return minimum of three values @@ -140,7 +140,7 @@ * @x: first value * @y: second value */ -#define min_t(type, x, y) __careful_cmp((type)(x), (type)(y), <) +#define min_t(type, x, y) __careful_cmp(min, (type)(x), (type)(y)) /** * max_t - return maximum of two values, using the specified type @@ -148,7 +148,7 @@ * @x: first value * @y: second value */ -#define max_t(type, x, y) __careful_cmp((type)(x), (type)(y), >) +#define max_t(type, x, y) __careful_cmp(max, (type)(x), (type)(y)) /** * clamp_t - return a value clamped to a given range using a given type