From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 37167CAC5B8 for ; Mon, 6 Oct 2025 10:40:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:Message-ID:In-Reply-To:Date:From:Cc:To:Subject: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:References:List-Owner; bh=HFD+XAs2zCyALFYQ03bIme/saFvTjOfsZFo9itLTFv0=; b=eeyO8cUS2lYcSQrNdbAVHQpAzJ Z/K5uUHtTA7RnqBrKYab6QrzRiZywk5xLLRIiVIj3jW1+hHdlydC/fTjP2bkIlDEPxyk/9IzBIzQm fEbmcdrXK/lkMu2eHfg+I/IhSItcxcbwmnxpnBR+FyxAbeVglvZuk13aoMokH1nV59x2bTGWenND7 hTJ59E5SJnkh8tRMnllK4f3ATmhjTS5/FzfpxleTlaVEqJbiwKo2eQ+AXPStMh/7EqXOieWAD8yI6 Y9ArmGlAmfV2BNGEUlOfrk1uOh976z+hcjd8ysSZ9owm2E2TA3y86xFLCu6yQUSFlr4D4Zqc7XHwS x1JikW+Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1v5idy-0000000HOOt-2m83; Mon, 06 Oct 2025 10:40:38 +0000 Received: from tor.source.kernel.org ([2600:3c04:e001:324:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1v5idw-0000000HOL8-0TWM for linux-arm-kernel@lists.infradead.org; Mon, 06 Oct 2025 10:40:36 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by tor.source.kernel.org (Postfix) with ESMTP id 5D40060443; Mon, 6 Oct 2025 10:40:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 77FAEC4CEF5; Mon, 6 Oct 2025 10:40:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1759747235; bh=DwIyVJT3dSSmH8DWM854dvwN6Q/1K9V6X6EKRDvtEk0=; h=Subject:To:Cc:From:Date:In-Reply-To:From; b=fTxOQSgBlKBLzOW53qSbxWFlg0rfirHt9QOgXkFTn3q7GhALCWuugfj0dZgAdW31r E/h6d0o2sJv4axljUn/CHCVDf2aJ5Hb5e6ZC9laL3hkm9PUPONymAauiIVtYpCuf8S 39QJ2bmjAV59mk+D2TXpGapRQQJUIRV1EU1p7iEU= Subject: Patch "minmax.h: simplify the variants of clamp()" has been added to the 6.1-stable tree To: David.Laight@ACULAB.COM,Jason@zx2c4.com,agk@redhat.com,airlied@gmail.com,akpm@linux-foundation.org,alexander.deucher@amd.com,amd-gfx@lists.freedesktop.org,andriy.shevchenko@linux.intel.com,arnd@kernel.org,asad.kamal@amd.com,axboe@kernel.dk,christian.koenig@amd.com,clm@fb.com,dan.carpenter@linaro.org,david.laight@aculab.com,dm-devel@lists.linux.dev,dmitry.torokhov@gmail.com,dri-devel@lists.freedesktop.org,dsterba@suse.com,farbere@amazon.com,gregkh@linuxfoundation.org,hch@infradead.org,jernej.skrabec@gmail.com,kenneth.feng@amd.com,kevinyang.wang@amd.com,lijo.lazar@amd.com,linus.walleij@linaro.org,linux-arm-kernel@lists.infradead.org,linux-sunxi@lists.linux.dev,linux@rasmusvillemoes.dk,lorenzo.stoakes@oracle.com,luc.vanoostenryck@gmail.com,mjguzik@gmail.com,mpatocka@redhat.com,pedro.falcato@gmail.com,pmladek@suse.com,rostedt@goodmis.org,samuel@sholland.org,senozhatsky@chromium.org,simona@ffwll.ch,snitzer@kernel.org,tglx@linutronix.de,wens@csie.org,willy@infradead.org Cc: From: Date: Mon, 06 Oct 2025 12:39:12 +0200 In-Reply-To: <20251003121520.8176-11-farbere@amazon.com> Message-ID: <2025100612-sarcasm-flashy-5e0a@gregkh> MIME-Version: 1.0 Content-Type: text/plain; charset=ANSI_X3.4-1968 Content-Transfer-Encoding: 8bit X-stable: commit X-Patchwork-Hint: ignore X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This is a note to let you know that I've just added the patch titled minmax.h: simplify the variants of clamp() to the 6.1-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: minmax.h-simplify-the-variants-of-clamp.patch and it can be found in the queue-6.1 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let know about it. >From stable+bounces-183181-greg=kroah.com@vger.kernel.org Fri Oct 3 14:28:17 2025 From: Eliav Farber Date: Fri, 3 Oct 2025 12:15:19 +0000 Subject: minmax.h: simplify the variants of clamp() To: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Cc: Arnd Bergmann , Christoph Hellwig , Dan Carpenter , "Jason A. Donenfeld" , Jens Axboe , Lorenzo Stoakes , Mateusz Guzik , "Matthew Wilcox" , Pedro Falcato Message-ID: <20251003121520.8176-11-farbere@amazon.com> 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.aculab.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 Signed-off-by: Greg Kroah-Hartman --- include/linux/minmax.h | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) --- 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(). Patches currently in stable-queue which might be from farbere@amazon.com are queue-6.1/minmax-improve-macro-expansion-and-type-checking.patch queue-6.1/minmax.h-simplify-the-variants-of-clamp.patch queue-6.1/minmax.h-move-all-the-clamp-definitions-after-the-min-max-ones.patch queue-6.1/minmax-don-t-use-max-in-situations-that-want-a-c-constant-expression.patch queue-6.1/minmax.h-remove-some-defines-that-are-only-expanded-once.patch queue-6.1/minmax.h-use-build_bug_on_msg-for-the-lo-hi-test-in-clamp.patch queue-6.1/minmax-simplify-min-max-clamp-implementation.patch queue-6.1/minmax.h-add-whitespace-around-operators-and-after-commas.patch queue-6.1/minmax-fix-up-min3-and-max3-too.patch queue-6.1/minmax.h-reduce-the-define-expansion-of-min-max-and-clamp.patch queue-6.1/minmax.h-update-some-comments.patch