From patchwork Sun Jan 28 19:34:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Laight X-Patchwork-Id: 13534618 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.86.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CB54933CC2 for ; Sun, 28 Jan 2024 19:34:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.58.86.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706470492; cv=none; b=Z6Io8+xPF44Zhakil2rp191FDpyLCxM7es/NeuR4kRlwoF4rm/OZx5WxpzI24QDVLHWDVrNATwHzgJeyP8KsjXTVAb6YZ72ZEo10QpsN79SvS07d5ekOmVAhdKuYJ3oWUk6H6l0NhsFHLdV5MzJggvyrzrruacVDrVvXYrtEkG8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706470492; c=relaxed/simple; bh=juZ2M3HUxnqIFqWU7GAGrFjPnoxq0zOmMPMgSI4HXxI=; h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To: MIME-Version:Content-Type; b=Btd6DQIt4d5UaxvAt9sC3D+x9LgaIw7+O8YbfINcu1aeaC94d5LSelwutmTMUGhLIDM1wNLyUzVTsvVybP9sLjZUHY0Lo4tgc3RxONufukQ3koQtF57kotTs55LXnbMsVjvtUuYf3uJlXQVo+J9saCylZimj56u0bLYnbh6bvTs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ACULAB.COM; spf=pass smtp.mailfrom=aculab.com; arc=none smtp.client-ip=185.58.86.151 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ACULAB.COM Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=aculab.com 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-323-SOw5q3D0MG6-hLHIb3ORig-1; Sun, 28 Jan 2024 19:34:47 +0000 X-MC-Unique: SOw5q3D0MG6-hLHIb3ORig-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; Sun, 28 Jan 2024 19:34:23 +0000 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Sun, 28 Jan 2024 19:34:23 +0000 From: David Laight To: "'linux-kernel@vger.kernel.org'" , "'Linus Torvalds'" , 'Netdev' , "'dri-devel@lists.freedesktop.org'" CC: 'Andy Shevchenko' , 'Andrew Morton' , "'Matthew Wilcox (Oracle)'" , 'Christoph Hellwig' , "'Dan Carpenter'" , 'Linus Walleij' , "'David S . Miller'" , "'linux-btrfs@vger.kernel.org'" , 'Jens Axboe' Subject: [PATCH next 09/11] tree-wide: minmax: Replace all the uses of max() for array sizes with max_const() Thread-Topic: [PATCH next 09/11] tree-wide: minmax: Replace all the uses of max() for array sizes with max_const() Thread-Index: AdpSIQx7w4lMNPy/TmCWjt5UFKRyKA== Date: Sun, 28 Jan 2024 19:34:23 +0000 Message-ID: <10638249b13c43cab9a5522271aa99e2@AcuMS.aculab.com> References: <0ca26166dd2a4ff5a674b84704ff1517@AcuMS.aculab.com> In-Reply-To: <0ca26166dd2a4ff5a674b84704ff1517@AcuMS.aculab.com> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US These are the only uses of max() that require a constant value from constant parameters. There don't seem to be any similar uses of min(). Replacing the max() by max_const() lets min()/max() be simplified speeding up compilation. max_const() will convert enums to int (or unsigned int) so that the casts added by max_t() are no longer needed. Signed-off-by: David Laight Acked-by: David Sterba --- drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c | 2 +- drivers/gpu/drm/drm_color_mgmt.c | 4 ++-- drivers/input/touchscreen/cyttsp4_core.c | 2 +- drivers/net/can/usb/etas_es58x/es58x_devlink.c | 2 +- fs/btrfs/tree-checker.c | 2 +- lib/vsprintf.c | 4 ++-- net/ipv4/proc.c | 2 +- net/ipv6/proc.c | 2 +- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c b/drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c index 00cd615bbcdc..935fb4014f7c 100644 --- a/drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c +++ b/drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c @@ -708,7 +708,7 @@ static const char *smu_get_feature_name(struct smu_context *smu, size_t smu_cmn_get_pp_feature_mask(struct smu_context *smu, char *buf) { - int8_t sort_feature[max(SMU_FEATURE_COUNT, SMU_FEATURE_MAX)]; + int8_t sort_feature[max_const(SMU_FEATURE_COUNT, SMU_FEATURE_MAX)]; uint64_t feature_mask; int i, feature_index; uint32_t count = 0; diff --git a/drivers/gpu/drm/drm_color_mgmt.c b/drivers/gpu/drm/drm_color_mgmt.c index d021497841b8..43a6bd0ca960 100644 --- a/drivers/gpu/drm/drm_color_mgmt.c +++ b/drivers/gpu/drm/drm_color_mgmt.c @@ -532,8 +532,8 @@ int drm_plane_create_color_properties(struct drm_plane *plane, { struct drm_device *dev = plane->dev; struct drm_property *prop; - struct drm_prop_enum_list enum_list[max_t(int, DRM_COLOR_ENCODING_MAX, - DRM_COLOR_RANGE_MAX)]; + struct drm_prop_enum_list enum_list[max_const(DRM_COLOR_ENCODING_MAX, + DRM_COLOR_RANGE_MAX)]; int i, len; if (WARN_ON(supported_encodings == 0 || diff --git a/drivers/input/touchscreen/cyttsp4_core.c b/drivers/input/touchscreen/cyttsp4_core.c index 7cb26929dc73..c6884c3c3fca 100644 --- a/drivers/input/touchscreen/cyttsp4_core.c +++ b/drivers/input/touchscreen/cyttsp4_core.c @@ -871,7 +871,7 @@ static void cyttsp4_get_mt_touches(struct cyttsp4_mt_data *md, int num_cur_tch) struct cyttsp4_touch tch; int sig; int i, j, t = 0; - int ids[max(CY_TMA1036_MAX_TCH, CY_TMA4XX_MAX_TCH)]; + int ids[max_const(CY_TMA1036_MAX_TCH, CY_TMA4XX_MAX_TCH)]; memset(ids, 0, si->si_ofs.tch_abs[CY_TCH_T].max * sizeof(int)); for (i = 0; i < num_cur_tch; i++) { diff --git a/drivers/net/can/usb/etas_es58x/es58x_devlink.c b/drivers/net/can/usb/etas_es58x/es58x_devlink.c index 635edeb8f68c..28fa87668bf8 100644 --- a/drivers/net/can/usb/etas_es58x/es58x_devlink.c +++ b/drivers/net/can/usb/etas_es58x/es58x_devlink.c @@ -215,7 +215,7 @@ static int es58x_devlink_info_get(struct devlink *devlink, struct es58x_sw_version *fw_ver = &es58x_dev->firmware_version; struct es58x_sw_version *bl_ver = &es58x_dev->bootloader_version; struct es58x_hw_revision *hw_rev = &es58x_dev->hardware_revision; - char buf[max(sizeof("xx.xx.xx"), sizeof("axxx/xxx"))]; + char buf[max_const(sizeof("xx.xx.xx"), sizeof("axxx/xxx"))]; int ret = 0; if (es58x_sw_version_is_valid(fw_ver)) { diff --git a/fs/btrfs/tree-checker.c b/fs/btrfs/tree-checker.c index 6eccf8496486..aec4729a9a82 100644 --- a/fs/btrfs/tree-checker.c +++ b/fs/btrfs/tree-checker.c @@ -615,7 +615,7 @@ static int check_dir_item(struct extent_buffer *leaf, */ if (key->type == BTRFS_DIR_ITEM_KEY || key->type == BTRFS_XATTR_ITEM_KEY) { - char namebuf[max(BTRFS_NAME_LEN, XATTR_NAME_MAX)]; + char namebuf[max_const(BTRFS_NAME_LEN, XATTR_NAME_MAX)]; read_extent_buffer(leaf, namebuf, (unsigned long)(di + 1), name_len); diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 552738f14275..6c3c319afd86 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -1080,8 +1080,8 @@ char *resource_string(char *buf, char *end, struct resource *res, #define FLAG_BUF_SIZE (2 * sizeof(res->flags)) #define DECODED_BUF_SIZE sizeof("[mem - 64bit pref window disabled]") #define RAW_BUF_SIZE sizeof("[mem - flags 0x]") - char sym[max(2*RSRC_BUF_SIZE + DECODED_BUF_SIZE, - 2*RSRC_BUF_SIZE + FLAG_BUF_SIZE + RAW_BUF_SIZE)]; + char sym[max_const(2*RSRC_BUF_SIZE + DECODED_BUF_SIZE, + 2*RSRC_BUF_SIZE + FLAG_BUF_SIZE + RAW_BUF_SIZE)]; char *p = sym, *pend = sym + sizeof(sym); int decode = (fmt[0] == 'R') ? 1 : 0; diff --git a/net/ipv4/proc.c b/net/ipv4/proc.c index 5f4654ebff48..a4aff27f949b 100644 --- a/net/ipv4/proc.c +++ b/net/ipv4/proc.c @@ -43,7 +43,7 @@ #include #include -#define TCPUDP_MIB_MAX max_t(u32, UDP_MIB_MAX, TCP_MIB_MAX) +#define TCPUDP_MIB_MAX max_const(UDP_MIB_MAX, TCP_MIB_MAX) /* * Report socket allocation statistics [mea@utu.fi] diff --git a/net/ipv6/proc.c b/net/ipv6/proc.c index 6d1d9221649d..7fedb60aaeac 100644 --- a/net/ipv6/proc.c +++ b/net/ipv6/proc.c @@ -27,7 +27,7 @@ #include #define MAX4(a, b, c, d) \ - max_t(u32, max_t(u32, a, b), max_t(u32, c, d)) + max_const(max_const(a, b), max_const(c, d)) #define SNMP_MIB_MAX MAX4(UDP_MIB_MAX, TCP_MIB_MAX, \ IPSTATS_MIB_MAX, ICMP_MIB_MAX) From patchwork Sun Jan 28 19:35:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: David Laight X-Patchwork-Id: 13534619 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.86.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C9B05200CC for ; Sun, 28 Jan 2024 19:36:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.58.86.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706470588; cv=none; b=npX7XFrZWzQG28VEhRpTh8paqW94HvvKuDvaNHDabARnrifrDzruNpjTS23gjhdEty07gEPtAdR8rQerz/R0sAKBqYHzA4XaGuAZQUyxqxC5wUPJzgrgHJfRTwaS1e4nPDYstGTlIGkyKwtw4Z6pn8aaR0TH/s0jt6crxfXe7So= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706470588; c=relaxed/simple; bh=QB5cBlZmX3HjIcw4VUIAA5Ehr6Qpy5RSN9Fbvir6iZk=; h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To: MIME-Version:Content-Type; b=ZtAtMQjO3rpLPGLDubQ2G2r9uohFxPRUWRK3q0zQKz/vErLQX7zfPoYrgQkFH8MEjnrvKx4xPZCCvrwgem2ViEve2w4Jj+av/7JEBdqwvQi7zOTkFIMS7r199TrVVLgG0+0JGfP529KrrpYaKd2TB4x7HlUwY8lSLdRGkozqOZ8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ACULAB.COM; spf=pass smtp.mailfrom=aculab.com; arc=none smtp.client-ip=185.58.86.151 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ACULAB.COM Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=aculab.com 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-253-wsGkhBltNxSy1X4pYfIzig-1; Sun, 28 Jan 2024 19:36:22 +0000 X-MC-Unique: wsGkhBltNxSy1X4pYfIzig-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; Sun, 28 Jan 2024 19:35:38 +0000 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Sun, 28 Jan 2024 19:35:38 +0000 From: David Laight To: "'linux-kernel@vger.kernel.org'" , "'Linus Torvalds'" , 'Netdev' , "'dri-devel@lists.freedesktop.org'" CC: 'Andy Shevchenko' , 'Andrew Morton' , "'Matthew Wilcox (Oracle)'" , 'Christoph Hellwig' , "'Dan Carpenter'" , 'Linus Walleij' , "'David S . Miller'" , "'linux-btrfs@vger.kernel.org'" , 'Jens Axboe' Subject: [PATCH next 10/11] block: Use a boolean expression instead of max() on booleans Thread-Topic: [PATCH next 10/11] block: Use a boolean expression instead of max() on booleans Thread-Index: AdpSITDgD70hEVnBTjm/gYoTnRBnpg== Date: Sun, 28 Jan 2024 19:35:38 +0000 Message-ID: References: <0ca26166dd2a4ff5a674b84704ff1517@AcuMS.aculab.com> In-Reply-To: <0ca26166dd2a4ff5a674b84704ff1517@AcuMS.aculab.com> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US blk_stack_limits() contains: t->zoned = max(t->zoned, b->zoned); These are bool, so it is just a bitwise or. However it generates: error: comparison of constant ‘0’ with boolean expression is always true [-Werror=bool-compare] inside the signedness check that max() does unless a '+ 0' is added. It is a shame the compiler generates this warning for code that will be optimised away. Change so that the extra '+ 0' can be removed. Signed-off-by: David Laight --- block/blk-settings.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/blk-settings.c b/block/blk-settings.c index 06ea91e51b8b..9ca21fea039d 100644 --- a/block/blk-settings.c +++ b/block/blk-settings.c @@ -688,7 +688,7 @@ int blk_stack_limits(struct queue_limits *t, struct queue_limits *b, b->max_secure_erase_sectors); t->zone_write_granularity = max(t->zone_write_granularity, b->zone_write_granularity); - t->zoned = max(t->zoned, b->zoned); + t->zoned = t->zoned | b->zoned; return ret; } EXPORT_SYMBOL(blk_stack_limits); From patchwork Sun Jan 28 19:36:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Laight X-Patchwork-Id: 13534620 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.86.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3C9CF33CD3 for ; Sun, 28 Jan 2024 19:37:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.58.86.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706470634; cv=none; b=gzcAV/NBvSr6R7GXxw0cN94HqeEtdgWeiYcZuB0jAS28P4FeQi0qOeFPGjMK35op9MGpS2i2zMe10LChvQrxkCZ3891hum4M5sXpzrIX7F8rB1X3K/bowagruM1I2IN9bosu8/lry2EfELxLo4YNN0BJm6lZC5LRXaQpr2xgnpk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706470634; c=relaxed/simple; bh=ZrixvhkJhbKZGck4jka4XG69l4/CfS4dYctLM5kLuEc=; h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To: MIME-Version:Content-Type; b=JBeMh5bC7lXUm3FJlFbWWd+8ka/mCuH6nDyDDBwMdoDSEDY8mF1IRiBD0Q9peiIWQ5Ae5ZkpZeHeyWo78APfmv8frYyri9+cBb3pc2cn2umexB1YeMbY60ONKSX2r2RctpD4WM5iizWvMFwgnEJaLKxS8c0ERm1ZOV2hs/pnOYM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ACULAB.COM; spf=pass smtp.mailfrom=aculab.com; arc=none smtp.client-ip=185.58.86.151 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ACULAB.COM Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=aculab.com 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-227-RgW8bFtTPC263FLYeWYyZg-1; Sun, 28 Jan 2024 19:37:05 +0000 X-MC-Unique: RgW8bFtTPC263FLYeWYyZg-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; Sun, 28 Jan 2024 19:36:41 +0000 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Sun, 28 Jan 2024 19:36:41 +0000 From: David Laight To: "'linux-kernel@vger.kernel.org'" , "'Linus Torvalds'" , 'Netdev' , "'dri-devel@lists.freedesktop.org'" CC: 'Andy Shevchenko' , 'Andrew Morton' , "'Matthew Wilcox (Oracle)'" , 'Christoph Hellwig' , "'Dan Carpenter'" , 'Linus Walleij' , "'David S . Miller'" , "'linux-btrfs@vger.kernel.org'" , 'Jens Axboe' Subject: [PATCH next 11/11] minmax: min() and max() don't need to return constant expressions Thread-Topic: [PATCH next 11/11] minmax: min() and max() don't need to return constant expressions Thread-Index: AdpSIVojuBa8D6X6RNmhjGfjyElxVg== Date: Sun, 28 Jan 2024 19:36:41 +0000 Message-ID: <30b5bc6c60a147f9985b47fb1cc08d2e@AcuMS.aculab.com> References: <0ca26166dd2a4ff5a674b84704ff1517@AcuMS.aculab.com> In-Reply-To: <0ca26166dd2a4ff5a674b84704ff1517@AcuMS.aculab.com> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US After changing the handful of places max() was used to size an on-stack array to use max_const() it is no longer necessary for min() and max() to return constant expressions from constant inputs. Remove the associated logic to reduce the expanded text. Remove the 'hack' that allowed max(bool, bool). Fixup the initial block comment to match current reality. Signed-off-by: David Laight --- include/linux/minmax.h | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/include/linux/minmax.h b/include/linux/minmax.h index c08916588425..5e65c98ff256 100644 --- a/include/linux/minmax.h +++ b/include/linux/minmax.h @@ -8,13 +8,10 @@ #include /* - * min()/max()/clamp() macros must accomplish three things: + * min()/max()/clamp() macros must accomplish several things: * * - Avoid multiple evaluations of the arguments (so side-effects like * "x++" happen only once) when non-constant. - * - Retain result as a constant expressions when called with only - * constant expressions (to avoid tripping VLA warnings in stack - * allocation usage). * - Perform signed v unsigned type-checking (to generate compile * errors instead of nasty runtime surprises). * - Unsigned char/short are always promoted to signed int and can be @@ -22,13 +19,19 @@ * - Unsigned arguments can be compared against non-negative signed constants. * - Comparison of a signed argument against an unsigned constant fails * even if the constant is below __INT_MAX__ and could be cast to int. + * + * The return value of min()/max() is not a constant expression for + * constant parameters - so will trigger a VLA warging if used to size + * an on-stack array. + * Instead use min_const() or max_const() which do generate constant + * expressions and are also valid for static initialisers. */ #define __typecheck(x, y) \ (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1))) /* Allow unsigned compares against non-negative signed constants. */ #define __is_ok_unsigned(x) \ - (is_unsigned_type(typeof(x)) || (__is_constexpr(x) ? (x) + 0 >= 0 : 0)) + (is_unsigned_type(typeof(x)) || (__is_constexpr(x) ? (x) >= 0 : 0)) /* Check for signed after promoting unsigned char/short to int */ #define __is_ok_signed(x) is_signed_type(typeof((x) + 0)) @@ -53,12 +56,10 @@ typeof(y) __y_##uniq = (y); \ __cmp(op, __x_##uniq, __y_##uniq); }) -#define __careful_cmp(op, x, y, uniq) \ - __builtin_choose_expr(__is_constexpr((x) - (y)), \ - __cmp(op, x, y), \ - ({ _Static_assert(__types_ok(x, y), \ - #op "(" #x ", " #y ") signedness error, fix types or consider u" #op "() before " #op "_t()"); \ - __cmp_once(op, x, y, uniq); })) +#define __careful_cmp(op, x, y, uniq) ({ \ + _Static_assert(__types_ok(x, y), \ + #op "(" #x ", " #y ") signedness error, fix types or consider u" #op "() before " #op "_t()"); \ + __cmp_once(op, x, y, uniq); }) #define __careful_cmp_const(op, x, y) \ (BUILD_BUG_ON_ZERO(!__is_constexpr((x) - (y))) + \