From nobody Thu Oct 2 04:45:16 2025 Received: from fra-out-004.esa.eu-central-1.outbound.mail-perimeter.amazon.com (fra-out-004.esa.eu-central-1.outbound.mail-perimeter.amazon.com [3.74.81.189]) (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 F15022FE076; Mon, 22 Sep 2025 10:31:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=3.74.81.189 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758537110; cv=none; b=ai8fB1qcWZLajnovNMTTehxIeu9m4eiH0S8K06yhPUWpRMrDnZ72rO4AO5rwSNUgPvG/59Li4BSpmKQ0NEVWSvQXsPXf1pGLexFzlcay6fFhv8FJxmtb399OXDCfxvu1ghwsX15N2hBHVMqSMQRLxUFNfdyRjBZ57IMq9RvFAR8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758537110; c=relaxed/simple; bh=20xAuZOYw8I0ufWzB2Ksi4V2Oix+SUEkw1tbLPElVss=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=sEmqzobiScGHZtS65IXMx5snYweNlOs9Bl+Q0tny3clsUdwAYYSVEFuNYXlKJKXgA3loRuBpWx8KWKJypQ7v53GpcXRSt+Y3zcHWVrRcfpW1NVCuJI5BEoKD6TQrCOAqKutaBGgAuAWte8ngUdg9BaXqXmSSv+oLFBiEGWT4WAM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.com; dkim=pass (2048-bit key) header.d=amazon.com header.i=@amazon.com header.b=i1qTIXpe; arc=none smtp.client-ip=3.74.81.189 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=amazon.com header.i=@amazon.com header.b="i1qTIXpe" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazoncorp2; t=1758537108; x=1790073108; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OdmfzjzF46YfqPKnSMGZyjhQcZN9I6u6dSg4k1vq8LU=; b=i1qTIXpeUfup1UvjOBSswl/vCLYJ6/XZGIDJGykv+Omu+vDdb/Iwx4h5 ppbvYugFgPF6FEQSJcE23CfefrpSyideVpW4K3X6ct9Cvr8u2LtkrVEf4 9KI9gQI6WVxLmTHG4s2W+bSUstQCN0Zi8LYK2b5cRHDHQDiJyZraAIi5+ d6Q/7WpjcmJ+mxUXv4j/mdUzmUSn1XvJfDFkp0C8xhRrk3UAxjpiraMOW sHVc49N0ybQA1yqNF2OwiJ+HHSE9od3l/nn19GvX4IECrqL5bco7L7xxa QM0wM9epZxZ9MeQINtso9uQwmPljU0ZJ5eYa2r2yYlZg7V/8fE8MAuPjy w==; X-CSE-ConnectionGUID: PiIEZaBYQaGrpjqFfVi5jg== X-CSE-MsgGUID: F1LwJAOsSWWaWCWnkijD5g== X-IronPort-AV: E=Sophos;i="6.18,284,1751241600"; d="scan'208";a="2475096" Received: from ip-10-6-3-216.eu-central-1.compute.internal (HELO smtpout.naws.eu-central-1.prod.farcaster.email.amazon.dev) ([10.6.3.216]) by internal-fra-out-004.esa.eu-central-1.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2025 10:31:38 +0000 Received: from EX19MTAEUA001.ant.amazon.com [54.240.197.233:24093] by smtpin.naws.eu-central-1.prod.farcaster.email.amazon.dev [10.0.36.68:2525] with esmtp (Farcaster) id f33e12ad-2b1a-4088-9d48-13f35b5563c8; Mon, 22 Sep 2025 10:31:38 +0000 (UTC) X-Farcaster-Flow-ID: f33e12ad-2b1a-4088-9d48-13f35b5563c8 Received: from EX19D018EUA004.ant.amazon.com (10.252.50.85) by EX19MTAEUA001.ant.amazon.com (10.252.50.192) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.20; Mon, 22 Sep 2025 10:31:37 +0000 Received: from dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (172.19.116.181) by EX19D018EUA004.ant.amazon.com (10.252.50.85) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.20; Mon, 22 Sep 2025 10:31:33 +0000 From: Eliav Farber To: , , , , , CC: Andy Shevchenko , Christoph Hellwig , Dan Carpenter , "Jason A. Donenfeld" , Jens Axboe , Lorenzo Stoakes , Mateusz Guzik , "Matthew Wilcox" , Pedro Falcato Subject: [PATCH 1/7 6.12.y] minmax.h: add whitespace around operators and after commas Date: Mon, 22 Sep 2025 10:31:17 +0000 Message-ID: <20250922103123.14538-2-farbere@amazon.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250922103123.14538-1-farbere@amazon.com> References: <20250922103123.14538-1-farbere@amazon.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: EX19D039UWB003.ant.amazon.com (10.13.138.93) To EX19D018EUA004.ant.amazon.com (10.252.50.85) Content-Type: text/plain; charset="utf-8" From: David Laight [ Upstream commit 71ee9b16251ea4bf7c1fe222517c82bdb3220acc ] Patch series "minmax.h: Cleanups and minor optimisations". Some tidyups and minor changes to minmax.h. This patch (of 7): Link: https://lkml.kernel.org/r/c50365d214e04f9ba256d417c8bebbc0@AcuMS.acul= ab.com Link: https://lkml.kernel.org/r/f04b2e1310244f62826267346fde0553@AcuMS.acul= ab.com Signed-off-by: David Laight Cc: Andy Shevchenko Cc: Arnd Bergmann Cc: Christoph Hellwig Cc: Dan Carpenter Cc: Jason A. Donenfeld Cc: Jens Axboe Cc: Lorenzo Stoakes Cc: Mateusz Guzik Cc: Matthew Wilcox Cc: Pedro Falcato Signed-off-by: Andrew Morton Signed-off-by: Eliav Farber --- 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)) =20 /* * 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, 1= LL, 1L)) #endif -#define __is_nonneg(x,ux) statically_true((__signed_type(ux))(x)>=3D0) +#define __is_nonneg(x, ux) statically_true((__signed_type(ux))(x) >=3D 0) =20 -#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)) =20 -#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)) =20 #define __cmp_op_min < #define __cmp_op_max > @@ -97,7 +97,7 @@ =20 #define __careful_cmp_once(op, x, y, ux, uy) ({ \ __auto_type ux =3D (x); __auto_type uy =3D (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); }) =20 @@ -114,7 +114,7 @@ static_assert(__builtin_choose_expr(__is_constexpr((lo) > (hi)), \ (lo) <=3D (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); }) =20 @@ -154,7 +154,7 @@ =20 #define __careful_op3(op, x, y, z, ux, uy, uz) ({ \ __auto_type ux =3D (x); __auto_type uy =3D (y);__auto_type uz =3D (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)); }) =20 @@ -326,9 +326,9 @@ static inline bool in_range32(u32 val, u32 start, u32 l= en) * 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)) =20 #endif /* _LINUX_MINMAX_H */ --=20 2.47.3 From nobody Thu Oct 2 04:45:16 2025 Received: from fra-out-008.esa.eu-central-1.outbound.mail-perimeter.amazon.com (fra-out-008.esa.eu-central-1.outbound.mail-perimeter.amazon.com [35.158.23.94]) (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 AAF8A2FF658; Mon, 22 Sep 2025 10:31:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=35.158.23.94 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758537117; cv=none; b=UQF83PtUIhVfCP0lOKpTDjpQE7ad+6hJzNp6ifGaJ5XhmY7xohx9PxzgRcU23Nd5RhKM2/nSL6oIGHMYTCNJJAmlzzQYwYNX9mRxbCL2sZLCV2uTqiq5ynWvBDj92a7wDWlwdtnUQtHamU3H+dzFiYsDELWzJw2qCUHj4IeVjAc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758537117; c=relaxed/simple; bh=7o6n/7afD73I8KmTywLVAVDBtvL4BDHX8Eeq0ODATQ8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Iam1j86lBPuIVnm0/FvvOZKfPME4OzYBGjWQK+oBLKSOyDke4LIVa+T9D1vpJ6ICH8SsoW0LPqpZq4EJukXdxJjqwBq/d7dIHOfxOrvHlzE9KDKc42mHOd8/kfpOQc7O230iRWKdv1c62LubheaHoeLQD38ij7ASkvLixnTxjXs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.com; dkim=pass (2048-bit key) header.d=amazon.com header.i=@amazon.com header.b=ZseQaM3n; arc=none smtp.client-ip=35.158.23.94 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=amazon.com header.i=@amazon.com header.b="ZseQaM3n" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazoncorp2; t=1758537113; x=1790073113; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0AzpApDbX8CFEbC2P7WHNPH2gra+XDIh1eSQ6GUhJZw=; b=ZseQaM3nTjv3PEFbsnEiEgbYj455X727P54JTylRyNc5ukaNrKduwNKG ZWmVV2GPyjEL04BvCeXVvUdwQJo5HP1NVzdG2AjW5j12TIOGU6XGrJgDt taXloW3cDOsw5cdK2Wo0rRdxTA8HwRBKOpvnj4pucpbvHvsrtoJZLgCca 2yOE442T7Pveha12L+FRNDvgbeN9/cwy5ZeWKNLTm4ImkSx/Fva7DZubk 81mx4EadXOG4CP9xJWBcbArXdMmOdPeRDiXRY+00+rlJcBiXhMlgRo9Er c33WUlhlVwWvLJkTmfqSLgUmNjteVesTKpPk9P4eF52zHwV34hQ8qQes1 Q==; X-CSE-ConnectionGUID: odvq3ZZpTyS49u8i0Iy5eQ== X-CSE-MsgGUID: SOYQmnpzS2mAx3i733nmYA== X-IronPort-AV: E=Sophos;i="6.18,284,1751241600"; d="scan'208";a="2478545" Received: from ip-10-6-3-216.eu-central-1.compute.internal (HELO smtpout.naws.eu-central-1.prod.farcaster.email.amazon.dev) ([10.6.3.216]) by internal-fra-out-008.esa.eu-central-1.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2025 10:31:42 +0000 Received: from EX19MTAEUB001.ant.amazon.com [54.240.197.234:13846] by smtpin.naws.eu-central-1.prod.farcaster.email.amazon.dev [10.0.23.64:2525] with esmtp (Farcaster) id b99996d2-d45b-4a9d-96e4-d87059b0f7bf; Mon, 22 Sep 2025 10:31:42 +0000 (UTC) X-Farcaster-Flow-ID: b99996d2-d45b-4a9d-96e4-d87059b0f7bf Received: from EX19D018EUA004.ant.amazon.com (10.252.50.85) by EX19MTAEUB001.ant.amazon.com (10.252.51.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.20; Mon, 22 Sep 2025 10:31:42 +0000 Received: from dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (172.19.116.181) by EX19D018EUA004.ant.amazon.com (10.252.50.85) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.20; Mon, 22 Sep 2025 10:31:37 +0000 From: Eliav Farber To: , , , , , CC: Andy Shevchenko , Christoph Hellwig , Dan Carpenter , "Jason A. Donenfeld" , Jens Axboe , Lorenzo Stoakes , Mateusz Guzik , "Matthew Wilcox" , Pedro Falcato Subject: [PATCH 2/7 6.12.y] minmax.h: update some comments Date: Mon, 22 Sep 2025 10:31:18 +0000 Message-ID: <20250922103123.14538-3-farbere@amazon.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250922103123.14538-1-farbere@amazon.com> References: <20250922103123.14538-1-farbere@amazon.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: EX19D039UWB003.ant.amazon.com (10.13.138.93) To EX19D018EUA004.ant.amazon.com (10.252.50.85) Content-Type: text/plain; charset="utf-8" From: David Laight [ Upstream commit 10666e99204818ef45c702469488353b5bb09ec7 ] - 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. Link: https://lkml.kernel.org/r/85b050c81c1d4076aeb91a6cded45fee@AcuMS.acul= ab.com Signed-off-by: David Laight Cc: Andy Shevchenko Cc: Arnd Bergmann Cc: Christoph Hellwig Cc: Dan Carpenter Cc: Jason A. Donenfeld Cc: Jens Axboe Cc: Lorenzo Stoakes Cc: Mateusz Guzik Cc: Matthew Wilcox Cc: Pedro Falcato Signed-off-by: Andrew Morton Signed-off-by: Eliav Farber --- 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 =20 /* - * 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 'in= t' + * 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 variab= le + * 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)) =20 /* - * 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 integ= ers + * 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 tru= ncate + * 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 --=20 2.47.3 From nobody Thu Oct 2 04:45:16 2025 Received: from fra-out-011.esa.eu-central-1.outbound.mail-perimeter.amazon.com (fra-out-011.esa.eu-central-1.outbound.mail-perimeter.amazon.com [52.28.197.132]) (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 D68F42FDC25; Mon, 22 Sep 2025 10:31:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=52.28.197.132 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758537120; cv=none; b=GeisqQwqeG8CjD+jKL5Ph8CeiC2yGg/EwEMzTZYZPz/gcMw08pgzH7DMAcZwvWIArbaAKm3czN0TvAEORKE81ac1cHAZmVuRAsJYlXJVAYknwHHbCNl9vyKiQuNQ5bdGjcCy15vDARFZSBnFJRj1yUnLjWKehkn3Wqnx8Mprvmg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758537120; c=relaxed/simple; bh=18hVRcjiq6jqKyPc+H8fDwSKZo20vfz8WvHD3u05Y74=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZtAijdI4FzTgzJj/05lCvfda83Lgiji2Ihq/KHI6S7iYX6+ZqaI/GKXMIXz6dPZXXfz5PPrIAD+6LLRM7mNxnvia/2wirBdVcEecoKd3G5wOdIH56rTmhVAVMiFI/NuwHqQ5NY7oclScscZInSn0ckfEqe7tQEDQXE+V324CDtI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.com; dkim=pass (2048-bit key) header.d=amazon.com header.i=@amazon.com header.b=s+6V9NXP; arc=none smtp.client-ip=52.28.197.132 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=amazon.com header.i=@amazon.com header.b="s+6V9NXP" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazoncorp2; t=1758537118; x=1790073118; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=FhepguEQ0VZAS3etCeAAj5D/xXUqupnQ1wf0VPifqWY=; b=s+6V9NXP3SnMuLS5v2EWsYqukrFh9yW0qLEeo6iaUXEcFZwJlZR4emxA RxU9j5b1qQXLuL9svE17jmk51hTcf62xwZMQiKeqY6005QdogckuNfw6K LKfVV2pA41PVH0XPFetifj8ssEUngaOLLHcYxP8VpJ27RYtIfIn+zWTrY vjpuZJe3SDbjL9OAOuIRFbHt1FfqZvQ/hGTL4HaqERJVUbI6QRIZ8h1F9 a8lIt27qEcCeK19XtZHxrNrN/T3u9zzFFenln9RH36PPt1gvI/mow6alg HTQd8G7r6AvkdU9PP2NdsxMqDOWKGuZpfRDDwv5VtwhmBhbte2geoyvry g==; X-CSE-ConnectionGUID: BU54+gz8R4qoBeASiy7j0Q== X-CSE-MsgGUID: Y7Jp5SVGRqGrlUMhaZVZgg== X-IronPort-AV: E=Sophos;i="6.18,284,1751241600"; d="scan'208";a="2372067" Received: from ip-10-6-11-83.eu-central-1.compute.internal (HELO smtpout.naws.eu-central-1.prod.farcaster.email.amazon.dev) ([10.6.11.83]) by internal-fra-out-011.esa.eu-central-1.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2025 10:31:47 +0000 Received: from EX19MTAEUC002.ant.amazon.com [54.240.197.228:1247] by smtpin.naws.eu-central-1.prod.farcaster.email.amazon.dev [10.0.21.238:2525] with esmtp (Farcaster) id f77a31b1-2b16-4e2b-94b2-939375090f63; Mon, 22 Sep 2025 10:31:47 +0000 (UTC) X-Farcaster-Flow-ID: f77a31b1-2b16-4e2b-94b2-939375090f63 Received: from EX19D018EUA004.ant.amazon.com (10.252.50.85) by EX19MTAEUC002.ant.amazon.com (10.252.51.245) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.20; Mon, 22 Sep 2025 10:31:46 +0000 Received: from dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (172.19.116.181) by EX19D018EUA004.ant.amazon.com (10.252.50.85) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.20; Mon, 22 Sep 2025 10:31:42 +0000 From: Eliav Farber To: , , , , , CC: Andy Shevchenko , Christoph Hellwig , Dan Carpenter , "Jason A. Donenfeld" , Jens Axboe , Lorenzo Stoakes , Mateusz Guzik , "Matthew Wilcox" , Pedro Falcato Subject: [PATCH 3/7 6.12.y] minmax.h: reduce the #define expansion of min(), max() and clamp() Date: Mon, 22 Sep 2025 10:31:19 +0000 Message-ID: <20250922103123.14538-4-farbere@amazon.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250922103123.14538-1-farbere@amazon.com> References: <20250922103123.14538-1-farbere@amazon.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: EX19D039UWB003.ant.amazon.com (10.13.138.93) To EX19D018EUA004.ant.amazon.com (10.252.50.85) Content-Type: text/plain; charset="utf-8" From: David Laight [ Upstream commit b280bb27a9f7c91ddab730e1ad91a9c18a051f41 ] 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. Link: https://lkml.kernel.org/r/051afc171806425da991908ed8688a98@AcuMS.acul= ab.com Signed-off-by: David Laight Cc: Andy Shevchenko Cc: Arnd Bergmann Cc: Christoph Hellwig Cc: Dan Carpenter Cc: Jason A. Donenfeld Cc: Jens Axboe Cc: Lorenzo Stoakes Cc: Mateusz Guzik Cc: Matthew Wilcox Cc: Pedro Falcato Signed-off-by: Andrew Morton Signed-off-by: Eliav Farber --- 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)) =20 /* * 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, 1= LL, 1L)) #endif -#define __is_nonneg(x, ux) statically_true((__signed_type(ux))(x) >=3D 0) +#define __is_nonneg(ux) statically_true((__signed_type(ux))(ux) >=3D 0) =20 -#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)) =20 -#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)) =20 #define __cmp_op_min < #define __cmp_op_max > @@ -92,7 +92,7 @@ =20 #define __careful_cmp_once(op, x, y, ux, uy) ({ \ __auto_type ux =3D (x); __auto_type uy =3D (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); }) =20 @@ -109,7 +109,7 @@ static_assert(__builtin_choose_expr(__is_constexpr((lo) > (hi)), \ (lo) <=3D (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); }) =20 @@ -149,7 +149,7 @@ =20 #define __careful_op3(op, x, y, z, ux, uy, uz) ({ \ __auto_type ux =3D (x); __auto_type uy =3D (y);__auto_type uz =3D (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)); }) =20 --=20 2.47.3 From nobody Thu Oct 2 04:45:16 2025 Received: from fra-out-006.esa.eu-central-1.outbound.mail-perimeter.amazon.com (fra-out-006.esa.eu-central-1.outbound.mail-perimeter.amazon.com [18.197.217.180]) (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 73DC02FFFB4; Mon, 22 Sep 2025 10:32:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=18.197.217.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758537142; cv=none; b=UAVGVaOvmoPPeFsirT+2UWyAGuuLNZQ2Sj1shplWvzck9dZoVRVPP24u8VGGTeAButMmV6AXwMv3wkMQhpEyU8LypivKeWErEv+dO1nH3JcGlUcpcCEOfII0iHgMr9tfXFiqm7FNZmPugUSpE6yF1kheb1PcH3ulQ3WV72jf2GA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758537142; c=relaxed/simple; bh=bSiDtvnimcgo6Y3knq8+w917eJDspbmoX3a4FcQGX4g=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ihfFGMbbCfhq9B3wcngn8ahb18PjYh7lsMHaJYwPOHMBIRI9p6CbdYOwhTL5QlKeuib+p8jjP9FN8SeSvzPzl3Dp9o+kkNBpHS+wAwydFctUHevkhIxD5GVY+VUfcJ5Cm9KVhpN+o/UDzCoN14nnfeEhvPvvkIqPDene3+doNQ0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.com; dkim=pass (2048-bit key) header.d=amazon.com header.i=@amazon.com header.b=JSl5B5Hp; arc=none smtp.client-ip=18.197.217.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=amazon.com header.i=@amazon.com header.b="JSl5B5Hp" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazoncorp2; t=1758537140; x=1790073140; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=U4cCFbpHvYq8yWCMIbT6T5sZXi6GGX+iNVIOVWCWFxY=; b=JSl5B5HpfNV9H3maZgxTygWCyLvKiU7hfu2hd4d46Fk3CohxK4FqLyD7 T7+3AfZirjij40wgP8nkSj2YZF3DSOcyXoDeKhQ1y4T+ktblijTCIvGL7 ZvcgN3FzBU2JR2KopuLeYuexPC9FLofQnwilYJjJ7YXNy4t4hnJ5m+0uA 1Ztk+ruMTNcsA/P/HHQG3nWX+6NXT7ILY3HAY/iOL5/dd3mrthtRu86Xv QjMOTr0WWxcEEX7DWFyvkgyaTkAMqLeIF4gatc975zahbd+2jtwkGfyL6 HRiIJWBcr0Q82rmTOLVHo49mfugxyaBjwACl19tKdnfSbXz1DSjjSNoAZ g==; X-CSE-ConnectionGUID: 1jI5RAn4TXWyYVbpj1/Yxw== X-CSE-MsgGUID: 0PqpIIYnTxuQ2H3tEdmKHg== X-IronPort-AV: E=Sophos;i="6.18,284,1751241600"; d="scan'208";a="2476012" Received: from ip-10-6-6-97.eu-central-1.compute.internal (HELO smtpout.naws.eu-central-1.prod.farcaster.email.amazon.dev) ([10.6.6.97]) by internal-fra-out-006.esa.eu-central-1.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2025 10:32:10 +0000 Received: from EX19MTAEUC002.ant.amazon.com [54.240.197.228:30313] by smtpin.naws.eu-central-1.prod.farcaster.email.amazon.dev [10.0.10.226:2525] with esmtp (Farcaster) id 5aac5fa6-1fc8-4a9e-b95c-8bcb740c89e6; Mon, 22 Sep 2025 10:32:10 +0000 (UTC) X-Farcaster-Flow-ID: 5aac5fa6-1fc8-4a9e-b95c-8bcb740c89e6 Received: from EX19D018EUA004.ant.amazon.com (10.252.50.85) by EX19MTAEUC002.ant.amazon.com (10.252.51.245) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.20; Mon, 22 Sep 2025 10:32:09 +0000 Received: from dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (172.19.116.181) by EX19D018EUA004.ant.amazon.com (10.252.50.85) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.20; Mon, 22 Sep 2025 10:32:05 +0000 From: Eliav Farber To: , , , , , CC: Andy Shevchenko , Christoph Hellwig , Dan Carpenter , "Jason A. Donenfeld" , Jens Axboe , Lorenzo Stoakes , Mateusz Guzik , "Matthew Wilcox" , Pedro Falcato Subject: [PATCH 4/7 6.12.y] minmax.h: use BUILD_BUG_ON_MSG() for the lo < hi test in clamp() Date: Mon, 22 Sep 2025 10:31:20 +0000 Message-ID: <20250922103123.14538-5-farbere@amazon.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250922103123.14538-1-farbere@amazon.com> References: <20250922103123.14538-1-farbere@amazon.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: EX19D044UWB003.ant.amazon.com (10.13.139.168) To EX19D018EUA004.ant.amazon.com (10.252.50.85) Content-Type: text/plain; charset="utf-8" From: David Laight [ Upstream commit a5743f32baec4728711bbc01d6ac2b33d4c67040 ] 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. Link: https://lkml.kernel.org/r/34d53778977747f19cce2abb287bb3e6@AcuMS.acul= ab.com Signed-off-by: David Laight Cc: Andy Shevchenko Cc: Arnd Bergmann Cc: Christoph Hellwig Cc: Dan Carpenter Cc: Jason A. Donenfeld Cc: Jens Axboe Cc: Lorenzo Stoakes Cc: Mateusz Guzik Cc: Matthew Wilcox Cc: Pedro Falcato Signed-off-by: Andrew Morton Signed-off-by: Eliav Farber --- 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 =3D (val); \ __auto_type ulo =3D (lo); \ __auto_type uhi =3D (hi); \ - static_assert(__builtin_choose_expr(__is_constexpr((lo) > (hi)), \ - (lo) <=3D (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"); \ --=20 2.47.3 From nobody Thu Oct 2 04:45:16 2025 Received: from fra-out-004.esa.eu-central-1.outbound.mail-perimeter.amazon.com (fra-out-004.esa.eu-central-1.outbound.mail-perimeter.amazon.com [3.74.81.189]) (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 CB72B2FDC59; Mon, 22 Sep 2025 10:32:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=3.74.81.189 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758537139; cv=none; b=rnwordM0aCYsedm6XgDQpl20NTrcZqlSmOwDDIQd7Lh4r/sgZLxsWbqNIhBtqj0xT8MYB1es7BhiwpniotU/gqBAAznxyDZ6zi/+pWoScv4GrBRpDPOCs0/BOqhki5lmAyUeE6p0wHQGa2ZkB/QJlyseGxPjrzwCRlr4HzTtClY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758537139; c=relaxed/simple; bh=vXDjGFm+HJwZhe9olHv5adnVqsW2PTDgXntaLnfVnnY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mmtc4kFNFtFLgK9u/0BPXB9qjppzBp6ibEZlS3SzX+BS5g9hJW7+AzGUDnO1NreujjlaZ21Jmd2IdQzaGujqO05DkMzVua6ix/8hEjJbk33kdtMXUNQGwO2qZ9q5SM1EW9dJ3Ig5IP69Y30BGob8tc+MmqBjNANV+8iNxrK7y1c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.com; dkim=pass (2048-bit key) header.d=amazon.com header.i=@amazon.com header.b=NWYb60ca; arc=none smtp.client-ip=3.74.81.189 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=amazon.com header.i=@amazon.com header.b="NWYb60ca" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazoncorp2; t=1758537137; x=1790073137; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=eLjmOO9Imra/tK5RPFIsLXDdpmNXUJwWiKD0++d4PGI=; b=NWYb60cabj+JqF32f1eR9o2TISwF1u+8Rf6h/31aNTRs3imY2IFbRP3H rC1eJDrdo3pjBLA+z/lJwSV/hJ4pa92krox2GAJPCyj8IEx6oF9HwyjWa C17SrQELH7VMsNkXqtHPEDeOTp5ezkvYgJxKpq71A0R0427OdopNc4qC2 LFlXqblTx3wUwIz/+md/cDDaz9g9Vi0DCXwxGnBgVUYTbxabQEXZknV+d ONvqB/GbmUb7XLgBSDFMztidL8sB9W0vmpsrS/G0PGR5BfK/ckwtHG+// BK3zt2U8clxZ2CvkK8W+RqwWUs2rUyRzwPuoNxg3A37z3AzClTe8yV8FX A==; X-CSE-ConnectionGUID: mj61e+P9TwmOQbjIgqBtkw== X-CSE-MsgGUID: UeBbuDvhRWOu2rxJJqFhUA== X-IronPort-AV: E=Sophos;i="6.18,284,1751241600"; d="scan'208";a="2475116" Received: from ip-10-6-3-216.eu-central-1.compute.internal (HELO smtpout.naws.eu-central-1.prod.farcaster.email.amazon.dev) ([10.6.3.216]) by internal-fra-out-004.esa.eu-central-1.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2025 10:32:14 +0000 Received: from EX19MTAEUB001.ant.amazon.com [54.240.197.234:2971] by smtpin.naws.eu-central-1.prod.farcaster.email.amazon.dev [10.0.39.25:2525] with esmtp (Farcaster) id 5a3495a9-a561-4289-98dd-9b42d03baa65; Mon, 22 Sep 2025 10:32:14 +0000 (UTC) X-Farcaster-Flow-ID: 5a3495a9-a561-4289-98dd-9b42d03baa65 Received: from EX19D018EUA004.ant.amazon.com (10.252.50.85) by EX19MTAEUB001.ant.amazon.com (10.252.51.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.20; Mon, 22 Sep 2025 10:32:14 +0000 Received: from dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (172.19.116.181) by EX19D018EUA004.ant.amazon.com (10.252.50.85) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.20; Mon, 22 Sep 2025 10:32:10 +0000 From: Eliav Farber To: , , , , , CC: Andy Shevchenko , Christoph Hellwig , Dan Carpenter , "Jason A. Donenfeld" , Jens Axboe , Lorenzo Stoakes , Mateusz Guzik , "Matthew Wilcox" , Pedro Falcato Subject: [PATCH 5/7 6.12.y] minmax.h: move all the clamp() definitions after the min/max() ones Date: Mon, 22 Sep 2025 10:31:21 +0000 Message-ID: <20250922103123.14538-6-farbere@amazon.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250922103123.14538-1-farbere@amazon.com> References: <20250922103123.14538-1-farbere@amazon.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: EX19D044UWB003.ant.amazon.com (10.13.139.168) To EX19D018EUA004.ant.amazon.com (10.252.50.85) Content-Type: text/plain; charset="utf-8" From: David Laight [ Upstream commit c3939872ee4a6b8bdcd0e813c66823b31e6e26f7 ] 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. Link: https://lkml.kernel.org/r/8bb285818e4846469121c8abc3dfb6e2@AcuMS.acul= ab.com Signed-off-by: David Laight Cc: Andy Shevchenko Cc: Arnd Bergmann Cc: Christoph Hellwig Cc: Dan Carpenter Cc: Jason A. Donenfeld Cc: Jens Axboe Cc: Lorenzo Stoakes Cc: Mateusz Guzik Cc: Matthew Wilcox Cc: Pedro Falcato Signed-off-by: Andrew Morton Signed-off-by: Eliav Farber --- 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_)) =20 -#define __clamp(val, lo, hi) \ - ((val) >=3D (hi) ? (hi) : ((val) <=3D (lo) ? (lo) : (val))) - -#define __clamp_once(val, lo, hi, uval, ulo, uhi) ({ \ - __auto_type uval =3D (val); \ - __auto_type ulo =3D (lo); \ - __auto_type uhi =3D (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_)) =20 +/** + * 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 z= ero * @x: value1 @@ -180,6 +180,22 @@ typeof(y) __y =3D (y); \ __x =3D=3D 0 ? __y : ((__y =3D=3D 0) ? __x : min(__x, __y)); }) =20 +#define __clamp(val, lo, hi) \ + ((val) >=3D (hi) ? (hi) : ((val) <=3D (lo) ? (lo) : (val))) + +#define __clamp_once(val, lo, hi, uval, ulo, uhi) ({ \ + __auto_type uval =3D (val); \ + __auto_type ulo =3D (lo); \ + __auto_type uhi =3D (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) =20 -/* - * ..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)) =20 /** - * 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 unsign= ed + * type and @lo and @hi are literals that will otherwise be assigned a sig= ned + * 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) =20 /* * Do not check the array parameter using __must_be_array(). @@ -257,31 +275,6 @@ */ #define max_array(array, len) __minmax_array(max, array, len) =20 -/** - * 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 unsign= ed - * type and @lo and @hi are literals that will otherwise be assigned a sig= ned - * 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; --=20 2.47.3 From nobody Thu Oct 2 04:45:16 2025 Received: from fra-out-004.esa.eu-central-1.outbound.mail-perimeter.amazon.com (fra-out-004.esa.eu-central-1.outbound.mail-perimeter.amazon.com [3.74.81.189]) (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 DB4B72FF67F; Mon, 22 Sep 2025 10:32:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=3.74.81.189 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758537142; cv=none; b=vABUq7EmFfpgA8eGsSDDfO1m8eRqxtOKVKwYz6wY5Bk/0ZR+0jbgA2HF1HH9vWlYhnRnemN2krgEW+3x9sS6Wg3tjP7wzGuy57R8pZJ89j63MGJsXzrqzgsGIeVDvzeKI/cfKSFOooraOojaXjgxVVyixCVOHieIAKZhx7We1PQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758537142; c=relaxed/simple; bh=M+DzBGorF0x2HwKxbRALu5Mz4okNvOwcKTlN8glrxuQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=bAWcuUdBJ304Nc947QJes8WHEd9ZLVW/uZUIEed+3DRANh98hwdaxrv+3/mo0/8gW7DD4A0t8Uwyv9HhY9tSVxaT07zp5eQEqIAgm7nU6VN69S3zMm/oaursx04zzGdK+lwbx90gauSN7h+6rflUItDUz8L8ovVMC+R0jzgE89g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.com; dkim=pass (2048-bit key) header.d=amazon.com header.i=@amazon.com header.b=m8FSUyE/; arc=none smtp.client-ip=3.74.81.189 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=amazon.com header.i=@amazon.com header.b="m8FSUyE/" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazoncorp2; t=1758537140; x=1790073140; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8djAgabF22BDsxfYcNFa72Q6mXnC3doUyHk+thXHzBc=; b=m8FSUyE/n4ZHYV0fTcK58iikQDGar5tNIdFtT2Qz6iNygxWNt2rP2F4g txp2TToiWRyvBHdxbZkjdSucCRYGbp7WR0TzbxFLXpJtXaORZRjPEv/6W zMU7LjvfEC8gwOQe1Bgnsz7XEariVFQo5NrBuhL3WuoghstFiasMLX0WM 2tmiQG8u4Spd1xr8GhpojuSH7jvBPxvb3Oay7AaE+7ddiob7C6xCI3mem uQ2fK/Zgb8a7kPAjHo/A2CsGaRbo5R8xX3eN6FqXv5lG0F/eLGycIiLZ+ Mx39+0iPZsR2lMidiZna789WMLTtrvrEh/OHaa9EnbERbaUpy1Fbt4Udq w==; X-CSE-ConnectionGUID: yS4WVbWFR6yJ2dUwWAhBOQ== X-CSE-MsgGUID: +S4Nh2FFTG+yjHzD2ltijQ== X-IronPort-AV: E=Sophos;i="6.18,284,1751241600"; d="scan'208";a="2475125" Received: from ip-10-6-3-216.eu-central-1.compute.internal (HELO smtpout.naws.eu-central-1.prod.farcaster.email.amazon.dev) ([10.6.3.216]) by internal-fra-out-004.esa.eu-central-1.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2025 10:32:19 +0000 Received: from EX19MTAEUC002.ant.amazon.com [54.240.197.228:11130] by smtpin.naws.eu-central-1.prod.farcaster.email.amazon.dev [10.0.21.238:2525] with esmtp (Farcaster) id 60e16807-4864-46b6-823a-89f1e0206c07; Mon, 22 Sep 2025 10:32:19 +0000 (UTC) X-Farcaster-Flow-ID: 60e16807-4864-46b6-823a-89f1e0206c07 Received: from EX19D018EUA004.ant.amazon.com (10.252.50.85) by EX19MTAEUC002.ant.amazon.com (10.252.51.245) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.20; Mon, 22 Sep 2025 10:32:18 +0000 Received: from dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (172.19.116.181) by EX19D018EUA004.ant.amazon.com (10.252.50.85) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.20; Mon, 22 Sep 2025 10:32:14 +0000 From: Eliav Farber To: , , , , , CC: Andy Shevchenko , Christoph Hellwig , Dan Carpenter , "Jason A. Donenfeld" , Jens Axboe , Lorenzo Stoakes , Mateusz Guzik , "Matthew Wilcox" , Pedro Falcato Subject: [PATCH 6/7 6.12.y] minmax.h: simplify the variants of clamp() Date: Mon, 22 Sep 2025 10:31:22 +0000 Message-ID: <20250922103123.14538-7-farbere@amazon.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250922103123.14538-1-farbere@amazon.com> References: <20250922103123.14538-1-farbere@amazon.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: EX19D044UWB003.ant.amazon.com (10.13.139.168) To EX19D018EUA004.ant.amazon.com (10.252.50.85) Content-Type: text/plain; charset="utf-8" From: David Laight [ Upstream commit 495bba17cdf95e9703af1b8ef773c55ef0dfe703 ] 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. Link: https://lkml.kernel.org/r/8f69f4deac014f558bab186444bac2e8@AcuMS.acul= ab.com Signed-off-by: David Laight Cc: Andy Shevchenko Cc: Arnd Bergmann Cc: Christoph Hellwig Cc: Dan Carpenter Cc: Jason A. Donenfeld Cc: Jens Axboe Cc: Lorenzo Stoakes Cc: Mateusz Guzik Cc: Matthew Wilcox Cc: Pedro Falcato Signed-off-by: Andrew Morton Signed-off-by: Eliav Farber --- 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) >=3D (hi) ? (hi) : ((val) <=3D (lo) ? (lo) : (val))) =20 -#define __clamp_once(val, lo, hi, uval, ulo, uhi) ({ \ - __auto_type uval =3D (val); \ - __auto_type ulo =3D (lo); \ - __auto_type uhi =3D (hi); \ +#define __clamp_once(type, val, lo, hi, uval, ulo, uhi) ({ \ + type uval =3D (val); \ + type ulo =3D (lo); \ + type uhi =3D (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); }) =20 -#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_), __UNIQU= E_ID(h_)) =20 /** - * 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) =20 /** * 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) =20 /** * 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 sig= ned * 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) =20 /* * Do not check the array parameter using __must_be_array(). --=20 2.47.3 From nobody Thu Oct 2 04:45:16 2025 Received: from fra-out-006.esa.eu-central-1.outbound.mail-perimeter.amazon.com (fra-out-006.esa.eu-central-1.outbound.mail-perimeter.amazon.com [18.197.217.180]) (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 16EB62FFDF7; Mon, 22 Sep 2025 10:32:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=18.197.217.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758537154; cv=none; b=gzGDK5xbLhSf7RH3TV1DJQUz6y5UubV4OnKOqDP/gh6urlCQZHdnO3YaRagFm3czQGOY2OnSE0zIDpF9e2Osn/iG5GAZiF5e9fqtmXCt4lnxwUSNiA8TVyiEu2S6wC63zHoYF3/LIWUuINRTa46u+LrOg7sdGXz+/2sErp7+sjw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758537154; c=relaxed/simple; bh=V2L3IilwofpV6SrsfVTvut5ipDXkokIOm+dTBT4i7eQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=TJ7Rucsg4E7WZ8Bgu3LtVuUoYeR7w4c7jv6rzxbRnno1P+HaCqt6tgtlLNdQiTE+3COfN4t3KdUYMTuzloE+nTFfDb/DFblrG1E+p2jS5+3J171eae9b0RfSbJuvjvYkNvA+b4CeaVssi+PN45m4Nf2FrMTAkxC+WIbhcL10y1c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.com; dkim=pass (2048-bit key) header.d=amazon.com header.i=@amazon.com header.b=IthLrmRu; arc=none smtp.client-ip=18.197.217.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=amazon.com header.i=@amazon.com header.b="IthLrmRu" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazoncorp2; t=1758537152; x=1790073152; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=k0dUe76w+6n5/NfsPbyefGVCom+xh3GGcFcV3Olhmks=; b=IthLrmRuVftwWeeGsu/xokV0H6tjX/uyvcL3e5rD+E9jdslwod+jYVgX lU0gyy8odyv1VyL3pJDMVQHK2XWwWWyO1ZEoqolHgL54q3Y8bmmSyXqFc MqEz3Zs5MBQfcg4kfeEqN+400kUXmV9nb+mALky8032AiwKnMLKJHfHE6 6fddQoD8oqUc97ur3mf7Sz+y2a2fdAekiFnsJKH/S2PCS/ek1yPs2eX9J w0+TtG1uiqtR3Uku7RbzxT+IbTZRbc9kqPfhRR9wWN1ChtwM9dIunqcxP h0b87C4EybOvB52ykrvrkJEdp03UvVeYcP6zk7Ls8f3u+getvJU/7xS6F w==; X-CSE-ConnectionGUID: wHuFl3MBT0m5MiBr6lj/0Q== X-CSE-MsgGUID: c/DAsGjMRFOZ6E8jGS9vCQ== X-IronPort-AV: E=Sophos;i="6.18,284,1751241600"; d="scan'208";a="2476069" Received: from ip-10-6-11-83.eu-central-1.compute.internal (HELO smtpout.naws.eu-central-1.prod.farcaster.email.amazon.dev) ([10.6.11.83]) by internal-fra-out-006.esa.eu-central-1.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2025 10:32:26 +0000 Received: from EX19MTAEUA002.ant.amazon.com [54.240.197.232:30767] by smtpin.naws.eu-central-1.prod.farcaster.email.amazon.dev [10.0.21.238:2525] with esmtp (Farcaster) id 1d3c3639-bbe2-4944-83c5-86a00262327e; Mon, 22 Sep 2025 10:32:26 +0000 (UTC) X-Farcaster-Flow-ID: 1d3c3639-bbe2-4944-83c5-86a00262327e Received: from EX19D018EUA004.ant.amazon.com (10.252.50.85) by EX19MTAEUA002.ant.amazon.com (10.252.50.126) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.20; Mon, 22 Sep 2025 10:32:23 +0000 Received: from dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (172.19.116.181) by EX19D018EUA004.ant.amazon.com (10.252.50.85) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.20; Mon, 22 Sep 2025 10:32:19 +0000 From: Eliav Farber To: , , , , , CC: Andy Shevchenko , Christoph Hellwig , Dan Carpenter , "Jason A. Donenfeld" , Jens Axboe , Lorenzo Stoakes , Mateusz Guzik , "Matthew Wilcox" , Pedro Falcato Subject: [PATCH 7/7 6.12.y] minmax.h: remove some #defines that are only expanded once Date: Mon, 22 Sep 2025 10:31:23 +0000 Message-ID: <20250922103123.14538-8-farbere@amazon.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250922103123.14538-1-farbere@amazon.com> References: <20250922103123.14538-1-farbere@amazon.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: EX19D044UWB003.ant.amazon.com (10.13.139.168) To EX19D018EUA004.ant.amazon.com (10.252.50.85) Content-Type: text/plain; charset="utf-8" From: David Laight [ Upstream commit 2b97aaf74ed534fb838d09867d09a3ca5d795208 ] 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. Link: https://lkml.kernel.org/r/9386d1ebb8974fbabbed2635160c3975@AcuMS.acul= ab.com Signed-off-by: David Laight Cc: Andy Shevchenko Cc: Arnd Bergmann Cc: Christoph Hellwig Cc: Dan Carpenter Cc: Jason A. Donenfeld Cc: Jens Axboe Cc: Lorenzo Stoakes Cc: Mateusz Guzik Cc: Matthew Wilcox Cc: Pedro Falcato Signed-off-by: Andrew Morton Signed-off-by: Eliav Farber --- 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))) =20 /* * 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 integ= ers * 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__ =3D=3D __SIZEOF_LONG_LONG__ +#define __is_nonneg(ux) statically_true((long long)(ux) >=3D 0) #else - #define __signed_type(ux) typeof(__builtin_choose_expr(sizeof(ux) > 4, 1= LL, 1L)) +#define __is_nonneg(ux) statically_true( \ + (typeof(__builtin_choose_expr(sizeof(ux) > 4, 1LL, 1L)))(ux) >=3D 0) #endif -#define __is_nonneg(ux) statically_true((__signed_type(ux))(ux) >=3D 0) =20 #define __types_ok(ux, uy) \ (__sign_use(ux) & __sign_use(uy)) --=20 2.47.3