[next,resend,5/5] minmax: Relax check to allow comparison between int and small unsigned constants.
Message ID | 48c2cd0407f14859919d4fcbe526234a@AcuMS.aculab.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp2432026vqg; Tue, 25 Jul 2023 05:27:19 -0700 (PDT) X-Google-Smtp-Source: APBJJlEGP58MBi28Tzpj45SE2xzVNW5PdjjaHjChMYGVD3wZl/2T7lscZfJy7MT2wtDjaAS4p57b X-Received: by 2002:a05:6358:2786:b0:135:62de:ff7d with SMTP id l6-20020a056358278600b0013562deff7dmr9706740rwb.8.1690288039235; Tue, 25 Jul 2023 05:27:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690288039; cv=none; d=google.com; s=arc-20160816; b=Kdp1/kEqz//rrssxKHQk34MHEL+Mv6WvTg7qV5jmbB7BjWlK8D0qTK+ky3VompHtoD zVIDL+xlV0244xdaSiHlAkL8gERtLWg5DZc0yONzF9EqtO++sUE2mVyYdzHkihl7Z3Gw 5R4zr7SOYltOXpYcJvOX7j6WRSD/Ht4ea/vH0uDgOYbl5ZmrfLo3NHZpmXUovG4VzDzD AJ6vqgWGjWP6g1KAEGYJmSQS05aa8cvghCeQeBsgn4L33ldZMsddQ1glcsxlrNnDYXob iZ+j9AQ5EHheolGzwck/Q1Z9LzxCyxDQyMpFot3+tJR2wi2v+HVpYfU8p0dqrxTB+7Em hL3g== 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=ibIiQ8BFUL41/i7DzWXMQkV6ZiVMbicnY8jd9DREsGg=; fh=lQu0FQMQB/KijsOLYPBSZ4oPXp6gJVSgtvs90PKCM00=; b=r02TyWnU3tqJ5vuIL/t1MzgkKMxYMYs1eA/1E3wHHonNx56pcrtnsFuLa3lPZInS3M EyVbqbaDqzGryRGaP1o/h+Xsvz0HSRv4PjafBbWIIj0bbSc2wrteu1avVgXMX7JFX0ex j45cz95LvmawDwCtDZfrqWmgRIgHiuJ0xpKBqeCg+KUHRQ4CICnpsySwobr4raeAG+KG y98nwj8Vvye503sPLeblEhDw++wJuvLyRCAmbFwrVMhyCx6zoG17GNyUTUpphjLKYscR Nzh+3GXBu7BwNYQQ2z7OugsUgYoWgTJugVpMC0uJ+wulHPbx7U5uFv+nKXjTu1yJe9tS 2Yxw== 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 z19-20020a63e113000000b00553a50c5d85si10915535pgh.510.2023.07.25.05.27.06; Tue, 25 Jul 2023 05:27:19 -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 S232949AbjGYLzR convert rfc822-to-8bit (ORCPT <rfc822;hanasaki@gmail.com> + 99 others); Tue, 25 Jul 2023 07:55:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232633AbjGYLy7 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 25 Jul 2023 07:54:59 -0400 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.86.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BDD361FD2 for <linux-kernel@vger.kernel.org>; Tue, 25 Jul 2023 04:54: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-83-x3rwowdDMCuvY-m_e9C9zQ-1; Tue, 25 Jul 2023 12:54:18 +0100 X-MC-Unique: x3rwowdDMCuvY-m_e9C9zQ-1 Received: from AcuMS.Aculab.com (10.202.163.6) by AcuMS.aculab.com (10.202.163.6) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Tue, 25 Jul 2023 12:54:16 +0100 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Tue, 25 Jul 2023 12:54:16 +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 resend 5/5] minmax: Relax check to allow comparison between int and small unsigned constants. Thread-Topic: [PATCH next resend 5/5] minmax: Relax check to allow comparison between int and small unsigned constants. Thread-Index: Adm+7rJ87D8nFkT9Rp6d+7ZLnF7rBg== Date: Tue, 25 Jul 2023 11:54:16 +0000 Message-ID: <48c2cd0407f14859919d4fcbe526234a@AcuMS.aculab.com> References: <caa84582f9414de895ac6c4fe2b53489@AcuMS.aculab.com> In-Reply-To: <caa84582f9414de895ac6c4fe2b53489@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: 1772395470831076380 X-GMAIL-MSGID: 1772395470831076380 |
Series |
minmax: Relax type checks in min() and max().
|
|
Commit Message
David Laight
July 25, 2023, 11:54 a.m. UTC
Convert constants between 0 and INT_MAX to 'int' prior to comparisons
so that min(signed_var, 20u) and, more commonly, min(signed_var, sizeof())
are both valid.
Signed-off-by: David Laight <david.laight@aculab.com>
---
Resend as reply to 0/5
include/linux/minmax.h | 35 +++++++++++++++++++++++------------
1 file changed, 23 insertions(+), 12 deletions(-)
Comments
Hi David, kernel test robot noticed the following build warnings: [auto build test WARNING on akpm-mm/mm-everything] [also build test WARNING on linus/master v6.5-rc3 next-20230725] [cannot apply to next-20230725] [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-Allow-min-max-clamp-if-the-arguments-have-the-same-signedness/20230725-204940 base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything patch link: https://lore.kernel.org/r/48c2cd0407f14859919d4fcbe526234a%40AcuMS.aculab.com patch subject: [PATCH next resend 5/5] minmax: Relax check to allow comparison between int and small unsigned constants. config: riscv-randconfig-r024-20230725 (https://download.01.org/0day-ci/archive/20230726/202307260303.3ftEpZRU-lkp@intel.com/config) compiler: riscv32-linux-gcc (GCC) 12.3.0 reproduce: (https://download.01.org/0day-ci/archive/20230726/202307260303.3ftEpZRU-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/202307260303.3ftEpZRU-lkp@intel.com/ All warnings (new ones prefixed by >>): In file included from include/linux/kernel.h:27, from include/linux/cpumask.h:10, from include/linux/smp.h:13, from include/linux/lockdep.h:14, from include/linux/mutex.h:17, from include/linux/notifier.h:14, from include/linux/kprobes.h:21, from include/linux/kgdb.h:19, from include/linux/fb.h:6, from drivers/gpu/drm/drm_modes.c:35: drivers/gpu/drm/drm_modes.c: In function 'drm_mode_parse_command_line_for_connector': >> include/linux/minmax.h:23:22: warning: ordered comparison of pointer with integer zero [-Wextra] 23 | ((x) >= 0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__)) | ^~ include/linux/minmax.h:36:27: note: in definition of macro '__cmp' 36 | #define __cmp(op, x, y) ((x) __cmp_op_##op (y) ? (x) : (y)) | ^ include/linux/minmax.h:25:47: note: in expansion of macro '__is_noneg_int' 25 | #define __int_const(x) __builtin_choose_expr(__is_noneg_int(x), (int)(long)(x), (x)) | ^~~~~~~~~~~~~~ include/linux/minmax.h:47:27: note: in expansion of macro '__int_const' 47 | __cmp(op, __int_const(x), __int_const(y)), \ | ^~~~~~~~~~~ include/linux/minmax.h:81:25: note: in expansion of macro '__careful_cmp' 81 | #define max(x, y) __careful_cmp(max, x, y) | ^~~~~~~~~~~~~ drivers/gpu/drm/drm_modes.c:2474:29: note: in expansion of macro 'max' 2474 | extra_ptr = max(bpp_end_ptr, refresh_end_ptr); | ^~~ >> include/linux/minmax.h:23:22: warning: ordered comparison of pointer with integer zero [-Wextra] 23 | ((x) >= 0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__)) | ^~ include/linux/minmax.h:36:45: note: in definition of macro '__cmp' 36 | #define __cmp(op, x, y) ((x) __cmp_op_##op (y) ? (x) : (y)) | ^ include/linux/minmax.h:25:47: note: in expansion of macro '__is_noneg_int' 25 | #define __int_const(x) __builtin_choose_expr(__is_noneg_int(x), (int)(long)(x), (x)) | ^~~~~~~~~~~~~~ include/linux/minmax.h:47:43: note: in expansion of macro '__int_const' 47 | __cmp(op, __int_const(x), __int_const(y)), \ | ^~~~~~~~~~~ include/linux/minmax.h:81:25: note: in expansion of macro '__careful_cmp' 81 | #define max(x, y) __careful_cmp(max, x, y) | ^~~~~~~~~~~~~ drivers/gpu/drm/drm_modes.c:2474:29: note: in expansion of macro 'max' 2474 | extra_ptr = max(bpp_end_ptr, refresh_end_ptr); | ^~~ >> include/linux/minmax.h:23:22: warning: ordered comparison of pointer with integer zero [-Wextra] 23 | ((x) >= 0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__)) | ^~ include/linux/minmax.h:36:51: note: in definition of macro '__cmp' 36 | #define __cmp(op, x, y) ((x) __cmp_op_##op (y) ? (x) : (y)) | ^ include/linux/minmax.h:25:47: note: in expansion of macro '__is_noneg_int' 25 | #define __int_const(x) __builtin_choose_expr(__is_noneg_int(x), (int)(long)(x), (x)) | ^~~~~~~~~~~~~~ include/linux/minmax.h:47:27: note: in expansion of macro '__int_const' 47 | __cmp(op, __int_const(x), __int_const(y)), \ | ^~~~~~~~~~~ include/linux/minmax.h:81:25: note: in expansion of macro '__careful_cmp' 81 | #define max(x, y) __careful_cmp(max, x, y) | ^~~~~~~~~~~~~ drivers/gpu/drm/drm_modes.c:2474:29: note: in expansion of macro 'max' 2474 | extra_ptr = max(bpp_end_ptr, refresh_end_ptr); | ^~~ >> include/linux/minmax.h:23:22: warning: ordered comparison of pointer with integer zero [-Wextra] 23 | ((x) >= 0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__)) | ^~ include/linux/minmax.h:36:57: note: in definition of macro '__cmp' 36 | #define __cmp(op, x, y) ((x) __cmp_op_##op (y) ? (x) : (y)) | ^ include/linux/minmax.h:25:47: note: in expansion of macro '__is_noneg_int' 25 | #define __int_const(x) __builtin_choose_expr(__is_noneg_int(x), (int)(long)(x), (x)) | ^~~~~~~~~~~~~~ include/linux/minmax.h:47:43: note: in expansion of macro '__int_const' 47 | __cmp(op, __int_const(x), __int_const(y)), \ | ^~~~~~~~~~~ include/linux/minmax.h:81:25: note: in expansion of macro '__careful_cmp' 81 | #define max(x, y) __careful_cmp(max, x, y) | ^~~~~~~~~~~~~ drivers/gpu/drm/drm_modes.c:2474:29: note: in expansion of macro 'max' 2474 | extra_ptr = max(bpp_end_ptr, refresh_end_ptr); | ^~~ >> include/linux/minmax.h:23:22: warning: ordered comparison of pointer with integer zero [-Wextra] 23 | ((x) >= 0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__)) | ^~ include/linux/minmax.h:25:47: note: in expansion of macro '__is_noneg_int' 25 | #define __int_const(x) __builtin_choose_expr(__is_noneg_int(x), (int)(long)(x), (x)) | ^~~~~~~~~~~~~~ include/linux/minmax.h:39:16: note: in expansion of macro '__int_const' 39 | typeof(__int_const(x)) unique_x = (x); \ | ^~~~~~~~~~~ include/linux/minmax.h:48:17: note: in expansion of macro '__cmp_once' 48 | __cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y))) | ^~~~~~~~~~ include/linux/minmax.h:81:25: note: in expansion of macro '__careful_cmp' 81 | #define max(x, y) __careful_cmp(max, x, y) | ^~~~~~~~~~~~~ drivers/gpu/drm/drm_modes.c:2474:29: note: in expansion of macro 'max' 2474 | extra_ptr = max(bpp_end_ptr, refresh_end_ptr); | ^~~ >> include/linux/minmax.h:23:22: warning: ordered comparison of pointer with integer zero [-Wextra] 23 | ((x) >= 0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__)) | ^~ include/linux/minmax.h:25:47: note: in expansion of macro '__is_noneg_int' 25 | #define __int_const(x) __builtin_choose_expr(__is_noneg_int(x), (int)(long)(x), (x)) | ^~~~~~~~~~~~~~ include/linux/minmax.h:40:16: note: in expansion of macro '__int_const' 40 | typeof(__int_const(y)) unique_y = (y); \ | ^~~~~~~~~~~ include/linux/minmax.h:48:17: note: in expansion of macro '__cmp_once' 48 | __cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y))) | ^~~~~~~~~~ include/linux/minmax.h:81:25: note: in expansion of macro '__careful_cmp' 81 | #define max(x, y) __careful_cmp(max, x, y) | ^~~~~~~~~~~~~ drivers/gpu/drm/drm_modes.c:2474:29: note: in expansion of macro 'max' 2474 | extra_ptr = max(bpp_end_ptr, refresh_end_ptr); | ^~~ In file included from include/linux/init.h:5, from include/linux/printk.h:6, from include/asm-generic/bug.h:22, from arch/riscv/include/asm/bug.h:83, from include/linux/bug.h:5, from arch/riscv/include/asm/cmpxchg.h:9, from arch/riscv/include/asm/atomic.h:19, from include/linux/atomic.h:7, from include/linux/refcount.h:95, from include/linux/fb.h:5: >> include/linux/minmax.h:23:22: warning: ordered comparison of pointer with integer zero [-Wextra] 23 | ((x) >= 0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__)) | ^~ include/linux/build_bug.h:78:56: note: in definition of macro '__static_assert' 78 | #define __static_assert(expr, msg, ...) _Static_assert(expr, msg) | ^~~~ include/linux/minmax.h:41:9: note: in expansion of macro 'static_assert' 41 | static_assert(__types_ok(x, y), \ | ^~~~~~~~~~~~~ include/linux/minmax.h:31:17: note: in expansion of macro '__is_noneg_int' 31 | __is_noneg_int(x) || __is_noneg_int(y)) | ^~~~~~~~~~~~~~ include/linux/minmax.h:41:23: note: in expansion of macro '__types_ok' 41 | static_assert(__types_ok(x, y), \ | ^~~~~~~~~~ include/linux/minmax.h:48:17: note: in expansion of macro '__cmp_once' 48 | __cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y))) | ^~~~~~~~~~ include/linux/minmax.h:81:25: note: in expansion of macro '__careful_cmp' 81 | #define max(x, y) __careful_cmp(max, x, y) | ^~~~~~~~~~~~~ drivers/gpu/drm/drm_modes.c:2474:29: note: in expansion of macro 'max' 2474 | extra_ptr = max(bpp_end_ptr, refresh_end_ptr); | ^~~ >> include/linux/minmax.h:23:22: warning: ordered comparison of pointer with integer zero [-Wextra] 23 | ((x) >= 0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__)) | ^~ include/linux/build_bug.h:78:56: note: in definition of macro '__static_assert' 78 | #define __static_assert(expr, msg, ...) _Static_assert(expr, msg) | ^~~~ include/linux/minmax.h:41:9: note: in expansion of macro 'static_assert' 41 | static_assert(__types_ok(x, y), \ | ^~~~~~~~~~~~~ include/linux/minmax.h:31:38: note: in expansion of macro '__is_noneg_int' 31 | __is_noneg_int(x) || __is_noneg_int(y)) | ^~~~~~~~~~~~~~ include/linux/minmax.h:41:23: note: in expansion of macro '__types_ok' 41 | static_assert(__types_ok(x, y), \ | ^~~~~~~~~~ include/linux/minmax.h:48:17: note: in expansion of macro '__cmp_once' 48 | __cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y))) | ^~~~~~~~~~ include/linux/minmax.h:81:25: note: in expansion of macro '__careful_cmp' 81 | #define max(x, y) __careful_cmp(max, x, y) | ^~~~~~~~~~~~~ drivers/gpu/drm/drm_modes.c:2474:29: note: in expansion of macro 'max' 2474 | extra_ptr = max(bpp_end_ptr, refresh_end_ptr); | ^~~ vim +23 include/linux/minmax.h 6 7 /* 8 * min()/max()/clamp() macros must accomplish three things: 9 * 10 * - Avoid multiple evaluations of the arguments (so side-effects like 11 * "x++" happen only once) when non-constant. 12 * - Perform signed v unsigned type-checking (to generate compile 13 * errors instead of nasty runtime surprises). 14 * Constants from 0 to INT_MAX are cast to (int) so can be used 15 * in comparisons with signed types. 16 * - Retain result as a constant expressions when called with only 17 * constant expressions (to avoid tripping VLA warnings in stack 18 * allocation usage). 19 */ 20 21 #define __is_noneg_int(x) \ 22 __builtin_choose_expr(!__is_constexpr(x), false, \ > 23 ((x) >= 0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__)) 24
From: kernel test robot <lkp@intel.com> > Sent: 25 July 2023 20:37 > ... > drivers/gpu/drm/drm_modes.c: In function 'drm_mode_parse_command_line_for_connector': > >> include/linux/minmax.h:23:22: warning: ordered comparison of pointer with integer zero [-Wextra] > 23 | ((x) >= 0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__)) > | ^~ ... > drivers/gpu/drm/drm_modes.c:2474:29: note: in expansion of macro 'max' > 2474 | extra_ptr = max(bpp_end_ptr, refresh_end_ptr); > | ^~~ There are a handful of annoying uses of min/max with pointers. I'll fix this in v2 by adding a cast to the 0. (I was expecting an error for unsigned types.) 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 warnings: [auto build test WARNING on akpm-mm/mm-everything] [also build test WARNING on linus/master crng-random/master v6.5-rc3 next-20230726] [cannot apply to next-20230725] [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-Allow-min-max-clamp-if-the-arguments-have-the-same-signedness/20230725-204940 base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything patch link: https://lore.kernel.org/r/48c2cd0407f14859919d4fcbe526234a%40AcuMS.aculab.com patch subject: [PATCH next resend 5/5] minmax: Relax check to allow comparison between int and small unsigned constants. config: x86_64-randconfig-r071-20230725 (https://download.01.org/0day-ci/archive/20230727/202307271340.F1VOMz4L-lkp@intel.com/config) compiler: gcc-12 (Debian 12.2.0-14) 12.2.0 reproduce: (https://download.01.org/0day-ci/archive/20230727/202307271340.F1VOMz4L-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/202307271340.F1VOMz4L-lkp@intel.com/ sparse warnings: (new ones prefixed by >>) >> mm/percpu.c:3102:24: sparse: sparse: incompatible types for operation (>=): >> mm/percpu.c:3102:24: sparse: void *ptr >> mm/percpu.c:3102:24: sparse: int >> mm/percpu.c:3102:24: sparse: sparse: bad constant expression type >> mm/percpu.c:3102:24: sparse: sparse: incompatible types for operation (>=): >> mm/percpu.c:3102:24: sparse: void *[assigned] ptr >> mm/percpu.c:3102:24: sparse: int >> mm/percpu.c:3102:24: sparse: sparse: incompatible types for operation (>=): >> mm/percpu.c:3102:24: sparse: void *base >> mm/percpu.c:3102:24: sparse: int >> mm/percpu.c:3102:24: sparse: sparse: incompatible types for operation (>=): >> mm/percpu.c:3102:24: sparse: void *[assigned] ptr >> mm/percpu.c:3102:24: sparse: int >> mm/percpu.c:3102:24: sparse: sparse: incompatible types for operation (>=): >> mm/percpu.c:3102:24: sparse: void *base >> mm/percpu.c:3102:24: sparse: int mm/percpu.c:3102:24: sparse: sparse: incompatible types for operation (<): mm/percpu.c:3102:24: sparse: bad type __UNIQUE_ID___x458 mm/percpu.c:3102:24: sparse: bad type __UNIQUE_ID___y459 -- >> fs/ntfs3/lznt.c:157:16: sparse: sparse: incompatible types for operation (>=): >> fs/ntfs3/lznt.c:157:16: sparse: unsigned char [usertype] * >> fs/ntfs3/lznt.c:157:16: sparse: int >> fs/ntfs3/lznt.c:157:16: sparse: sparse: bad constant expression type >> fs/ntfs3/lznt.c:157:16: sparse: sparse: incompatible types for operation (>=): >> fs/ntfs3/lznt.c:157:16: sparse: unsigned char [usertype] * >> fs/ntfs3/lznt.c:157:16: sparse: int >> fs/ntfs3/lznt.c:157:16: sparse: sparse: incompatible types for operation (>=): >> fs/ntfs3/lznt.c:157:16: sparse: unsigned char [usertype] *cmpr_end >> fs/ntfs3/lznt.c:157:16: sparse: int >> fs/ntfs3/lznt.c:157:16: sparse: sparse: incompatible types for operation (>=): >> fs/ntfs3/lznt.c:157:16: sparse: unsigned char [usertype] * >> fs/ntfs3/lznt.c:157:16: sparse: int >> fs/ntfs3/lznt.c:157:16: sparse: sparse: incompatible types for operation (>=): >> fs/ntfs3/lznt.c:157:16: sparse: unsigned char [usertype] *cmpr_end >> fs/ntfs3/lznt.c:157:16: sparse: int fs/ntfs3/lznt.c:157:16: sparse: sparse: incompatible types for operation (<): fs/ntfs3/lznt.c:157:16: sparse: bad type __UNIQUE_ID___x333 fs/ntfs3/lznt.c:157:16: sparse: bad type __UNIQUE_ID___y334 vim +3102 mm/percpu.c 3c9a024fde58b0 Tejun Heo 2010-09-09 3022 3c9a024fde58b0 Tejun Heo 2010-09-09 3023 #if defined(BUILD_EMBED_FIRST_CHUNK) 66c3a75772247c Tejun Heo 2009-03-10 3024 /** 66c3a75772247c Tejun Heo 2009-03-10 3025 * pcpu_embed_first_chunk - embed the first percpu chunk into bootmem 66c3a75772247c Tejun Heo 2009-03-10 3026 * @reserved_size: the size of reserved percpu area in bytes 4ba6ce250e406b Tejun Heo 2010-06-27 3027 * @dyn_size: minimum free size for dynamic allocation in bytes c8826dd538602d Tejun Heo 2009-08-14 3028 * @atom_size: allocation atom size c8826dd538602d Tejun Heo 2009-08-14 3029 * @cpu_distance_fn: callback to determine distance between cpus, optional 1ca3fb3abd2b61 Kefeng Wang 2022-01-19 3030 * @cpu_to_nd_fn: callback to convert cpu to it's node, optional 66c3a75772247c Tejun Heo 2009-03-10 3031 * 66c3a75772247c Tejun Heo 2009-03-10 3032 * This is a helper to ease setting up embedded first percpu chunk and 66c3a75772247c Tejun Heo 2009-03-10 3033 * can be called where pcpu_setup_first_chunk() is expected. 66c3a75772247c Tejun Heo 2009-03-10 3034 * 66c3a75772247c Tejun Heo 2009-03-10 3035 * If this function is used to setup the first chunk, it is allocated 23f917169ef157 Kefeng Wang 2022-01-19 3036 * by calling pcpu_fc_alloc and used as-is without being mapped into c8826dd538602d Tejun Heo 2009-08-14 3037 * vmalloc area. Allocations are always whole multiples of @atom_size c8826dd538602d Tejun Heo 2009-08-14 3038 * aligned to @atom_size. c8826dd538602d Tejun Heo 2009-08-14 3039 * c8826dd538602d Tejun Heo 2009-08-14 3040 * This enables the first chunk to piggy back on the linear physical c8826dd538602d Tejun Heo 2009-08-14 3041 * mapping which often uses larger page size. Please note that this c8826dd538602d Tejun Heo 2009-08-14 3042 * can result in very sparse cpu->unit mapping on NUMA machines thus c8826dd538602d Tejun Heo 2009-08-14 3043 * requiring large vmalloc address space. Don't use this allocator if c8826dd538602d Tejun Heo 2009-08-14 3044 * vmalloc space is not orders of magnitude larger than distances c8826dd538602d Tejun Heo 2009-08-14 3045 * between node memory addresses (ie. 32bit NUMA machines). 66c3a75772247c Tejun Heo 2009-03-10 3046 * 4ba6ce250e406b Tejun Heo 2010-06-27 3047 * @dyn_size specifies the minimum dynamic area size. 66c3a75772247c Tejun Heo 2009-03-10 3048 * 66c3a75772247c Tejun Heo 2009-03-10 3049 * If the needed size is smaller than the minimum or specified unit 23f917169ef157 Kefeng Wang 2022-01-19 3050 * size, the leftover is returned using pcpu_fc_free. 66c3a75772247c Tejun Heo 2009-03-10 3051 * 66c3a75772247c Tejun Heo 2009-03-10 3052 * RETURNS: fb435d5233f8b6 Tejun Heo 2009-08-14 3053 * 0 on success, -errno on failure. 66c3a75772247c Tejun Heo 2009-03-10 3054 */ 4ba6ce250e406b Tejun Heo 2010-06-27 3055 int __init pcpu_embed_first_chunk(size_t reserved_size, size_t dyn_size, c8826dd538602d Tejun Heo 2009-08-14 3056 size_t atom_size, c8826dd538602d Tejun Heo 2009-08-14 3057 pcpu_fc_cpu_distance_fn_t cpu_distance_fn, 23f917169ef157 Kefeng Wang 2022-01-19 3058 pcpu_fc_cpu_to_node_fn_t cpu_to_nd_fn) 66c3a75772247c Tejun Heo 2009-03-10 3059 { c8826dd538602d Tejun Heo 2009-08-14 3060 void *base = (void *)ULONG_MAX; c8826dd538602d Tejun Heo 2009-08-14 3061 void **areas = NULL; fd1e8a1fe2b54d Tejun Heo 2009-08-14 3062 struct pcpu_alloc_info *ai; 93c76b6b2faaad zijun_hu 2016-10-05 3063 size_t size_sum, areas_size; 93c76b6b2faaad zijun_hu 2016-10-05 3064 unsigned long max_distance; 163fa23435cc9c Kefeng Wang 2019-07-03 3065 int group, i, highest_group, rc = 0; 66c3a75772247c Tejun Heo 2009-03-10 3066 c8826dd538602d Tejun Heo 2009-08-14 3067 ai = pcpu_build_alloc_info(reserved_size, dyn_size, atom_size, c8826dd538602d Tejun Heo 2009-08-14 3068 cpu_distance_fn); fd1e8a1fe2b54d Tejun Heo 2009-08-14 3069 if (IS_ERR(ai)) fd1e8a1fe2b54d Tejun Heo 2009-08-14 3070 return PTR_ERR(ai); 66c3a75772247c Tejun Heo 2009-03-10 3071 fd1e8a1fe2b54d Tejun Heo 2009-08-14 3072 size_sum = ai->static_size + ai->reserved_size + ai->dyn_size; c8826dd538602d Tejun Heo 2009-08-14 3073 areas_size = PFN_ALIGN(ai->nr_groups * sizeof(void *)); fa8a7094ba1679 Tejun Heo 2009-06-22 3074 26fb3dae0a1ec7 Mike Rapoport 2019-03-11 3075 areas = memblock_alloc(areas_size, SMP_CACHE_BYTES); c8826dd538602d Tejun Heo 2009-08-14 3076 if (!areas) { fb435d5233f8b6 Tejun Heo 2009-08-14 3077 rc = -ENOMEM; c8826dd538602d Tejun Heo 2009-08-14 3078 goto out_free; fa8a7094ba1679 Tejun Heo 2009-06-22 3079 } 66c3a75772247c Tejun Heo 2009-03-10 3080 9b7396624a7b50 zijun_hu 2016-10-05 3081 /* allocate, copy and determine base address & max_distance */ 9b7396624a7b50 zijun_hu 2016-10-05 3082 highest_group = 0; c8826dd538602d Tejun Heo 2009-08-14 3083 for (group = 0; group < ai->nr_groups; group++) { c8826dd538602d Tejun Heo 2009-08-14 3084 struct pcpu_group_info *gi = &ai->groups[group]; c8826dd538602d Tejun Heo 2009-08-14 3085 unsigned int cpu = NR_CPUS; c8826dd538602d Tejun Heo 2009-08-14 3086 void *ptr; c8826dd538602d Tejun Heo 2009-08-14 3087 c8826dd538602d Tejun Heo 2009-08-14 3088 for (i = 0; i < gi->nr_units && cpu == NR_CPUS; i++) c8826dd538602d Tejun Heo 2009-08-14 3089 cpu = gi->cpu_map[i]; c8826dd538602d Tejun Heo 2009-08-14 3090 BUG_ON(cpu == NR_CPUS); c8826dd538602d Tejun Heo 2009-08-14 3091 c8826dd538602d Tejun Heo 2009-08-14 3092 /* allocate space for the whole group */ 23f917169ef157 Kefeng Wang 2022-01-19 3093 ptr = pcpu_fc_alloc(cpu, gi->nr_units * ai->unit_size, atom_size, cpu_to_nd_fn); c8826dd538602d Tejun Heo 2009-08-14 3094 if (!ptr) { c8826dd538602d Tejun Heo 2009-08-14 3095 rc = -ENOMEM; c8826dd538602d Tejun Heo 2009-08-14 3096 goto out_free_areas; c8826dd538602d Tejun Heo 2009-08-14 3097 } f528f0b8e53d73 Catalin Marinas 2011-09-26 3098 /* kmemleak tracks the percpu allocations separately */ a317ebccaa3609 Patrick Wang 2022-07-05 3099 kmemleak_ignore_phys(__pa(ptr)); c8826dd538602d Tejun Heo 2009-08-14 3100 areas[group] = ptr; c8826dd538602d Tejun Heo 2009-08-14 3101 c8826dd538602d Tejun Heo 2009-08-14 @3102 base = min(ptr, base); 9b7396624a7b50 zijun_hu 2016-10-05 3103 if (ptr > areas[highest_group]) 9b7396624a7b50 zijun_hu 2016-10-05 3104 highest_group = group; 9b7396624a7b50 zijun_hu 2016-10-05 3105 } 9b7396624a7b50 zijun_hu 2016-10-05 3106 max_distance = areas[highest_group] - base; 9b7396624a7b50 zijun_hu 2016-10-05 3107 max_distance += ai->unit_size * ai->groups[highest_group].nr_units; 9b7396624a7b50 zijun_hu 2016-10-05 3108 9b7396624a7b50 zijun_hu 2016-10-05 3109 /* warn if maximum distance is further than 75% of vmalloc space */ 9b7396624a7b50 zijun_hu 2016-10-05 3110 if (max_distance > VMALLOC_TOTAL * 3 / 4) { 9b7396624a7b50 zijun_hu 2016-10-05 3111 pr_warn("max_distance=0x%lx too large for vmalloc space 0x%lx\n", 9b7396624a7b50 zijun_hu 2016-10-05 3112 max_distance, VMALLOC_TOTAL); 9b7396624a7b50 zijun_hu 2016-10-05 3113 #ifdef CONFIG_NEED_PER_CPU_PAGE_FIRST_CHUNK 9b7396624a7b50 zijun_hu 2016-10-05 3114 /* and fail if we have fallback */ 9b7396624a7b50 zijun_hu 2016-10-05 3115 rc = -EINVAL; 9b7396624a7b50 zijun_hu 2016-10-05 3116 goto out_free_areas; 9b7396624a7b50 zijun_hu 2016-10-05 3117 #endif 42b64281453249 Tejun Heo 2012-04-27 3118 } 42b64281453249 Tejun Heo 2012-04-27 3119 42b64281453249 Tejun Heo 2012-04-27 3120 /* 42b64281453249 Tejun Heo 2012-04-27 3121 * Copy data and free unused parts. This should happen after all 42b64281453249 Tejun Heo 2012-04-27 3122 * allocations are complete; otherwise, we may end up with 42b64281453249 Tejun Heo 2012-04-27 3123 * overlapping groups. 42b64281453249 Tejun Heo 2012-04-27 3124 */ 42b64281453249 Tejun Heo 2012-04-27 3125 for (group = 0; group < ai->nr_groups; group++) { 42b64281453249 Tejun Heo 2012-04-27 3126 struct pcpu_group_info *gi = &ai->groups[group]; 42b64281453249 Tejun Heo 2012-04-27 3127 void *ptr = areas[group]; 66c3a75772247c Tejun Heo 2009-03-10 3128 c8826dd538602d Tejun Heo 2009-08-14 3129 for (i = 0; i < gi->nr_units; i++, ptr += ai->unit_size) { c8826dd538602d Tejun Heo 2009-08-14 3130 if (gi->cpu_map[i] == NR_CPUS) { c8826dd538602d Tejun Heo 2009-08-14 3131 /* unused unit, free whole */ 23f917169ef157 Kefeng Wang 2022-01-19 3132 pcpu_fc_free(ptr, ai->unit_size); c8826dd538602d Tejun Heo 2009-08-14 3133 continue; c8826dd538602d Tejun Heo 2009-08-14 3134 } c8826dd538602d Tejun Heo 2009-08-14 3135 /* copy and return the unused part */ fd1e8a1fe2b54d Tejun Heo 2009-08-14 3136 memcpy(ptr, __per_cpu_load, ai->static_size); 23f917169ef157 Kefeng Wang 2022-01-19 3137 pcpu_fc_free(ptr + size_sum, ai->unit_size - size_sum); c8826dd538602d Tejun Heo 2009-08-14 3138 } 66c3a75772247c Tejun Heo 2009-03-10 3139 } 66c3a75772247c Tejun Heo 2009-03-10 3140 c8826dd538602d Tejun Heo 2009-08-14 3141 /* base address is now known, determine group base offsets */ 6ea529a2037ce6 Tejun Heo 2009-09-24 3142 for (group = 0; group < ai->nr_groups; group++) { c8826dd538602d Tejun Heo 2009-08-14 3143 ai->groups[group].base_offset = areas[group] - base; 6ea529a2037ce6 Tejun Heo 2009-09-24 3144 } c8826dd538602d Tejun Heo 2009-08-14 3145 00206a69ee32f0 Matteo Croce 2019-03-18 3146 pr_info("Embedded %zu pages/cpu s%zu r%zu d%zu u%zu\n", 00206a69ee32f0 Matteo Croce 2019-03-18 3147 PFN_DOWN(size_sum), ai->static_size, ai->reserved_size, fd1e8a1fe2b54d Tejun Heo 2009-08-14 3148 ai->dyn_size, ai->unit_size); 66c3a75772247c Tejun Heo 2009-03-10 3149 163fa23435cc9c Kefeng Wang 2019-07-03 3150 pcpu_setup_first_chunk(ai, base); c8826dd538602d Tejun Heo 2009-08-14 3151 goto out_free; c8826dd538602d Tejun Heo 2009-08-14 3152 c8826dd538602d Tejun Heo 2009-08-14 3153 out_free_areas: c8826dd538602d Tejun Heo 2009-08-14 3154 for (group = 0; group < ai->nr_groups; group++) f851c8d8583891 Michael Holzheu 2013-09-17 3155 if (areas[group]) 23f917169ef157 Kefeng Wang 2022-01-19 3156 pcpu_fc_free(areas[group], c8826dd538602d Tejun Heo 2009-08-14 3157 ai->groups[group].nr_units * ai->unit_size); c8826dd538602d Tejun Heo 2009-08-14 3158 out_free: fd1e8a1fe2b54d Tejun Heo 2009-08-14 3159 pcpu_free_alloc_info(ai); c8826dd538602d Tejun Heo 2009-08-14 3160 if (areas) 4421cca0a3e483 Mike Rapoport 2021-11-05 3161 memblock_free(areas, areas_size); fb435d5233f8b6 Tejun Heo 2009-08-14 3162 return rc; fa8a7094ba1679 Tejun Heo 2009-06-22 3163 } 3c9a024fde58b0 Tejun Heo 2010-09-09 3164 #endif /* BUILD_EMBED_FIRST_CHUNK */ d4b95f80399471 Tejun Heo 2009-07-04 3165
Hi David, kernel test robot noticed the following build warnings: [auto build test WARNING on akpm-mm/mm-everything] [also build test WARNING on linus/master v6.5-rc3 next-20230727] [cannot apply to next-20230725] [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-Allow-min-max-clamp-if-the-arguments-have-the-same-signedness/20230725-204940 base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything patch link: https://lore.kernel.org/r/48c2cd0407f14859919d4fcbe526234a%40AcuMS.aculab.com patch subject: [PATCH next resend 5/5] minmax: Relax check to allow comparison between int and small unsigned constants. config: microblaze-randconfig-r092-20230725 (https://download.01.org/0day-ci/archive/20230728/202307281520.WNoM3bxU-lkp@intel.com/config) compiler: microblaze-linux-gcc (GCC) 12.3.0 reproduce: (https://download.01.org/0day-ci/archive/20230728/202307281520.WNoM3bxU-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/202307281520.WNoM3bxU-lkp@intel.com/ sparse warnings: (new ones prefixed by >>) >> crypto/skcipher.c:80:16: sparse: sparse: incompatible types for operation (>=): >> crypto/skcipher.c:80:16: sparse: unsigned char [usertype] *start >> crypto/skcipher.c:80:16: sparse: int >> crypto/skcipher.c:80:16: sparse: sparse: bad constant expression type >> crypto/skcipher.c:80:16: sparse: sparse: incompatible types for operation (>=): >> crypto/skcipher.c:80:16: sparse: unsigned char [usertype] *start >> crypto/skcipher.c:80:16: sparse: int >> crypto/skcipher.c:80:16: sparse: sparse: incompatible types for operation (>=): >> crypto/skcipher.c:80:16: sparse: unsigned char [usertype] *end_page >> crypto/skcipher.c:80:16: sparse: int >> crypto/skcipher.c:80:16: sparse: sparse: incompatible types for operation (>=): >> crypto/skcipher.c:80:16: sparse: unsigned char [usertype] *start >> crypto/skcipher.c:80:16: sparse: int >> crypto/skcipher.c:80:16: sparse: sparse: incompatible types for operation (>=): >> crypto/skcipher.c:80:16: sparse: unsigned char [usertype] *end_page >> crypto/skcipher.c:80:16: sparse: int crypto/skcipher.c:80:16: sparse: sparse: incompatible types for operation (>): crypto/skcipher.c:80:16: sparse: bad type __UNIQUE_ID___x297 crypto/skcipher.c:80:16: sparse: bad type __UNIQUE_ID___y298 >> crypto/skcipher.c:80:16: sparse: sparse: incompatible types for operation (>=): >> crypto/skcipher.c:80:16: sparse: unsigned char [usertype] *start >> crypto/skcipher.c:80:16: sparse: int >> crypto/skcipher.c:80:16: sparse: sparse: incompatible types for operation (>=): >> crypto/skcipher.c:80:16: sparse: unsigned char [usertype] *end_page >> crypto/skcipher.c:80:16: sparse: int crypto/skcipher.c:80:16: sparse: sparse: incompatible types for operation (>): crypto/skcipher.c:80:16: sparse: bad type __UNIQUE_ID___x297 crypto/skcipher.c:80:16: sparse: bad type __UNIQUE_ID___y298 >> crypto/skcipher.c:80:16: sparse: sparse: incompatible types for operation (>=): >> crypto/skcipher.c:80:16: sparse: unsigned char [usertype] *start >> crypto/skcipher.c:80:16: sparse: int >> crypto/skcipher.c:80:16: sparse: sparse: incompatible types for operation (>=): >> crypto/skcipher.c:80:16: sparse: unsigned char [usertype] *end_page >> crypto/skcipher.c:80:16: sparse: int crypto/skcipher.c:80:16: sparse: sparse: incompatible types for operation (>): crypto/skcipher.c:80:16: sparse: bad type __UNIQUE_ID___x297 crypto/skcipher.c:80:16: sparse: bad type __UNIQUE_ID___y298 >> crypto/skcipher.c:80:16: sparse: sparse: incompatible types for operation (>=): >> crypto/skcipher.c:80:16: sparse: unsigned char [usertype] *start >> crypto/skcipher.c:80:16: sparse: int >> crypto/skcipher.c:80:16: sparse: sparse: incompatible types for operation (>=): >> crypto/skcipher.c:80:16: sparse: unsigned char [usertype] *end_page >> crypto/skcipher.c:80:16: sparse: int crypto/skcipher.c:80:16: sparse: sparse: incompatible types for operation (>): crypto/skcipher.c:80:16: sparse: bad type __UNIQUE_ID___x297 crypto/skcipher.c:80:16: sparse: bad type __UNIQUE_ID___y298 -- drivers/gpu/drm/drm_modes.c: note: in included file (through include/drm/drm_plane.h, include/drm/drm_crtc.h): include/drm/drm_color_mgmt.h:52:16: sparse: sparse: bad integer constant expression include/drm/drm_color_mgmt.h:52:16: sparse: sparse: static assertion failed: "clamp() low limit (typeof(val))(0) greater than high limit (typeof(val))(max)" >> drivers/gpu/drm/drm_modes.c:2474:29: sparse: sparse: incompatible types for operation (>=): >> drivers/gpu/drm/drm_modes.c:2474:29: sparse: char *bpp_end_ptr >> drivers/gpu/drm/drm_modes.c:2474:29: sparse: int >> drivers/gpu/drm/drm_modes.c:2474:29: sparse: sparse: bad constant expression type >> drivers/gpu/drm/drm_modes.c:2474:29: sparse: sparse: incompatible types for operation (>=): >> drivers/gpu/drm/drm_modes.c:2474:29: sparse: char *[addressable] bpp_end_ptr >> drivers/gpu/drm/drm_modes.c:2474:29: sparse: int >> drivers/gpu/drm/drm_modes.c:2474:29: sparse: sparse: incompatible types for operation (>=): >> drivers/gpu/drm/drm_modes.c:2474:29: sparse: char *[addressable] refresh_end_ptr >> drivers/gpu/drm/drm_modes.c:2474:29: sparse: int >> drivers/gpu/drm/drm_modes.c:2474:29: sparse: sparse: incompatible types for operation (>=): >> drivers/gpu/drm/drm_modes.c:2474:29: sparse: char *[addressable] bpp_end_ptr >> drivers/gpu/drm/drm_modes.c:2474:29: sparse: int >> drivers/gpu/drm/drm_modes.c:2474:29: sparse: sparse: incompatible types for operation (>=): >> drivers/gpu/drm/drm_modes.c:2474:29: sparse: char *[addressable] refresh_end_ptr >> drivers/gpu/drm/drm_modes.c:2474:29: sparse: int drivers/gpu/drm/drm_modes.c:2474:29: sparse: sparse: incompatible types for operation (>): drivers/gpu/drm/drm_modes.c:2474:29: sparse: bad type __UNIQUE_ID___x334 drivers/gpu/drm/drm_modes.c:2474:29: sparse: bad type __UNIQUE_ID___y335 -- >> net/ceph/osdmap.c:1773:54: sparse: sparse: incompatible types for operation (>=): >> net/ceph/osdmap.c:1773:54: sparse: void * >> net/ceph/osdmap.c:1773:54: sparse: int >> net/ceph/osdmap.c:1773:54: sparse: sparse: bad constant expression type net/ceph/osdmap.c:2000:46: sparse: sparse: incompatible types for operation (>=): net/ceph/osdmap.c:2000:46: sparse: void * net/ceph/osdmap.c:2000:46: sparse: int net/ceph/osdmap.c:2000:46: sparse: sparse: bad constant expression type net/ceph/osdmap.c:2007:57: sparse: sparse: incompatible types for operation (>=): net/ceph/osdmap.c:2007:57: sparse: void * net/ceph/osdmap.c:2007:57: sparse: int net/ceph/osdmap.c:2007:57: sparse: sparse: bad constant expression type >> net/ceph/osdmap.c:1773:54: sparse: sparse: incompatible types for operation (>=): >> net/ceph/osdmap.c:1773:54: sparse: void * >> net/ceph/osdmap.c:1773:54: sparse: int >> net/ceph/osdmap.c:1773:54: sparse: sparse: incompatible types for operation (>=): >> net/ceph/osdmap.c:1773:54: sparse: void *end >> net/ceph/osdmap.c:1773:54: sparse: int >> net/ceph/osdmap.c:1773:54: sparse: sparse: incompatible types for operation (>=): >> net/ceph/osdmap.c:1773:54: sparse: void * >> net/ceph/osdmap.c:1773:54: sparse: int >> net/ceph/osdmap.c:1773:54: sparse: sparse: incompatible types for operation (>=): >> net/ceph/osdmap.c:1773:54: sparse: void *end >> net/ceph/osdmap.c:1773:54: sparse: int net/ceph/osdmap.c:1773:54: sparse: sparse: incompatible types for operation (<): net/ceph/osdmap.c:1773:54: sparse: bad type __UNIQUE_ID___x318 net/ceph/osdmap.c:1773:54: sparse: bad type __UNIQUE_ID___y319 net/ceph/osdmap.c:2000:46: sparse: sparse: incompatible types for operation (>=): net/ceph/osdmap.c:2000:46: sparse: void * net/ceph/osdmap.c:2000:46: sparse: int net/ceph/osdmap.c:2000:46: sparse: sparse: incompatible types for operation (>=): net/ceph/osdmap.c:2000:46: sparse: void *end net/ceph/osdmap.c:2000:46: sparse: int net/ceph/osdmap.c:2000:46: sparse: sparse: incompatible types for operation (>=): net/ceph/osdmap.c:2000:46: sparse: void * net/ceph/osdmap.c:2000:46: sparse: int net/ceph/osdmap.c:2000:46: sparse: sparse: incompatible types for operation (>=): net/ceph/osdmap.c:2000:46: sparse: void *end net/ceph/osdmap.c:2000:46: sparse: int net/ceph/osdmap.c:2000:46: sparse: sparse: incompatible types for operation (<): net/ceph/osdmap.c:2000:46: sparse: bad type __UNIQUE_ID___x322 net/ceph/osdmap.c:2000:46: sparse: bad type __UNIQUE_ID___y323 net/ceph/osdmap.c:2007:57: sparse: sparse: incompatible types for operation (>=): net/ceph/osdmap.c:2007:57: sparse: void * net/ceph/osdmap.c:2007:57: sparse: int net/ceph/osdmap.c:2007:57: sparse: sparse: incompatible types for operation (>=): net/ceph/osdmap.c:2007:57: sparse: void *end net/ceph/osdmap.c:2007:57: sparse: int net/ceph/osdmap.c:2007:57: sparse: sparse: incompatible types for operation (>=): net/ceph/osdmap.c:2007:57: sparse: void * net/ceph/osdmap.c:2007:57: sparse: int net/ceph/osdmap.c:2007:57: sparse: sparse: incompatible types for operation (>=): net/ceph/osdmap.c:2007:57: sparse: void *end net/ceph/osdmap.c:2007:57: sparse: int net/ceph/osdmap.c:2007:57: sparse: sparse: incompatible types for operation (<): net/ceph/osdmap.c:2007:57: sparse: bad type __UNIQUE_ID___x324 net/ceph/osdmap.c:2007:57: sparse: bad type __UNIQUE_ID___y325 -- >> lib/lzo/lzo1x_compress.c:53:54: sparse: sparse: incompatible types for operation (>=): >> lib/lzo/lzo1x_compress.c:53:54: sparse: unsigned char const *const ip_end >> lib/lzo/lzo1x_compress.c:53:54: sparse: int >> lib/lzo/lzo1x_compress.c:53:54: sparse: sparse: bad constant expression type >> lib/lzo/lzo1x_compress.c:53:54: sparse: sparse: incompatible types for operation (>=): >> lib/lzo/lzo1x_compress.c:53:54: sparse: unsigned char const *const ip_end >> lib/lzo/lzo1x_compress.c:53:54: sparse: int >> lib/lzo/lzo1x_compress.c:53:54: sparse: sparse: incompatible types for operation (>=): >> lib/lzo/lzo1x_compress.c:53:54: sparse: unsigned char const * >> lib/lzo/lzo1x_compress.c:53:54: sparse: int >> lib/lzo/lzo1x_compress.c:53:54: sparse: sparse: incompatible types for operation (>=): >> lib/lzo/lzo1x_compress.c:53:54: sparse: unsigned char const *const ip_end >> lib/lzo/lzo1x_compress.c:53:54: sparse: int >> lib/lzo/lzo1x_compress.c:53:54: sparse: sparse: incompatible types for operation (>=): >> lib/lzo/lzo1x_compress.c:53:54: sparse: unsigned char const * >> lib/lzo/lzo1x_compress.c:53:54: sparse: int lib/lzo/lzo1x_compress.c:53:54: sparse: sparse: incompatible types for operation (<): lib/lzo/lzo1x_compress.c:53:54: sparse: bad type __UNIQUE_ID___x182 lib/lzo/lzo1x_compress.c:53:54: sparse: bad type __UNIQUE_ID___y183 vim +80 crypto/skcipher.c b286d8b1a69066 Herbert Xu 2016-11-22 72 b286d8b1a69066 Herbert Xu 2016-11-22 73 /* Get a spot of the specified length that does not straddle a page. b286d8b1a69066 Herbert Xu 2016-11-22 74 * The caller needs to ensure that there is enough space for this operation. b286d8b1a69066 Herbert Xu 2016-11-22 75 */ b286d8b1a69066 Herbert Xu 2016-11-22 76 static inline u8 *skcipher_get_spot(u8 *start, unsigned int len) b286d8b1a69066 Herbert Xu 2016-11-22 77 { b286d8b1a69066 Herbert Xu 2016-11-22 78 u8 *end_page = (u8 *)(((unsigned long)(start + len - 1)) & PAGE_MASK); b286d8b1a69066 Herbert Xu 2016-11-22 79 b286d8b1a69066 Herbert Xu 2016-11-22 @80 return max(start, end_page); b286d8b1a69066 Herbert Xu 2016-11-22 81 } b286d8b1a69066 Herbert Xu 2016-11-22 82
Hi David, kernel test robot noticed the following build warnings: [auto build test WARNING on akpm-mm/mm-everything] [also build test WARNING on linus/master crng-random/master v6.5-rc3 next-20230728] [cannot apply to next-20230725] [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-Allow-min-max-clamp-if-the-arguments-have-the-same-signedness/20230725-204940 base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything patch link: https://lore.kernel.org/r/48c2cd0407f14859919d4fcbe526234a%40AcuMS.aculab.com patch subject: [PATCH next resend 5/5] minmax: Relax check to allow comparison between int and small unsigned constants. config: xtensa-randconfig-r093-20230725 (https://download.01.org/0day-ci/archive/20230728/202307281556.iTVIR4tJ-lkp@intel.com/config) compiler: xtensa-linux-gcc (GCC) 12.3.0 reproduce: (https://download.01.org/0day-ci/archive/20230728/202307281556.iTVIR4tJ-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/202307281556.iTVIR4tJ-lkp@intel.com/ sparse warnings: (new ones prefixed by >>) mm/kmemleak.c: note: in included file (through arch/xtensa/include/asm/bitops.h, include/linux/bitops.h, include/linux/kernel.h): arch/xtensa/include/asm/processor.h:103:2: sparse: sparse: Unsupported xtensa ABI arch/xtensa/include/asm/processor.h:133:2: sparse: sparse: Unsupported Xtensa ABI >> mm/kmemleak.c:1429:32: sparse: sparse: incompatible types for operation (>=): >> mm/kmemleak.c:1429:32: sparse: void * >> mm/kmemleak.c:1429:32: sparse: int >> mm/kmemleak.c:1429:32: sparse: sparse: bad constant expression type >> mm/kmemleak.c:1429:32: sparse: sparse: incompatible types for operation (>=): >> mm/kmemleak.c:1429:32: sparse: void * >> mm/kmemleak.c:1429:32: sparse: int >> mm/kmemleak.c:1429:32: sparse: sparse: incompatible types for operation (>=): >> mm/kmemleak.c:1429:32: sparse: void *end >> mm/kmemleak.c:1429:32: sparse: int >> mm/kmemleak.c:1429:32: sparse: sparse: incompatible types for operation (>=): >> mm/kmemleak.c:1429:32: sparse: void * >> mm/kmemleak.c:1429:32: sparse: int >> mm/kmemleak.c:1429:32: sparse: sparse: incompatible types for operation (>=): >> mm/kmemleak.c:1429:32: sparse: void *end >> mm/kmemleak.c:1429:32: sparse: int mm/kmemleak.c:1429:32: sparse: sparse: incompatible types for operation (<): mm/kmemleak.c:1429:32: sparse: bad type __UNIQUE_ID___x229 mm/kmemleak.c:1429:32: sparse: bad type __UNIQUE_ID___y230 vim +1429 mm/kmemleak.c 3c7b4e6b8be4c1 Catalin Marinas 2009-06-11 1396 3c7b4e6b8be4c1 Catalin Marinas 2009-06-11 1397 /* 3c7b4e6b8be4c1 Catalin Marinas 2009-06-11 1398 * Scan a memory block corresponding to a kmemleak_object. A condition is 3c7b4e6b8be4c1 Catalin Marinas 2009-06-11 1399 * that object->use_count >= 1. 3c7b4e6b8be4c1 Catalin Marinas 2009-06-11 1400 */ 3c7b4e6b8be4c1 Catalin Marinas 2009-06-11 1401 static void scan_object(struct kmemleak_object *object) 3c7b4e6b8be4c1 Catalin Marinas 2009-06-11 1402 { 3c7b4e6b8be4c1 Catalin Marinas 2009-06-11 1403 struct kmemleak_scan_area *area; 3c7b4e6b8be4c1 Catalin Marinas 2009-06-11 1404 unsigned long flags; 0c24e061196c21 Patrick Wang 2022-06-11 1405 void *obj_ptr; 3c7b4e6b8be4c1 Catalin Marinas 2009-06-11 1406 3c7b4e6b8be4c1 Catalin Marinas 2009-06-11 1407 /* 21ae2956ce289f Uwe Kleine-König 2009-10-07 1408 * Once the object->lock is acquired, the corresponding memory block 21ae2956ce289f Uwe Kleine-König 2009-10-07 1409 * cannot be freed (the same lock is acquired in delete_object). 3c7b4e6b8be4c1 Catalin Marinas 2009-06-11 1410 */ 8c96f1bc6fc49c He Zhe 2020-01-30 1411 raw_spin_lock_irqsave(&object->lock, flags); 3c7b4e6b8be4c1 Catalin Marinas 2009-06-11 1412 if (object->flags & OBJECT_NO_SCAN) 3c7b4e6b8be4c1 Catalin Marinas 2009-06-11 1413 goto out; 3c7b4e6b8be4c1 Catalin Marinas 2009-06-11 1414 if (!(object->flags & OBJECT_ALLOCATED)) 3c7b4e6b8be4c1 Catalin Marinas 2009-06-11 1415 /* already freed object */ 3c7b4e6b8be4c1 Catalin Marinas 2009-06-11 1416 goto out; 0c24e061196c21 Patrick Wang 2022-06-11 1417 0c24e061196c21 Patrick Wang 2022-06-11 1418 obj_ptr = object->flags & OBJECT_PHYS ? 0c24e061196c21 Patrick Wang 2022-06-11 1419 __va((phys_addr_t)object->pointer) : 0c24e061196c21 Patrick Wang 2022-06-11 1420 (void *)object->pointer; 0c24e061196c21 Patrick Wang 2022-06-11 1421 dba82d9431770e Catalin Marinas 2019-09-23 1422 if (hlist_empty(&object->area_list) || dba82d9431770e Catalin Marinas 2019-09-23 1423 object->flags & OBJECT_FULL_SCAN) { 0c24e061196c21 Patrick Wang 2022-06-11 1424 void *start = obj_ptr; 0c24e061196c21 Patrick Wang 2022-06-11 1425 void *end = obj_ptr + object->size; 93ada579b0eea0 Catalin Marinas 2015-06-24 1426 void *next; af98603dad87e3 Catalin Marinas 2009-08-27 1427 93ada579b0eea0 Catalin Marinas 2015-06-24 1428 do { 93ada579b0eea0 Catalin Marinas 2015-06-24 @1429 next = min(start + MAX_SCAN_SIZE, end); 93ada579b0eea0 Catalin Marinas 2015-06-24 1430 scan_block(start, next, object); 93ada579b0eea0 Catalin Marinas 2015-06-24 1431 93ada579b0eea0 Catalin Marinas 2015-06-24 1432 start = next; 93ada579b0eea0 Catalin Marinas 2015-06-24 1433 if (start >= end) 93ada579b0eea0 Catalin Marinas 2015-06-24 1434 break; af98603dad87e3 Catalin Marinas 2009-08-27 1435 8c96f1bc6fc49c He Zhe 2020-01-30 1436 raw_spin_unlock_irqrestore(&object->lock, flags); af98603dad87e3 Catalin Marinas 2009-08-27 1437 cond_resched(); 8c96f1bc6fc49c He Zhe 2020-01-30 1438 raw_spin_lock_irqsave(&object->lock, flags); 93ada579b0eea0 Catalin Marinas 2015-06-24 1439 } while (object->flags & OBJECT_ALLOCATED); af98603dad87e3 Catalin Marinas 2009-08-27 1440 } else b67bfe0d42cac5 Sasha Levin 2013-02-27 1441 hlist_for_each_entry(area, &object->area_list, node) c017b4be3e8417 Catalin Marinas 2009-10-28 1442 scan_block((void *)area->start, c017b4be3e8417 Catalin Marinas 2009-10-28 1443 (void *)(area->start + area->size), 93ada579b0eea0 Catalin Marinas 2015-06-24 1444 object); 3c7b4e6b8be4c1 Catalin Marinas 2009-06-11 1445 out: 8c96f1bc6fc49c He Zhe 2020-01-30 1446 raw_spin_unlock_irqrestore(&object->lock, flags); 3c7b4e6b8be4c1 Catalin Marinas 2009-06-11 1447 } 3c7b4e6b8be4c1 Catalin Marinas 2009-06-11 1448
diff --git a/include/linux/minmax.h b/include/linux/minmax.h index baffbe5c855d..27ebab9f21e7 100644 --- a/include/linux/minmax.h +++ b/include/linux/minmax.h @@ -7,17 +7,28 @@ /* * min()/max()/clamp() macros must accomplish three things: * - * - avoid multiple evaluations of the arguments (so side-effects like + * - Avoid multiple evaluations of the arguments (so side-effects like * "x++" happen only once) when non-constant. - * - perform signed v unsigned type-checking (to generate compile + * - 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 + * Constants from 0 to INT_MAX are cast to (int) so can be used + * in comparisons with signed types. + * - Retain result as a constant expressions when called with only * constant expressions (to avoid tripping VLA warnings in stack * allocation usage). */ -#define __types_ok(x, y) \ - (is_signed_type(typeof(x)) == is_signed_type(typeof(y)) || \ - is_signed_type(typeof((x) + 0)) == is_signed_type(typeof((y) + 0))) + +#define __is_noneg_int(x) \ + __builtin_choose_expr(!__is_constexpr(x), false, \ + ((x) >= 0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__)) + +#define __int_const(x) __builtin_choose_expr(__is_noneg_int(x), (int)(long)(x), (x)) + +#define __is_signed(x) is_signed_type(typeof(x)) +#define __types_ok(x, y) \ + (__is_signed(x) == __is_signed(y) || \ + __is_signed((x) + 0) == __is_signed((y) + 0) || \ + __is_noneg_int(x) || __is_noneg_int(y)) #define __cmp_op_min < #define __cmp_op_max > @@ -25,24 +36,24 @@ #define __cmp(op, x, y) ((x) __cmp_op_##op (y) ? (x) : (y)) #define __cmp_once(op, x, y, unique_x, unique_y) ({ \ - typeof(x) unique_x = (x); \ - typeof(y) unique_y = (y); \ + typeof(__int_const(x)) unique_x = (x); \ + typeof(__int_const(y)) unique_y = (y); \ 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(op, x, y) \ __builtin_choose_expr(__is_constexpr((x) - (y)), \ - __cmp(op, x, y), \ + __cmp(op, __int_const(x), __int_const(y)), \ __cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y))) #define __clamp(val, lo, hi) \ ((val) >= (hi) ? (hi) : ((val) <= (lo) ? (lo) : (val))) #define __clamp_once(val, lo, hi, unique_val, unique_lo, unique_hi) ({ \ - typeof(val) unique_val = (val); \ - typeof(lo) unique_lo = (lo); \ - typeof(hi) unique_hi = (hi); \ + typeof(__int_const(val)) unique_val = (val); \ + typeof(__int_const(lo)) unique_lo = (lo); \ + typeof(__int_const(hi)) unique_hi = (hi); \ static_assert(!__is_constexpr((lo) > (hi)) || (lo) <= (hi), \ "clamp() low limit " #lo " greater than high limit " #hi); \ static_assert(__types_ok(val, lo), "clamp() 'lo' signedness error"); \