From patchwork Mon Nov 18 19:11:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Laight X-Patchwork-Id: 13878983 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2ABF5D591AD for ; Mon, 18 Nov 2024 19:11:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B3A766B008A; Mon, 18 Nov 2024 14:11:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AEA736B008C; Mon, 18 Nov 2024 14:11:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 98A696B0093; Mon, 18 Nov 2024 14:11:33 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 73F2C6B008A for ; Mon, 18 Nov 2024 14:11:33 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 025E7A04A6 for ; Mon, 18 Nov 2024 19:11:32 +0000 (UTC) X-FDA: 82800157398.08.DE1AA14 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.86.151]) by imf01.hostedemail.com (Postfix) with ESMTP id 3571740007 for ; Mon, 18 Nov 2024 19:10:52 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=aculab.com; spf=pass (imf01.hostedemail.com: domain of david.laight@aculab.com designates 185.58.86.151 as permitted sender) smtp.mailfrom=david.laight@aculab.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731956908; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=z33N7mgF2KOq9AaIi5l929I/cDq7Ura0ZVwAuZiFio8=; b=4U3gfOWwIeuR468ZFcMd7GgSrIZnhjZaQMPnukcH26N/9Q2QnMcrhJ+0X1iWM6MwaA2gKD L8yehkK4en+zuUVvc3EhaP2ubnq4cfzy/nnnyKowqZz+CKY1rMAkqBCeUVVhETy+bDlGPA tJ5schyLC6c2SHwzlKXxcqSeijmm9xY= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=aculab.com; spf=pass (imf01.hostedemail.com: domain of david.laight@aculab.com designates 185.58.86.151 as permitted sender) smtp.mailfrom=david.laight@aculab.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731956908; a=rsa-sha256; cv=none; b=NoZ3gPAqLfrB/KydEkLUinHi5Kxxl4tz66ZCggXGCp08bNpmgK+YRVgFHCRmPj2hf5FbQc RIkGH06RrzhLV+/jvFuhN2azTeMjuukfV2qzHHIWSMpSugdliu0OPalWV8aimP8Itekcv0 0yZhFZzBx3D9HtEBAZeUIF6SIAzMcKY= 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-13-pwgGBRruNOqD6Np7u3lSnQ-1; Mon, 18 Nov 2024 19:11:25 +0000 X-MC-Unique: pwgGBRruNOqD6Np7u3lSnQ-1 X-Mimecast-MFC-AGG-ID: pwgGBRruNOqD6Np7u3lSnQ 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; Mon, 18 Nov 2024 19:11:24 +0000 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Mon, 18 Nov 2024 19:11:24 +0000 From: David Laight To: Linus Torvalds CC: 'Arnd Bergmann' , "'linux-kernel@vger.kernel.org'" , 'Jens Axboe' , "'Matthew Wilcox'" , 'Christoph Hellwig' , 'Andrew Morton' , 'Andy Shevchenko' , 'Dan Carpenter' , "'Jason A . Donenfeld'" , "'pedro.falcato@gmail.com'" , 'Mateusz Guzik' , "'linux-mm@kvack.org'" , "'Lorenzo Stoakes'" Subject: [PATCH next 1/7] minmax.h: Add whitespace around operators and after commas Thread-Topic: [PATCH next 1/7] minmax.h: Add whitespace around operators and after commas Thread-Index: Ads57aZG7lyHiUjzR+iewqg1n0YFUQ== Date: Mon, 18 Nov 2024 19:11:24 +0000 Message-ID: References: In-Reply-To: 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-MFC-PROC-ID: fgKjrjAVkrkyhQVmcNFeJMuIstvGMNSGRy8ef11FnPY_1731957084 X-Mimecast-Originator: aculab.com Content-Language: en-US X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 3571740007 X-Stat-Signature: qy9r9b7ixkmjoqfpgue4fbjrdy8tm3sj X-Rspam-User: X-HE-Tag: 1731957052-545690 X-HE-Meta: U2FsdGVkX19Lcsjyk6DHMlDDvgN3EkaN3Mp1mm/CbXX8e74ITqoVrnizqLUbwU6lmdg8cyyLH5OfvotkzdjxRo57pW5pF0yoarHQBuxQVLJC7FANLMvG5Rdtlq7zuBdSVCIMDY/o3ep+JvwvkNnR/VVK9ofZF4z6JMlyNPa53PsOQAp7IVSa6OF6XEE6mSFYaGzhZujH8Am8SuloiKlNHS6LOWk925xP5vrfp+wuvUqK847cwVxjW1KnmqmcnbimbGFC1h7qgR3t1jIADqG9/8TySSSte9hMpvpw/oVmFDzwfd1vB0XyDAbVrs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As/Fyogzd1lSd8kYTNJw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Signed-off-by: David Laight --- include/linux/minmax.h | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/include/linux/minmax.h b/include/linux/minmax.h index 98008dd92153..51b0d988e322 100644 --- a/include/linux/minmax.h +++ b/include/linux/minmax.h @@ -51,10 +51,10 @@ * only need to be careful to not cause warnings for * pointer use. */ -#define __signed_type_use(x,ux) (2+__is_nonneg(x,ux)) -#define __unsigned_type_use(x,ux) (1+2*(sizeof(ux)<4)) -#define __sign_use(x,ux) (is_signed_type(typeof(ux))? \ - __signed_type_use(x,ux):__unsigned_type_use(x,ux)) +#define __signed_type_use(x, ux) (2 + __is_nonneg(x, ux)) +#define __unsigned_type_use(x, ux) (1 + 2 * (sizeof(ux) < 4)) +#define __sign_use(x, ux) (is_signed_type(typeof(ux)) ? \ + __signed_type_use(x, ux) : __unsigned_type_use(x, ux)) /* * To avoid warnings about casting pointers to integers @@ -74,15 +74,15 @@ #ifdef CONFIG_64BIT #define __signed_type(ux) long #else - #define __signed_type(ux) typeof(__builtin_choose_expr(sizeof(ux)>4,1LL,1L)) + #define __signed_type(ux) typeof(__builtin_choose_expr(sizeof(ux) > 4, 1LL, 1L)) #endif -#define __is_nonneg(x,ux) statically_true((__signed_type(ux))(x)>=0) +#define __is_nonneg(x, ux) statically_true((__signed_type(ux))(x) >= 0) -#define __types_ok(x,y,ux,uy) \ - (__sign_use(x,ux) & __sign_use(y,uy)) +#define __types_ok(x, y, ux, uy) \ + (__sign_use(x, ux) & __sign_use(y, uy)) -#define __types_ok3(x,y,z,ux,uy,uz) \ - (__sign_use(x,ux) & __sign_use(y,uy) & __sign_use(z,uz)) +#define __types_ok3(x, y, z, ux, uy, uz) \ + (__sign_use(x, ux) & __sign_use(y, uy) & __sign_use(z, uz)) #define __cmp_op_min < #define __cmp_op_max > @@ -97,7 +97,7 @@ #define __careful_cmp_once(op, x, y, ux, uy) ({ \ __auto_type ux = (x); __auto_type uy = (y); \ - BUILD_BUG_ON_MSG(!__types_ok(x,y,ux,uy), \ + BUILD_BUG_ON_MSG(!__types_ok(x, y, ux, uy), \ #op"("#x", "#y") signedness error"); \ __cmp(op, ux, uy); }) @@ -114,7 +114,7 @@ static_assert(__builtin_choose_expr(__is_constexpr((lo) > (hi)), \ (lo) <= (hi), true), \ "clamp() low limit " #lo " greater than high limit " #hi); \ - BUILD_BUG_ON_MSG(!__types_ok3(val,lo,hi,uval,ulo,uhi), \ + BUILD_BUG_ON_MSG(!__types_ok3(val, lo, hi, uval, ulo, uhi), \ "clamp("#val", "#lo", "#hi") signedness error"); \ __clamp(uval, ulo, uhi); }) @@ -154,7 +154,7 @@ #define __careful_op3(op, x, y, z, ux, uy, uz) ({ \ __auto_type ux = (x); __auto_type uy = (y);__auto_type uz = (z);\ - BUILD_BUG_ON_MSG(!__types_ok3(x,y,z,ux,uy,uz), \ + BUILD_BUG_ON_MSG(!__types_ok3(x, y, z, ux, uy, uz), \ #op"3("#x", "#y", "#z") signedness error"); \ __cmp(op, ux, __cmp(op, uy, uz)); }) @@ -326,9 +326,9 @@ static inline bool in_range32(u32 val, u32 start, u32 len) * Use these carefully: no type checking, and uses the arguments * multiple times. Use for obvious constants only. */ -#define MIN(a,b) __cmp(min,a,b) -#define MAX(a,b) __cmp(max,a,b) -#define MIN_T(type,a,b) __cmp(min,(type)(a),(type)(b)) -#define MAX_T(type,a,b) __cmp(max,(type)(a),(type)(b)) +#define MIN(a, b) __cmp(min, a, b) +#define MAX(a, b) __cmp(max, a, b) +#define MIN_T(type, a, b) __cmp(min, (type)(a), (type)(b)) +#define MAX_T(type, a, b) __cmp(max, (type)(a), (type)(b)) #endif /* _LINUX_MINMAX_H */ From patchwork Mon Nov 18 19:12:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Laight X-Patchwork-Id: 13878984 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B797ED591AD for ; Mon, 18 Nov 2024 19:12:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 51F3E6B0093; Mon, 18 Nov 2024 14:12:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4CF716B0095; Mon, 18 Nov 2024 14:12:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 397886B0096; Mon, 18 Nov 2024 14:12:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 178586B0093 for ; Mon, 18 Nov 2024 14:12:16 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id CBECEACE91 for ; Mon, 18 Nov 2024 19:12:15 +0000 (UTC) X-FDA: 82800160506.04.B5CC3E7 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.86.151]) by imf17.hostedemail.com (Postfix) with ESMTP id 84A6A40012 for ; Mon, 18 Nov 2024 19:11:35 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=aculab.com; spf=pass (imf17.hostedemail.com: domain of david.laight@aculab.com designates 185.58.86.151 as permitted sender) smtp.mailfrom=david.laight@aculab.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731957043; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VLsFOgRWaKjCZEStmR6xIL41uZE8Bm39Z0Bsb4xM78k=; b=rRzz3hAYvV5LK94642VXLI14fjiimgXPHi8IotL76Az1H//3w0bQawkxUIPCPmEGepdX5f rgdIga5JsCUSMNW2nHurTBXtgdroTB+yy/esdc/PJ/wQB8hwkvw2W6Hs6nUqVlamssm9dS iGuuWb/s1PhjMOWuV95hWrgiZBvcHOg= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=aculab.com; spf=pass (imf17.hostedemail.com: domain of david.laight@aculab.com designates 185.58.86.151 as permitted sender) smtp.mailfrom=david.laight@aculab.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731957043; a=rsa-sha256; cv=none; b=67j+PxspV+73Pvinn5PZSBS7CmVynqiiH4fhTEpcwLYinUeL4eFZc2vgCb1Vm745kbW8ow gwcd0I2QGbLcgsP7P04KG/rmBmh1CZ7LZv0v+sf1b3S3ut1o/7oeLQ5tXSyhx2eACdsscy 39+/I6bqGy28BkECTYqTshfc6xWBG/M= 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-131-lyN8MeafO_qKA23yXAR8qw-1; Mon, 18 Nov 2024 19:12:08 +0000 X-MC-Unique: lyN8MeafO_qKA23yXAR8qw-1 X-Mimecast-MFC-AGG-ID: lyN8MeafO_qKA23yXAR8qw 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; Mon, 18 Nov 2024 19:12:07 +0000 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Mon, 18 Nov 2024 19:12:07 +0000 From: David Laight To: Linus Torvalds CC: 'Arnd Bergmann' , "'linux-kernel@vger.kernel.org'" , 'Jens Axboe' , "'Matthew Wilcox'" , 'Christoph Hellwig' , 'Andrew Morton' , 'Andy Shevchenko' , 'Dan Carpenter' , "'Jason A . Donenfeld'" , "'pedro.falcato@gmail.com'" , 'Mateusz Guzik' , "'linux-mm@kvack.org'" , "'Lorenzo Stoakes'" Subject: [PATCH next 2/7] minmax.h: Update some comments Thread-Topic: [PATCH next 2/7] minmax.h: Update some comments Thread-Index: Ads57cA01trJ5zhURpGnEK/DpxxPAQ== Date: Mon, 18 Nov 2024 19:12:07 +0000 Message-ID: <85b050c81c1d4076aeb91a6cded45fee@AcuMS.aculab.com> References: In-Reply-To: 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-MFC-PROC-ID: Gye7onJebyoynL6Yb4X9XFsIISgAcmbMkI1XVDJFG-I_1731957127 X-Mimecast-Originator: aculab.com Content-Language: en-US X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 84A6A40012 X-Stat-Signature: e9ar8ywodj8kiar66p6xzn5rrn6a56wq X-HE-Tag: 1731957095-372668 X-HE-Meta: U2FsdGVkX1920eXoeY+9Auu90mCxuT03tRnNiDLhZCQyUEjvACwpCu5Eo2yfDKnnfZ3LRbNmTpV66gmnsoogS46TEUsJXEA1QtcZYLBmaR2qqCHWaeQwbqfaluSS61KD7sv5vYuTpqx83b/800DRmD9jWMv4H5ImhG4NECv52FeCyUZzHsmt+i4JFQS8qXKtRACDI4W72c6VaBw0TxDHN771mOmJsy45ZuzyeL0RF77/F+ULjWkjftP6+hszqnbhbEeQcRavQ/HssFmx4MDKM87PCWVib1JdeJgxafHLLBRM3WV18ghS096R0XxZ+Jh0igZZIV97mB44qSTeK0uxEZFMbLhualvklYWiyOGL0mNwd1m9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: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: - Change three to several. - Remove the comment about retaining constant expressions, no longer true. - Realign to nearer 80 columns and break on major punctiation. - Add a leading comment to the block before __signed_type() and __is_nonneg() Otherwise the block explaining the cast is a bit 'floating'. Reword the rest of that comment to improve readability. Signed-off-by: David Laight --- include/linux/minmax.h | 53 +++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 29 deletions(-) diff --git a/include/linux/minmax.h b/include/linux/minmax.h index 51b0d988e322..24e4b372649a 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 @@ -31,25 +28,23 @@ * bit #0 set if ok for unsigned comparisons * bit #1 set if ok for signed comparisons * - * In particular, statically non-negative signed integer - * expressions are ok for both. + * In particular, statically non-negative signed integer expressions + * are ok for both. * - * NOTE! Unsigned types smaller than 'int' are implicitly - * converted to 'int' in expressions, and are accepted for - * signed conversions for now. This is debatable. + * NOTE! Unsigned types smaller than 'int' are implicitly converted to 'int' + * in expressions, and are accepted for signed conversions for now. + * This is debatable. * - * Note that 'x' is the original expression, and 'ux' is - * the unique variable that contains the value. + * Note that 'x' is the original expression, and 'ux' is the unique variable + * that contains the value. * - * We use 'ux' for pure type checking, and 'x' for when - * we need to look at the value (but without evaluating - * it for side effects! Careful to only ever evaluate it - * with sizeof() or __builtin_constant_p() etc). + * We use 'ux' for pure type checking, and 'x' for when we need to look at the + * value (but without evaluating it for side effects! + * Careful to only ever evaluate it with sizeof() or __builtin_constant_p() etc). * - * Pointers end up being checked by the normal C type - * rules at the actual comparison, and these expressions - * only need to be careful to not cause warnings for - * pointer use. + * Pointers end up being checked by the normal C type rules at the actual + * comparison, and these expressions only need to be careful to not cause + * warnings for pointer use. */ #define __signed_type_use(x, ux) (2 + __is_nonneg(x, ux)) #define __unsigned_type_use(x, ux) (1 + 2 * (sizeof(ux) < 4)) @@ -57,19 +52,19 @@ __signed_type_use(x, ux) : __unsigned_type_use(x, ux)) /* - * To avoid warnings about casting pointers to integers - * of different sizes, we need that special sign type. + * Check whether a signed value is always non-negative. * - * On 64-bit we can just always use 'long', since any - * integer or pointer type can just be cast to that. + * A cast is needed to avoid any warnings from values that aren't signed + * integer types (in which case the result doesn't matter). * - * This does not work for 128-bit signed integers since - * the cast would truncate them, but we do not use s128 - * types in the kernel (we do use 'u128', but they will - * be handled by the !is_signed_type() case). + * On 64-bit any integer or pointer type can safely be cast to 'long'. + * But on 32-bit we need to avoid warnings about casting pointers to integers + * of different sizes without truncating 64-bit values so 'long' or 'long long' + * must be used depending on the size of the value. * - * NOTE! The cast is there only to avoid any warnings - * from when values that aren't signed integer types. + * This does not work for 128-bit signed integers since the cast would truncate + * them, but we do not use s128 types in the kernel (we do use 'u128', + * but they are handled by the !is_signed_type() case). */ #ifdef CONFIG_64BIT #define __signed_type(ux) long From patchwork Mon Nov 18 19:12:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Laight X-Patchwork-Id: 13878985 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C7B65D591AC for ; Mon, 18 Nov 2024 19:12:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 595A76B0095; Mon, 18 Nov 2024 14:12:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 545676B0096; Mon, 18 Nov 2024 14:12:57 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3E6E06B0099; Mon, 18 Nov 2024 14:12:57 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 21C206B0096 for ; Mon, 18 Nov 2024 14:12:57 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id CE039AC994 for ; Mon, 18 Nov 2024 19:12:56 +0000 (UTC) X-FDA: 82800159708.17.5A0BACB Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.86.151]) by imf08.hostedemail.com (Postfix) with ESMTP id 51CED160006 for ; Mon, 18 Nov 2024 19:12:21 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=none; spf=pass (imf08.hostedemail.com: domain of david.laight@aculab.com designates 185.58.86.151 as permitted sender) smtp.mailfrom=david.laight@aculab.com; dmarc=pass (policy=none) header.from=aculab.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731957114; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MC36Hplj10fV2ksNU9xBGYy7o0UNgQO/YpkVzJnfO/w=; b=TVT5fMQtiVdnRbEH/4PDerNE3oibj4tSR2MC7LYbkuW1edMe9DPgaPHnmKbH2dCFTKx1+R neSUANHfOLA3NX/kdqI/umNCWp/AOvYWyKiy6VRBhoO3kH3cTDnBWLofio3j3x2Y+N21TX RztIdLkXeiIG2V5iToZmcuIPKajJUnE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731957114; a=rsa-sha256; cv=none; b=UTx6C7Yhf/8J/0UY+oRAuyolN8WvVCw5E82fcVN3KVFUuZhFjZXBKZ0r9+fnl1BGk1oOGN 24uz+oHTtAZQg/SyRVUnfAlxXrTrjrApnfZi7g/CoQ9sATFSP3aSXhoogpfd4xy4LnMxhi GfXc73QLOXsZ274o0KiTugeXa+LIErU= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=none; spf=pass (imf08.hostedemail.com: domain of david.laight@aculab.com designates 185.58.86.151 as permitted sender) smtp.mailfrom=david.laight@aculab.com; dmarc=pass (policy=none) header.from=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-27-JS3bqrNRMXmEnncm00apUg-1; Mon, 18 Nov 2024 19:12:51 +0000 X-MC-Unique: JS3bqrNRMXmEnncm00apUg-1 X-Mimecast-MFC-AGG-ID: JS3bqrNRMXmEnncm00apUg 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; Mon, 18 Nov 2024 19:12:50 +0000 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Mon, 18 Nov 2024 19:12:50 +0000 From: David Laight To: Linus Torvalds CC: 'Arnd Bergmann' , "'linux-kernel@vger.kernel.org'" , 'Jens Axboe' , "'Matthew Wilcox'" , 'Christoph Hellwig' , 'Andrew Morton' , 'Andy Shevchenko' , 'Dan Carpenter' , "'Jason A . Donenfeld'" , "'pedro.falcato@gmail.com'" , 'Mateusz Guzik' , "'linux-mm@kvack.org'" , "'Lorenzo Stoakes'" Subject: [PATCH next 3/7] minmax.h: Reduce the #define expansion of min(), max() and clamp() Thread-Topic: [PATCH next 3/7] minmax.h: Reduce the #define expansion of min(), max() and clamp() Thread-Index: Ads57dnbMgzUo0QtRCKjFtFmfCRzXg== Date: Mon, 18 Nov 2024 19:12:50 +0000 Message-ID: <051afc171806425da991908ed8688a98@AcuMS.aculab.com> References: In-Reply-To: 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-MFC-PROC-ID: H8SxEPoWcF743HTflWPuYhgGU3BYrh1U6xX_ncpeOAs_1731957170 X-Mimecast-Originator: aculab.com Content-Language: en-US X-Stat-Signature: mukmgpbz3xpzwq9nxbbsjdeeeegr61es X-Rspam-User: X-Rspamd-Queue-Id: 51CED160006 X-Rspamd-Server: rspam02 X-HE-Tag: 1731957141-666431 X-HE-Meta: U2FsdGVkX18hU7c/Na2+Lp4ZIu8BJrszHqG/JZSu5aqjh6fEhClG7TyxCpTDRnAEMAp2fBXjudVct2zctrSTffwwsJVb7fQuy1+0sRNxq+dA+sCup9XQDZV9jQ2qY1VznLRYncxCc1+wK3mNaiVR5GAuMEMO5R2B1bkYBsTjhkGPvZMQhpQ5S0vlnXYEN2uPWvvIbB8Sm/pPeIWnLcct9xqqhND3Mar3vKpkzkFBRvowYtcwDwUwjATMAoByzaNAJKPJ7L8EEWFrlfUnjrQNdYotuDZNqNP8FHy7JbVbBMOESFZ/BSNh0BSCuGgDZ1C/nPyZ14ImCjkxcqf2kiQ6/tVfPB6AIuQnZvOEIlNrHOhz30SGjrApr5wkZCVpQbLukRUou/G2BwoX8sSFjmCDWi9Zkrp4MJECGQZugaQub3PcL/z2IyaCCGijyacSAtXJtBZFsHlZKtsAgNRmIyeg8lh7Y5fyDLIXsp2H/3fgra3GPmR3ddktFhLHV9PVwzQ1NHlKO6TF9Q9ZPzpeXOPgzykfPejJru4Z8CHAaorh6OkCPpiQwjw47xgLoINt/4Fxf5Z7iYqPZG52x9fcIobn30xVjzsgheSrAkyR/VkxFUCWv5G77gXEjBt5FnoMfYQp9qTjI/rPaiYnWd5VL60I8DfZi13MZQluiVtdvoV2QU0lz1AabXozsfiqIlGz41c67dz+kKxfs+oqxfTIWdMDO46LUH37y0XM3BlvI6HB475UpKBtkV1J+TSy3W5ifwe1cREFKw6R1SAnZNieOUu/M4rYK89Jp1I5JeTRkiVh1XYRd/OnZG7clrm5exa4y3Jlelpc7scGObctIsV/BAA0HEsAle8NqWiSFMTBKKy2QJRDwNX9Jg/AhoiCt4uyI1P/pfkph3sWEvkn0pO3rIWhHGFOhsLfV7Cv2BXOwFKx5t9i6WbgZ/X0ubbGe7nGRd34+DXNbLuaR4ta7w/0tB7 rtdgVQU4 MfDklpkQ6BXBcddkuoeeHMLryPCkOtSZ3N7vVtsmPc7VmUOTS15K1BcjEiJLa761+dx4WRqlksZN6bIR2Cy7RSjQayrx1IO3kJVCHN63iKK1AH0Bdu8jF0fcU+9loJ/SjA43xvRL/RdXZBNhmIcYOlUOHR9jTodIMjJ9K58JjFji1vSm3YNQD1grxEAG0Tu4CpML3l7rHSbfIouAc1BgUGekfOvJhnX/LotCdBRHok7jKmcfvXx/J7+CCAZ0rhQ9bryoUIddu8Jjr4iXTY2y0vUMgiAG4rJbFZrDc0FmZ2d1FJHKpflqEjiJjQis7RRk+NBogKZV59So603LBtxNLFWjMzz+LT02C6BRGUJQ23zwCvBzLEzDQ1oECIqS90nydHKCGPwjgX7MYDbxy/SQTG7NH0gvfJWyRWi9BlioUMVJdHKuR4SeOkKUhxQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Since the test for signed values being non-negative only relies on __builtion_constant_p() (not is_constexpr()) it can use the 'ux' variable instead of the caller supplied expression. This means that the #define parameters are only expanded twice. Once in the code and once quoted in the error message. Signed-off-by: David Laight --- include/linux/minmax.h | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/include/linux/minmax.h b/include/linux/minmax.h index 24e4b372649a..6f7ea669d305 100644 --- a/include/linux/minmax.h +++ b/include/linux/minmax.h @@ -46,10 +46,10 @@ * comparison, and these expressions only need to be careful to not cause * warnings for pointer use. */ -#define __signed_type_use(x, ux) (2 + __is_nonneg(x, ux)) -#define __unsigned_type_use(x, ux) (1 + 2 * (sizeof(ux) < 4)) -#define __sign_use(x, ux) (is_signed_type(typeof(ux)) ? \ - __signed_type_use(x, ux) : __unsigned_type_use(x, ux)) +#define __signed_type_use(ux) (2 + __is_nonneg(ux)) +#define __unsigned_type_use(ux) (1 + 2 * (sizeof(ux) < 4)) +#define __sign_use(ux) (is_signed_type(typeof(ux)) ? \ + __signed_type_use(ux) : __unsigned_type_use(ux)) /* * Check whether a signed value is always non-negative. @@ -71,13 +71,13 @@ #else #define __signed_type(ux) typeof(__builtin_choose_expr(sizeof(ux) > 4, 1LL, 1L)) #endif -#define __is_nonneg(x, ux) statically_true((__signed_type(ux))(x) >= 0) +#define __is_nonneg(ux) statically_true((__signed_type(ux))(ux) >= 0) -#define __types_ok(x, y, ux, uy) \ - (__sign_use(x, ux) & __sign_use(y, uy)) +#define __types_ok(ux, uy) \ + (__sign_use(ux) & __sign_use(uy)) -#define __types_ok3(x, y, z, ux, uy, uz) \ - (__sign_use(x, ux) & __sign_use(y, uy) & __sign_use(z, uz)) +#define __types_ok3(ux, uy, uz) \ + (__sign_use(ux) & __sign_use(uy) & __sign_use(uz)) #define __cmp_op_min < #define __cmp_op_max > @@ -92,7 +92,7 @@ #define __careful_cmp_once(op, x, y, ux, uy) ({ \ __auto_type ux = (x); __auto_type uy = (y); \ - BUILD_BUG_ON_MSG(!__types_ok(x, y, ux, uy), \ + BUILD_BUG_ON_MSG(!__types_ok(ux, uy), \ #op"("#x", "#y") signedness error"); \ __cmp(op, ux, uy); }) @@ -109,7 +109,7 @@ static_assert(__builtin_choose_expr(__is_constexpr((lo) > (hi)), \ (lo) <= (hi), true), \ "clamp() low limit " #lo " greater than high limit " #hi); \ - BUILD_BUG_ON_MSG(!__types_ok3(val, lo, hi, uval, ulo, uhi), \ + BUILD_BUG_ON_MSG(!__types_ok3(uval, ulo, uhi), \ "clamp("#val", "#lo", "#hi") signedness error"); \ __clamp(uval, ulo, uhi); }) @@ -149,7 +149,7 @@ #define __careful_op3(op, x, y, z, ux, uy, uz) ({ \ __auto_type ux = (x); __auto_type uy = (y);__auto_type uz = (z);\ - BUILD_BUG_ON_MSG(!__types_ok3(x, y, z, ux, uy, uz), \ + BUILD_BUG_ON_MSG(!__types_ok3(ux, uy, uz), \ #op"3("#x", "#y", "#z") signedness error"); \ __cmp(op, ux, __cmp(op, uy, uz)); }) From patchwork Mon Nov 18 19:13:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Laight X-Patchwork-Id: 13878986 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 15FC7D591AC for ; Mon, 18 Nov 2024 19:13:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A029B6B008C; Mon, 18 Nov 2024 14:13:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9B2156B0093; Mon, 18 Nov 2024 14:13:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 879C56B0095; Mon, 18 Nov 2024 14:13:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 6AF806B008C for ; Mon, 18 Nov 2024 14:13:40 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id DF05A1A04C6 for ; Mon, 18 Nov 2024 19:13:38 +0000 (UTC) X-FDA: 82800163740.15.57B342F Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.86.151]) by imf03.hostedemail.com (Postfix) with ESMTP id CA5F320002 for ; Mon, 18 Nov 2024 19:13:13 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=aculab.com; spf=pass (imf03.hostedemail.com: domain of david.laight@aculab.com designates 185.58.86.151 as permitted sender) smtp.mailfrom=david.laight@aculab.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731957034; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DLnsRHfCjtWxXwmCaXLQoT++BY50b46si2gHIz+U13M=; b=lujDaGaKmB3usdjr7AbRIZdhqyL3axMJsLhcYoFt+/65sTsheX717EhonHrsN41d0ywuAo zeoMvxZeHZD7B7NA2Kfo8byUC1+64/LRNlEn6BTfgiywtiOzc6nO0BbafZ+yfRPYkGhnwH w3mZoDXkD0csHb0Xir4QxGAIcu0V7EI= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=aculab.com; spf=pass (imf03.hostedemail.com: domain of david.laight@aculab.com designates 185.58.86.151 as permitted sender) smtp.mailfrom=david.laight@aculab.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731957034; a=rsa-sha256; cv=none; b=H3+dzXX373VoL/6VhipqCQp+KYPdfHkCuGw2naylwT27cMTJEGLIyD4Wwrkgqdx5QnJanR BIENfrAU5MdvGHxvh/vzreTpNqNgx5mJmFr/q3gjSHLonXZTmy9ctKIgxJn2F7L1/ezmZ0 eSFCcN7drSwzbziU6rid+ek2f4BLU0c= 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-53-8QuoD1GfPLOo-8Il3CnRIg-1; Mon, 18 Nov 2024 19:13:33 +0000 X-MC-Unique: 8QuoD1GfPLOo-8Il3CnRIg-1 X-Mimecast-MFC-AGG-ID: 8QuoD1GfPLOo-8Il3CnRIg 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; Mon, 18 Nov 2024 19:13:32 +0000 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Mon, 18 Nov 2024 19:13:32 +0000 From: David Laight To: Linus Torvalds CC: 'Arnd Bergmann' , "'linux-kernel@vger.kernel.org'" , 'Jens Axboe' , "'Matthew Wilcox'" , 'Christoph Hellwig' , 'Andrew Morton' , 'Andy Shevchenko' , 'Dan Carpenter' , "'Jason A . Donenfeld'" , "'pedro.falcato@gmail.com'" , 'Mateusz Guzik' , "'linux-mm@kvack.org'" , "'Lorenzo Stoakes'" Subject: [PATCH next 4/7] minmax.h: Use BUILD_BUG_ON_MSG() for the lo < hi test in clamp() Thread-Topic: [PATCH next 4/7] minmax.h: Use BUILD_BUG_ON_MSG() for the lo < hi test in clamp() Thread-Index: Ads57fNMrPBo0VpjT1C2YVoqcr+8eA== Date: Mon, 18 Nov 2024 19:13:31 +0000 Message-ID: <34d53778977747f19cce2abb287bb3e6@AcuMS.aculab.com> References: In-Reply-To: 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-MFC-PROC-ID: GGEXM2LKcVL7OPOJKOl5ICNkVVQh0RZk7ZExUv_X_W4_1731957212 X-Mimecast-Originator: aculab.com Content-Language: en-US X-Rspamd-Server: rspam04 X-Rsp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TdX4wo oduDGYujcN5Robbre8jImx2Q3elMWmLMRfo6KAu4VQ0fVSOBW2WuBWZBMuPdX+o/h0fL8duPdIsy2rgjAN9Cgn3C+O6FZae0nsP/MT3CMQeYT0bIn7UrGclhZkGgyxBp1C5uPVQ++KW/Oc+i1H+EpBPSBgPQkURRqydgPBcOgc1eNMkg9qAJJtOJSVP7mc1CLXj/hmT5xckiiBCR5D13ZtP/QYX6bTHsUgIZKlNfdzHl5WiNL8DEWrPZ24FgLBXgwLjoVNOpZD2quiITjwdsryIywFsunJRL/fAkyzH7F9WL/vuBsZJg5/b+TB0POLyXKJKatTOgdtTonpgM5CuuoLMMtvHVheS+pk7hf852KwV8iUyppNuQbmpeldNMbhnLyeZki5oSdgu4c0dLpvYs5jVevVDXYMxR/LwrH03OEBMGF+Rvyx6GKQdBOjqMjo8z/Gys4cb1dNeMS53EToOPtSGaDmslaF+O7NTwU0JiA8c3q6Q5zlZaxrxBsUg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Use BUILD_BUG_ON_MSG(statically_true(ulo > uhi), ...) for the sanity check of the bounds in clamp(). Gives better error coverage and one less expansion of the arguments. Signed-off-by: David Laight --- include/linux/minmax.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/linux/minmax.h b/include/linux/minmax.h index 6f7ea669d305..91aa1b90c1bb 100644 --- a/include/linux/minmax.h +++ b/include/linux/minmax.h @@ -106,8 +106,7 @@ __auto_type uval = (val); \ __auto_type ulo = (lo); \ __auto_type uhi = (hi); \ - static_assert(__builtin_choose_expr(__is_constexpr((lo) > (hi)), \ - (lo) <= (hi), true), \ + BUILD_BUG_ON_MSG(statically_true(ulo > uhi), \ "clamp() low limit " #lo " greater than high limit " #hi); \ BUILD_BUG_ON_MSG(!__types_ok3(uval, ulo, uhi), \ "clamp("#val", "#lo", "#hi") signedness error"); \ From patchwork Mon Nov 18 19:14:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Laight X-Patchwork-Id: 13878987 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 51157D591AC for ; Mon, 18 Nov 2024 19:14:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DD3AA6B0093; Mon, 18 Nov 2024 14:14:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D83186B0095; Mon, 18 Nov 2024 14:14:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C71F96B0096; Mon, 18 Nov 2024 14:14:25 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id A9C996B0093 for ; Mon, 18 Nov 2024 14:14:25 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 66D671C617F for ; Mon, 18 Nov 2024 19:14:25 +0000 (UTC) X-FDA: 82800164370.01.0FC4895 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.86.151]) by imf23.hostedemail.com (Postfix) with ESMTP id 85BFA140017 for ; Mon, 18 Nov 2024 19:13:50 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=aculab.com; spf=pass (imf23.hostedemail.com: domain of david.laight@aculab.com designates 185.58.86.151 as permitted sender) smtp.mailfrom=david.laight@aculab.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731957197; a=rsa-sha256; cv=none; b=ebecSTVHm/X/QV/e15wgOSws+t0qfWdt55FdKbAciplGncgnWtl9vJ/RbkXbpx+PTaaLmt bCHBFOswcm9PyahcY6AA2gg9bOCkn/UvowGC/8Zic1V6HSSTLjM+BDEb5XzLBKa6QDvEkR OXB0NpT+LHyDo4wrPHns8wVfy1vfob0= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=aculab.com; spf=pass (imf23.hostedemail.com: domain of david.laight@aculab.com designates 185.58.86.151 as permitted sender) smtp.mailfrom=david.laight@aculab.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731957197; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Bkkne61MLl1Cne8dOG9T8thxhzoeA6oa/NqsmHVl0Gs=; b=CeTw/L2Pv9cYz3EaMGph9BQrJjvVcv8hQqvCfYUCCC5asi5ZFdeyTOXGFRPhtC3F4E6hMM Dr5b3EbBkCuAp70IHQVA6LBkeu6Ohki1wmD92mnjeFBUMxpnDD1p25rYBydXwgJv2YVSR+ SDwBRtiKg2eHOVsVgJv96StDJ4L4d6U= 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-401-uKPs-5wQMmmpgcJGIGanNA-1; Mon, 18 Nov 2024 19:14:20 +0000 X-MC-Unique: uKPs-5wQMmmpgcJGIGanNA-1 X-Mimecast-MFC-AGG-ID: uKPs-5wQMmmpgcJGIGanNA 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; Mon, 18 Nov 2024 19:14:19 +0000 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Mon, 18 Nov 2024 19:14:19 +0000 From: David Laight To: Linus Torvalds CC: 'Arnd Bergmann' , "'linux-kernel@vger.kernel.org'" , 'Jens Axboe' , "'Matthew Wilcox'" , 'Christoph Hellwig' , 'Andrew Morton' , 'Andy Shevchenko' , 'Dan Carpenter' , "'Jason A . Donenfeld'" , "'pedro.falcato@gmail.com'" , 'Mateusz Guzik' , "'linux-mm@kvack.org'" , "'Lorenzo Stoakes'" Subject: [PATCH next 5/7] minmax.h: Move all the clamp() definitions after the min/max() ones Thread-Topic: [PATCH next 5/7] minmax.h: Move all the clamp() definitions after the min/max() ones Thread-Index: Ads57g96P3rlqjRlR9q8btqd7zczRA== Date: Mon, 18 Nov 2024 19:14:19 +0000 Message-ID: <8bb285818e4846469121c8abc3dfb6e2@AcuMS.aculab.com> References: In-Reply-To: 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-MFC-PROC-ID: KdaaSg1di7l0CPdqzvrcyioeQqUnPhdLGUcK_b3y3w0_1731957259 X-Mimecast-Originator: aculab.com Content-Language: en-US X-Rspam-User: X-Rspamd-Queue-Id: 85BFA140017 X-Rspamd-Server: rspam01 X-Stat-Signature: o5k85uqeqcjyfafdod4qhkhwhqqig5qt X-HE-Tag: 1731957230-597817 X-HE-Meta: U2FsdGVkX19qvN+kJuujgk+GW+7XXbaRg55sKue1ka4UkWXi0kFTNfrnnQuFODrbb5H9+qhaIUfJbQzruPPHvDVukgLAAqAfqb6Kg3GGeZwq88fTlXH5/bYFgQUYPX43rBJojzgRIbGSEKpVWf18cW4Jp7sHMv5xIBMeyIEDrAHqnE75zVc8bEfH3k5DTKLjZ4Ws7bFE8xjCIA+KR2yoWXKiv9HWao6waNObfvtG4NH7m/MU2tP7O7JE/IE7HnRVtir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KELlgeyy9sWRxWQRc6G3OnYr2Njn2Fgg7YR9NVb5QLfOC7CnB+vELp0xxSXMTRMQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: At some point the definitions for clamp() got added in the middle of the ones for min() and max(). Re-order the definitions so they are more sensibly grouped. Signed-off-by: David Laight --- include/linux/minmax.h | 109 +++++++++++++++++++---------------------- 1 file changed, 51 insertions(+), 58 deletions(-) diff --git a/include/linux/minmax.h b/include/linux/minmax.h index 91aa1b90c1bb..75fb7a6ad4c6 100644 --- a/include/linux/minmax.h +++ b/include/linux/minmax.h @@ -99,22 +99,6 @@ #define __careful_cmp(op, x, y) \ __careful_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, uval, ulo, uhi) ({ \ - __auto_type uval = (val); \ - __auto_type ulo = (lo); \ - __auto_type uhi = (hi); \ - BUILD_BUG_ON_MSG(statically_true(ulo > uhi), \ - "clamp() low limit " #lo " greater than high limit " #hi); \ - BUILD_BUG_ON_MSG(!__types_ok3(uval, ulo, uhi), \ - "clamp("#val", "#lo", "#hi") signedness error"); \ - __clamp(uval, ulo, uhi); }) - -#define __careful_clamp(val, lo, hi) \ - __clamp_once(val, lo, hi, __UNIQUE_ID(v_), __UNIQUE_ID(l_), __UNIQUE_ID(h_)) - /** * min - return minimum of two values of the same or compatible types * @x: first value @@ -170,6 +154,22 @@ #define max3(x, y, z) \ __careful_op3(max, x, y, z, __UNIQUE_ID(x_), __UNIQUE_ID(y_), __UNIQUE_ID(z_)) +/** + * min_t - return minimum of two values, using the specified type + * @type: data type to use + * @x: first value + * @y: second value + */ +#define min_t(type, x, y) __cmp_once(min, type, x, y) + +/** + * max_t - return maximum of two values, using the specified type + * @type: data type to use + * @x: first value + * @y: second value + */ +#define max_t(type, x, y) __cmp_once(max, type, x, y) + /** * min_not_zero - return the minimum that is _not_ zero, unless both are zero * @x: value1 @@ -180,6 +180,22 @@ typeof(y) __y = (y); \ __x == 0 ? __y : ((__y == 0) ? __x : min(__x, __y)); }) +#define __clamp(val, lo, hi) \ + ((val) >= (hi) ? (hi) : ((val) <= (lo) ? (lo) : (val))) + +#define __clamp_once(val, lo, hi, uval, ulo, uhi) ({ \ + __auto_type uval = (val); \ + __auto_type ulo = (lo); \ + __auto_type uhi = (hi); \ + BUILD_BUG_ON_MSG(statically_true(ulo > uhi), \ + "clamp() low limit " #lo " greater than high limit " #hi); \ + BUILD_BUG_ON_MSG(!__types_ok3(uval, ulo, uhi), \ + "clamp("#val", "#lo", "#hi") signedness error"); \ + __clamp(uval, ulo, uhi); }) + +#define __careful_clamp(val, lo, hi) \ + __clamp_once(val, lo, hi, __UNIQUE_ID(v_), __UNIQUE_ID(l_), __UNIQUE_ID(h_)) + /** * clamp - return a value clamped to a given range with strict typechecking * @val: current value @@ -191,28 +207,30 @@ */ #define clamp(val, lo, hi) __careful_clamp(val, lo, hi) -/* - * ..and if you can't take the strict - * types, you can specify one yourself. - * - * Or not use min/max/clamp at all, of course. - */ - /** - * min_t - return minimum of two values, using the specified type - * @type: data type to use - * @x: first value - * @y: second value + * clamp_t - return a value clamped to a given range using a given type + * @type: the type of variable to use + * @val: current value + * @lo: minimum allowable value + * @hi: maximum allowable value + * + * This macro does no typechecking and uses temporary variables of type + * @type to make all the comparisons. */ -#define min_t(type, x, y) __cmp_once(min, type, x, y) +#define clamp_t(type, val, lo, hi) __careful_clamp((type)(val), (type)(lo), (type)(hi)) /** - * max_t - return maximum of two values, using the specified type - * @type: data type to use - * @x: first value - * @y: second value + * clamp_val - return a value clamped to a given range using val's type + * @val: current value + * @lo: minimum allowable value + * @hi: maximum allowable value + * + * This macro does no typechecking and uses temporary variables of whatever + * type the input argument @val is. This is useful when @val is an unsigned + * type and @lo and @hi are literals that will otherwise be assigned a signed + * integer type. */ -#define max_t(type, x, y) __cmp_once(max, type, x, y) +#define clamp_val(val, lo, hi) clamp_t(typeof(val), val, lo, hi) /* * Do not check the array parameter using __must_be_array(). @@ -257,31 +275,6 @@ */ #define max_array(array, len) __minmax_array(max, array, len) -/** - * clamp_t - return a value clamped to a given range using a given type - * @type: the type of variable to use - * @val: current value - * @lo: minimum allowable value - * @hi: maximum allowable value - * - * This macro does no typechecking and uses temporary variables of type - * @type to make all the comparisons. - */ -#define clamp_t(type, val, lo, hi) __careful_clamp((type)(val), (type)(lo), (type)(hi)) - -/** - * clamp_val - return a value clamped to a given range using val's type - * @val: current value - * @lo: minimum allowable value - * @hi: maximum allowable value - * - * This macro does no typechecking and uses temporary variables of whatever - * type the input argument @val is. This is useful when @val is an unsigned - * type and @lo and @hi are literals that will otherwise be assigned a signed - * integer type. - */ -#define clamp_val(val, lo, hi) clamp_t(typeof(val), val, lo, hi) - static inline bool in_range64(u64 val, u64 start, u64 len) { return (val - start) < len; From patchwork Mon Nov 18 19:15:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Laight X-Patchwork-Id: 13878988 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3AD59D591AD for ; Mon, 18 Nov 2024 19:15:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CC3D46B0085; Mon, 18 Nov 2024 14:15:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C721D6B0088; Mon, 18 Nov 2024 14:15:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B88456B0095; Mon, 18 Nov 2024 14:15:12 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 9A32E6B0085 for ; Mon, 18 Nov 2024 14:15:12 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 57A4E1604A0 for ; Mon, 18 Nov 2024 19:15:12 +0000 (UTC) X-FDA: 82800167436.12.C8D5E7D Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.86.151]) by imf25.hostedemail.com (Postfix) with ESMTP id 13D84A001D for ; Mon, 18 Nov 2024 19:14:33 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=none; spf=pass (imf25.hostedemail.com: domain of david.laight@aculab.com designates 185.58.86.151 as permitted sender) smtp.mailfrom=david.laight@aculab.com; dmarc=pass (policy=none) header.from=aculab.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731957109; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9maQU4wGvYW3paDE/WtpSZ7O4+dlztwiKjoAdeMmpl4=; b=BJLtMax9rOt51KuRgxArZbUDO7Pq66eaQPq/JprwxyC7nA3KTrh62G1805QLGj0wTC3oD6 u1RbcKy/ks6vcLGW7imNR7FWm59tLZDo4YzY9bj/tyhd4f3qirPvRPEcaJy1S4gm6qVe7G GZnvsrmDKocNsCMmPEQm2WI/ockJzpM= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=none; spf=pass (imf25.hostedemail.com: domain of david.laight@aculab.com designates 185.58.86.151 as permitted sender) smtp.mailfrom=david.laight@aculab.com; dmarc=pass (policy=none) header.from=aculab.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731957109; a=rsa-sha256; cv=none; b=iZuvxW3BedP7TVuuL+YQYkQbrALjF9AT/tHBfowUFc5WxVwTKlqT5Y3vFZV6WBqUxCdPP5 IVYwmgHXUYBoB5vTGGTavbEr6BB5WU3a87hF1aqeGIG4uVZLWksPjbw8a6ugUiHCSmKNMv 2EsI1AZq1lNJ8dJe6zofnexwf1dUbus= 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-1-Li-56pJWM8mS-HZ_UNxcng-1; Mon, 18 Nov 2024 19:15:06 +0000 X-MC-Unique: Li-56pJWM8mS-HZ_UNxcng-1 X-Mimecast-MFC-AGG-ID: Li-56pJWM8mS-HZ_UNxcng 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; Mon, 18 Nov 2024 19:15:05 +0000 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Mon, 18 Nov 2024 19:15:05 +0000 From: David Laight To: Linus Torvalds CC: 'Arnd Bergmann' , "'linux-kernel@vger.kernel.org'" , 'Jens Axboe' , "'Matthew Wilcox'" , 'Christoph Hellwig' , 'Andrew Morton' , 'Andy Shevchenko' , 'Dan Carpenter' , "'Jason A . Donenfeld'" , "'pedro.falcato@gmail.com'" , 'Mateusz Guzik' , "'linux-mm@kvack.org'" , "'Lorenzo Stoakes'" Subject: [PATCH next 6/7] minmax.h: Simplify the variants of clamp() Thread-Topic: [PATCH next 6/7] minmax.h: Simplify the variants of clamp() Thread-Index: Ads57ipn63eWKuUFSOOk3Sda6NOThQ== Date: Mon, 18 Nov 2024 19:15:05 +0000 Message-ID: <8f69f4deac014f558bab186444bac2e8@AcuMS.aculab.com> References: In-Reply-To: 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-MFC-PROC-ID: PIn-oo-fgqRBt4vMFrIktXgS1ArQ__ypHjZdvNct5nA_1731957305 X-Mimecast-Originator: aculab.com Content-Language: en-US X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 13D84A001D X-Stat-Signature: 59ancfq8rm9ju1udrre5s5jdffhbmo4j X-Rspam-User: X-HE-Tag: 1731957273-58419 X-HE-Meta: U2FsdGVkX18dpZweQB2Ae3cTbogIU9EWrVZdI5nTpJVyBFFkM9E5Kds6nhjlZsM+GBykBYTl71z2RxgPtw8J5oibCzsQ3ahToudxTK0qsK+ufmEH0HKvZEpf/oJAFsgf2S7zqhBGYPjoxq8OqJKPME8jixx1lhwut3hmJC9is48lcnIQBOk4LP7Ci69cCgg84N5I8x7Z5lIU5HVPZ6fTTMUGKHyBppyUND6f7cYd6s24AEi1u1jwK/O7JwUyOI7SVWSEP0h6XQAOGHHX25qYFwmDx0w9W/5zNl+FYcAPYTuBpag2BLOFcRvH4ZsW1E7LPQDfK/fHmD54CSA3OKYIx9ecarIfjcQBzE/Xoo5HFsdnVvI8fS+mGseNsTUBWMMDe63QfOg82b0ATkl6RFzsKMQHoCiSpO94ZzXVTqL/Z6CPhGxsr0VXvQs7sIwVqb9Zc2yXvmk5eEQYi0jcCF1j59CBbruP6CFLhG7zwe+81nCJzAA8Yx7Go0DUW3gfuKGw6TVqDP1DR+bZkKkzdK//gpCMDkFPyvWBUZlt/mCqz+DL98QvPYhloGHlrHKIYid5Rnq7jTmjsrOA5t0k2Lw7VQC1R1ZbxPjn1GP0NgCiG8dg8lidMxX7eJKK4ZqzTa7pQlHAViMCJTebnHD7F8EuMPIs8EgZc5Rb8bwFZNB1XBKggTnRIGa9X222PPmpRGDWWApTjTRGbJRRYCYL20x5HxZbB4PhEVDMMKUcGOfrb7Fl3tgA+Q0VnZafjeXEEMc8RVOgi3jeWU1DCx28M8GlqbV1cbYrHvfNob8X+UBaQR4Eh5s833bTV3/GPAc92nsrHqJnu9jbigYRKo1P4e7E6WIP4nRFfdvlkWCyVo0QsQTwyhGixdYnub8yBzhBElCh41fmfgTn8A4SvI3utyIQDwPOLE+0QvYmyYG8jGLIzyLWq1KMpFfgje14InxosdTwaFOsrpGk2T4FoKhz06X /53ZhNvP Zj/bVz1OTGzLlYA5GYOs5h2BSl2CRoN5ElKFniTTpKLSsjz4RJI5mNhQmgIbdY8bNLGUm4dUSJgq6SZzDr7op0iARoGdMuOpvBL6CvexIG9iRYU311wsBV9SS9TJiuCwbqS25nO121FQ0MvtMM9Qx+mJkdUMXHm7mSrFUE9lf9TDR8C1uWT0L+lnlw98nEbYYUXBo1EAre/Zi9f8UabphpNZMlT9LtvHVAeDCmtyliQJ/t3B+N3K3GPRPMOQJ3QK8/+d+QCMfNSeEFnLWM5px2/Fp1M5SkEh+Pj6LUBCiXPsFQ3b2OOLYBWyLql8e3YrU3ruLqMPMcCkTn3bNJPBv3729EtEAAsFirYwkw5e2w4zdm+VwpTj0LOJ/YaKpadthfkLspIjdp4gcPagLgM73ikeE/lBhduNBgKNsDY3Vk0BvG5DkX572S51PL0t5gkPUX3+a X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Always pass a 'type' through to __clamp_once(), pass '__auto_type' from clamp() itself. The expansion of __types_ok3() is reasonable so it isn't worth the added complexity of avoiding it when a fixed type is used for all three values. Signed-off-by: David Laight --- include/linux/minmax.h | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/include/linux/minmax.h b/include/linux/minmax.h index 75fb7a6ad4c6..2bbdd5b5e07e 100644 --- a/include/linux/minmax.h +++ b/include/linux/minmax.h @@ -183,29 +183,29 @@ #define __clamp(val, lo, hi) \ ((val) >= (hi) ? (hi) : ((val) <= (lo) ? (lo) : (val))) -#define __clamp_once(val, lo, hi, uval, ulo, uhi) ({ \ - __auto_type uval = (val); \ - __auto_type ulo = (lo); \ - __auto_type uhi = (hi); \ +#define __clamp_once(type, val, lo, hi, uval, ulo, uhi) ({ \ + type uval = (val); \ + type ulo = (lo); \ + type uhi = (hi); \ BUILD_BUG_ON_MSG(statically_true(ulo > uhi), \ "clamp() low limit " #lo " greater than high limit " #hi); \ BUILD_BUG_ON_MSG(!__types_ok3(uval, ulo, uhi), \ "clamp("#val", "#lo", "#hi") signedness error"); \ __clamp(uval, ulo, uhi); }) -#define __careful_clamp(val, lo, hi) \ - __clamp_once(val, lo, hi, __UNIQUE_ID(v_), __UNIQUE_ID(l_), __UNIQUE_ID(h_)) +#define __careful_clamp(type, val, lo, hi) \ + __clamp_once(type, val, lo, hi, __UNIQUE_ID(v_), __UNIQUE_ID(l_), __UNIQUE_ID(h_)) /** - * clamp - return a value clamped to a given range with strict typechecking + * clamp - return a value clamped to a given range with typechecking * @val: current value * @lo: lowest allowable value * @hi: highest allowable value * - * This macro does strict typechecking of @lo/@hi to make sure they are of the - * same type as @val. See the unnecessary pointer comparisons. + * This macro checks @val/@lo/@hi to make sure they have compatible + * signedness. */ -#define clamp(val, lo, hi) __careful_clamp(val, lo, hi) +#define clamp(val, lo, hi) __careful_clamp(__auto_type, val, lo, hi) /** * clamp_t - return a value clamped to a given range using a given type @@ -217,7 +217,7 @@ * This macro does no typechecking and uses temporary variables of type * @type to make all the comparisons. */ -#define clamp_t(type, val, lo, hi) __careful_clamp((type)(val), (type)(lo), (type)(hi)) +#define clamp_t(type, val, lo, hi) __careful_clamp(type, val, lo, hi) /** * clamp_val - return a value clamped to a given range using val's type @@ -230,7 +230,7 @@ * type and @lo and @hi are literals that will otherwise be assigned a signed * integer type. */ -#define clamp_val(val, lo, hi) clamp_t(typeof(val), val, lo, hi) +#define clamp_val(val, lo, hi) __careful_clamp(typeof(val), val, lo, hi) /* * Do not check the array parameter using __must_be_array(). From patchwork Mon Nov 18 19:15:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Laight X-Patchwork-Id: 13878989 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3196FD591AE for ; Mon, 18 Nov 2024 19:15:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BD8746B0085; Mon, 18 Nov 2024 14:15:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B88296B0088; Mon, 18 Nov 2024 14:15:57 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A50536B008A; Mon, 18 Nov 2024 14:15:57 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 8944C6B0085 for ; Mon, 18 Nov 2024 14:15:57 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 348D740473 for ; Mon, 18 Nov 2024 19:15:57 +0000 (UTC) X-FDA: 82800168864.25.C42DF80 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.86.151]) by imf17.hostedemail.com (Postfix) with ESMTP id D653A4002D for ; Mon, 18 Nov 2024 19:15:16 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=aculab.com; spf=pass (imf17.hostedemail.com: domain of david.laight@aculab.com designates 185.58.86.151 as permitted sender) smtp.mailfrom=david.laight@aculab.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731957206; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JRytXLO7xuf/PIyuFUZIElyqtU4MFdHGWBtvkM4EmaQ=; b=CmjlDkTKtrwtVSklvzmNIdxdY+vmEUW6QKbMzSJ4sKYcwvYfO01bJsiwtm0n/g6bkWLoYr GFw0uxVCmnTny06NB7zHANGfeukbQn9JNoRdyrIbziZDKNmeQT89eO3zGPDAF5BgQL6Xw2 8Nil/gAfE79azkSCiRRUuHvyIXOJph4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731957206; a=rsa-sha256; cv=none; b=enAUSo8r5YBSPVwehIN5GvOAc4avAj4fygvaranxBbrcIpgPnwVYeKTFSQKzArlOFwikIE sv4aT2d+pOn3YarTFZ/9RzmkVEOnLYHyZvJCvFMXSxnSvMELYbI90YCJYKTirOibmaKrbg CsUNf3bQJr768N8qrnD+/+2srI8qAH4= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=aculab.com; spf=pass (imf17.hostedemail.com: domain of david.laight@aculab.com designates 185.58.86.151 as permitted sender) smtp.mailfrom=david.laight@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-53-13-iqr8aPEKNwrfrKL2jEg-1; Mon, 18 Nov 2024 19:15:52 +0000 X-MC-Unique: 13-iqr8aPEKNwrfrKL2jEg-1 X-Mimecast-MFC-AGG-ID: 13-iqr8aPEKNwrfrKL2jEg 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; Mon, 18 Nov 2024 19:15:51 +0000 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Mon, 18 Nov 2024 19:15:51 +0000 From: David Laight To: Linus Torvalds CC: 'Arnd Bergmann' , "'linux-kernel@vger.kernel.org'" , 'Jens Axboe' , "'Matthew Wilcox'" , 'Christoph Hellwig' , 'Andrew Morton' , 'Andy Shevchenko' , 'Dan Carpenter' , "'Jason A . Donenfeld'" , "'pedro.falcato@gmail.com'" , 'Mateusz Guzik' , "'linux-mm@kvack.org'" , "'Lorenzo Stoakes'" Subject: [PATCH next 7/7] minmax.h: Remove some #defines that are only expanded once Thread-Topic: [PATCH next 7/7] minmax.h: Remove some #defines that are only expanded once Thread-Index: Ads57kK39EnzR0zLSLWjfI7GoDxEdQ== Date: Mon, 18 Nov 2024 19:15:51 +0000 Message-ID: <9386d1ebb8974fbabbed2635160c3975@AcuMS.aculab.com> References: In-Reply-To: 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-MFC-PROC-ID: cM51TGWZnUWE8lghKGuE9TVUVMsNMV8NfDN7l_e__1g_1731957351 X-Mimecast-Originator: aculab.com Content-Language: en-US X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: D653A4002D X-Stat-Signature: rtk4bcdmq6gq1hbff1rce8atkb81o3fg X-HE-Tag: 1731957316-285146 X-HE-Meta: U2FsdGVkX18s4O4NDnWZGCL1PZaIxVGhzEPK+VN6OB90mxTj8Zu8xnsoiZxjVRuzotcldaMghnRs0jWmlHdlaAkpKPrwZKnbO2ea/ibCR4uv0lEssLbB0leYxZflaDgaOsRSYDw5KJK6L+PlsLv4CfYE+jEefwTBShh4/9pvnQdlajCDsMOxvRlXMqInjQOj+OKGHeLxpP60nv15yQB9Zrrs+eVFtLA2yqQMd0OBnfIxPYTpb15WV2Ht5PcShDHYJckLkXYWIueJg+lfUut3QrNVt3vtXqAAbEWGeGV9lf2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gOqG4olAh8pgSUIQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: The bodies of __signed_type_use() and __unsigned_type_use() are much the same size as their names - so put the bodies in the only line that expands them. Similarly __signed_type() is defined separately for 64bit and then used exactly once just below. Change the test for __signed_type from CONFIG_64BIT to one based on gcc defined macros so that the code is valid if it gets used outside of a kernel build. Signed-off-by: David Laight --- include/linux/minmax.h | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/include/linux/minmax.h b/include/linux/minmax.h index 2bbdd5b5e07e..eaaf5c008e4d 100644 --- a/include/linux/minmax.h +++ b/include/linux/minmax.h @@ -46,10 +46,8 @@ * comparison, and these expressions only need to be careful to not cause * warnings for pointer use. */ -#define __signed_type_use(ux) (2 + __is_nonneg(ux)) -#define __unsigned_type_use(ux) (1 + 2 * (sizeof(ux) < 4)) #define __sign_use(ux) (is_signed_type(typeof(ux)) ? \ - __signed_type_use(ux) : __unsigned_type_use(ux)) + (2 + __is_nonneg(ux)) : (1 + 2 * (sizeof(ux) < 4))) /* * Check whether a signed value is always non-negative. @@ -57,7 +55,7 @@ * A cast is needed to avoid any warnings from values that aren't signed * integer types (in which case the result doesn't matter). * - * On 64-bit any integer or pointer type can safely be cast to 'long'. + * On 64-bit any integer or pointer type can safely be cast to 'long long'. * But on 32-bit we need to avoid warnings about casting pointers to integers * of different sizes without truncating 64-bit values so 'long' or 'long long' * must be used depending on the size of the value. @@ -66,12 +64,12 @@ * them, but we do not use s128 types in the kernel (we do use 'u128', * but they are handled by the !is_signed_type() case). */ -#ifdef CONFIG_64BIT - #define __signed_type(ux) long +#if __SIZEOF_POINTER__ == __SIZEOF_LONG_LONG__ +#define __is_nonneg(ux) statically_true((long long)(ux) >= 0) #else - #define __signed_type(ux) typeof(__builtin_choose_expr(sizeof(ux) > 4, 1LL, 1L)) +#define __is_nonneg(ux) statically_true( \ + (typeof(__builtin_choose_expr(sizeof(ux) > 4, 1LL, 1L)))(ux) >= 0) #endif -#define __is_nonneg(ux) statically_true((__signed_type(ux))(ux) >= 0) #define __types_ok(ux, uy) \ (__sign_use(ux) & __sign_use(uy))