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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 72898CCD184 for ; Fri, 17 Oct 2025 08:16:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CF4CA8E0048; Fri, 17 Oct 2025 04:16:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C7E728E0016; Fri, 17 Oct 2025 04:16:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B6D838E0048; Fri, 17 Oct 2025 04:16:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 9E8598E0016 for ; Fri, 17 Oct 2025 04:16:50 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 691811DFDAF for ; Fri, 17 Oct 2025 08:16:50 +0000 (UTC) X-FDA: 84006900180.10.7A63F4F Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by imf16.hostedemail.com (Postfix) with ESMTP id 9692D18000C for ; Fri, 17 Oct 2025 08:16:48 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=fail ("body hash did not verify") header.d=linuxfoundation.org header.s=korg header.b=gXjndgCu; spf=pass (imf16.hostedemail.com: domain of gregkh@linuxfoundation.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org; dmarc=pass (policy=none) header.from=linuxfoundation.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1760689008; 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:dkim-signature; bh=PHuEhSEl4MRmNCzo4Ub5GpIUeSTcy95EXO8KXcEcLGY=; b=peBrHI326z/QKkbnZ3/rlGw1pvHIagh6LZX/ri2FSdhTJofIj81GAQD/q6H+RJAjdfnHCL 0/28gZk4BUVpawidv7ji9eX4hCmT1ti0njq3nNEEoHSTQctOZmXK5JftzUeoEkWj2pUcYg PoOSavx3K8RUwrEyeXMK68Pakpt2CA8= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=fail ("body hash did not verify") header.d=linuxfoundation.org header.s=korg header.b=gXjndgCu; spf=pass (imf16.hostedemail.com: domain of gregkh@linuxfoundation.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org; dmarc=pass (policy=none) header.from=linuxfoundation.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1760689008; a=rsa-sha256; cv=none; b=QR4YlDqohDFiWsh+mi2mfB+wT72/mhhceou2hK34LaZcTADmpJMej3d1gSepUaNPKtRv85 s4Is2xjZjbI/91N1txKE9qsbuHl+TEUOaHVuEvsxaWJIpQGZl8fdDv647FgOjC9JdzS5hj 4MAEo+omUQZlkM+ADlRORT8l34lH8vk= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id 9351B4B002; Fri, 17 Oct 2025 08:16:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E67D0C4CEFE; Fri, 17 Oct 2025 08:16:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1760689007; bh=IZp8/GMuXp6QraNcAKXUTsG2tBOrqDuZVa9XkkKMO+k=; h=Subject:To:Cc:From:Date:In-Reply-To:From; b=gXjndgCup14D+INtA6mLCK2+v5u3qEF7Mn+kggU8yY8OK293VssE4VTJ6fcOpTYn2 ZPc+NhWns7dzp3+03VLLsLe+AynUge9PlCpdE7uu6ssEzQky+YuevQV26hRvceGrnU 6KjOJKuI0Pzip6fFYffMA/J23JsJLwqJt1aINpv4= Subject: Patch "minmax.h: simplify the variants of clamp()" has been added to the 5.15-stable tree To: David.Laight@ACULAB.COM, Jason@zx2c4.com, adilger.kernel@dilger.ca, agk@redhat.com, airlied@linux.ie, akpm@linux-foundation.org, amd-gfx@lists.freedesktop.org, andriy.shevchenko@linux.intel.com, anton.ivanov@cambridgegreys.com, arnd@kernel.org, axboe@kernel.dk, bp@alien8.de, clm@fb.com, coreteam@netfilter.org, dan.carpenter@linaro.org, daniel@ffwll.ch, dave.hansen@linux.intel.com, davem@davemloft.net, david.laight@aculab.com, dm-devel@redhat.com, dmitry.torokhov@gmail.com, dri-devel@lists.freedesktop.org, dsahern@kernel.org, dsterba@suse.com, dushistov@mail.ru, farbere@amazon.com, freedreno@lists.freedesktop.org, fw@strlen.de, gregkh@linuxfoundation.org, hch@infradead.org, hdegoede@redhat.com, herve.codina@bootlin.com, hpa@zytor.com, jack@suse.com, james.morse@arm.com, jdelvare@suse.com, jdike@addtoit.com, jejb@linux.ibm.com, jernej.skrabec@gmail.com, jmaloy@redhat.com, josef@toxicpanda.com, kadlec@netfilter.org, krzysztof.kozlowski@canonical.com, kuba@kernel.org, linus.walleij@linaro.org, linux-arm-kernel@lists.infradead.o, rg@kvack.org, linux-mm@kvack.org, linux-staging@lists.linux.dev, linux-stm32@st-md-mailman.stormreply.com, linux-sunxi@lists.linux.dev, linux-um@lists.infradead.org, linux@rasmusvillemoes.dk, linux@roeck-us.net, lorenzo.stoakes@oracle.com, luc.vanoostenryck@gmail.com, luto@kernel.org, maarten.lankhorst@linux.intel.com, malattia@linux.it, martin.petersen@oracle.com, maz@kernel.org, mcoquelin.stm32@gmail.com, mgross@linux.intel.com, minchan@kernel.org, mingo@redhat.com, mjguzik@gmail.com, mripard@kernel.org, ngupta@vflare.org, pablo@netfilter.org, pedro.falcato@gmail.com, peterz@infradead.org, pmladek@suse.com, qiuxu.zhuo@intel.com, quic_akhilpo@quicinc.com, richard@nod.at, robdclark@gmail.com, rostedt@goodmis.org, rric@kernel.org, ruanjinjie@huawei.com, sakari.ailus@linux.intel.com, sashal@kernel.org, sean@poorly.run, senozhatsky@chromium.org, shuah@kernel.org, snitzer@redhat.com, tglx@linutronix.de, tipc-discussion@lists.sourceforge.net, tony.luck@intel.com, tytso@mit.edu, tzimmermann@suse.de, wens@csie.org, willy@infradead.org, x86@kern.kvack.org, el.org@kvack.org, ying.xue@windriver.com, yoshfuji@linux-ipv6.org Cc: From: Date: Fri, 17 Oct 2025 10:16:19 +0200 In-Reply-To: <20251008152946.29285-19-farbere@amazon.com> Message-ID: <2025101719-art-pang-4c25@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-Stat-Signature: k77trx5wsmyg8b4cpfjs8f161ckukjm6 X-Rspamd-Queue-Id: 9692D18000C X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1760689008-203335 X-HE-Meta: U2FsdGVkX1/rqaeii7uJuryXt613T0EkcRGjfqXd8cwiYiGPb18lSWawhl74F1+ns5U8SI1uUahySc65YhL28ntpbU3owgDB3O/MNMiy3ksjNB9xUSOm4od0RnpVKKj8uV4HeBj+MV4Vrp9mVD1FN0sExQgLngwRkNwIgtFv6CvdXjtFJ62ZslhBoBtY1oZSFjlpqXn0MIHUeDIL096weUQI1LjXOtu8iws+Da07DDBRtM8pbAy8jQbcnUH9BeBG0bev7QGBA0WdnIwgObWJWiLfpl1OMUXGo1p+a7Jlg6pOMnpsTSiDG6pF2zx47QbBOCf0t8ZOKw+F/ssTcTUuLUXMLK7qt8MUWmnyqimg1Txennnb9MKs01BgIq+/hDCHTtjjEaFujLw5oH5KLEZ2m+4nAod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wPm1XHSsWnU57/g3FnIIiiawV7uW5ori37g3XKeHPf1hLTogYmxZXy9MV61L0mxOnTF9Y3lubAi7R85cHL3nncRFyTSq20QzhmQmBrD4qVpL0AjCAXE4lBuFVrjoJ+rPdG2xtiR9rpWG+0No9D0cPe7qnzoZ1xrA37HyXpmHjpSz3wSUtn1fFp1Yrjb8QabT8BiMm/cUoeKbFzEBDuJP4JQBBVEZwxW1KbzCFxfImhxvEeg/gvevOQixoDjDlAGHbBiidCsYVIIb88ddsT5YngXJmF+RuaVmqGTHEhgM+9tZ9Rs 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: 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 5.15-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-5.15 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let know about it. >From prvs=36971892a=farbere@amazon.com Wed Oct 8 17:35:26 2025 From: Eliav Farber Date: Wed, 8 Oct 2025 15:29:43 +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 , "Pedro Falcato" Message-ID: <20251008152946.29285-19-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-5.15/minmax-add-a-few-more-min_t-max_t-users.patch queue-5.15/minmax-improve-macro-expansion-and-type-checking.patch queue-5.15/minmax-fix-indentation-of-__cmp_once-and-__clamp_once.patch queue-5.15/minmax.h-simplify-the-variants-of-clamp.patch queue-5.15/minmax-add-in_range-macro.patch queue-5.15/minmax.h-move-all-the-clamp-definitions-after-the-min-max-ones.patch queue-5.15/minmax-don-t-use-max-in-situations-that-want-a-c-constant-expression.patch queue-5.15/minmax.h-remove-some-defines-that-are-only-expanded-once.patch queue-5.15/minmax.h-use-build_bug_on_msg-for-the-lo-hi-test-in-clamp.patch queue-5.15/minmax-simplify-min-max-clamp-implementation.patch queue-5.15/minmax-deduplicate-__unconst_integer_typeof.patch queue-5.15/minmax-simplify-and-clarify-min_t-max_t-implementation.patch queue-5.15/minmax.h-add-whitespace-around-operators-and-after-commas.patch queue-5.15/minmax-avoid-overly-complicated-constant-expressions-in-vm-code.patch queue-5.15/minmax-make-generic-min-and-max-macros-available-everywhere.patch queue-5.15/minmax-fix-up-min3-and-max3-too.patch queue-5.15/minmax.h-reduce-the-define-expansion-of-min-max-and-clamp.patch queue-5.15/minmax-introduce-min-max-_array.patch queue-5.15/minmax.h-update-some-comments.patch