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 522FDCCD1A2 for ; Fri, 17 Oct 2025 08:06:00 +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=Bng1/1BVXUk1NKCno716V5LgVGQ1BNvdNFZ4NcMDgJ0=; b=S4G2I75BCH8QozpSECvbq6pjQV 0sCOLeUC85fXP9R5Ff9bjCvwxd5GhfrSfLYrVn6cSlUWp3L8IAMikA1//U73p1Eg1vzcebSiPfB/v uxi9NbEleW2dtQWwP2AvjT+whkzmuzluUcz0Wr4ziYc8wtWY012to+DhbrzmLFDMTFm81P3+tRtzo dDnvRN6U8KLoW1Nxsmu3ktFQYKnQ3T7KIpEyRdITHltGay6ZTvXGgEeGik5bR3VDFGe1r8nHIj4dF Cgkcv9nZsV8JcLW/hQkOidROHU4Pk8PyqY0t/IkkvsqMzzff7nUkx34SF0VBaK9eGqRA7CqHD80EB S1S+wOGg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1v9fTK-0000000725v-1Djz; Fri, 17 Oct 2025 08:05:58 +0000 Received: from sea.source.kernel.org ([172.234.252.31]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1v9fTH-0000000724G-0knC; Fri, 17 Oct 2025 08:05:56 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id 782DD45A8B; Fri, 17 Oct 2025 08:05:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BA077C4CEFE; Fri, 17 Oct 2025 08:05:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1760688354; bh=YOfE2dusPxaWBKd8nlIpPYnwK35lY1FgnMY8GHpw1To=; h=Subject:To:Cc:From:Date:In-Reply-To:From; b=JcEpuLh21dmJKWXrm44O7oJmNoJlFlyi6s6Dm4FuBhtcupBDvQfT65Prt1n2HtDBS xBwgoRWEMXdLoAOER/yaeb8+GPzvm2l22izBRaXSxpokwLD2+iwF22GcUPcwpdXo/6 7LDHOeaqaB3dcdM5iV5xAE+D8EaLIejXTBoGK9B8= Subject: Patch "minmax: Introduce {min,max}_array()" has been added to the 5.15-stable tree To: David.Laight@ACULAB.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,andy.shevchenko@gmail.com,anton.ivanov@cambridgegreys.com,bp@alien8.de,broonie@kernel.org,christophe.leroy@csgroup.eu,clm@fb.com,coreteam@netfilter.org,daniel@ffwll.ch,dave.hansen@linux.intel.com,davem@davemloft.net,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,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.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,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,mripard@kernel.org,ngupta@vflare.org,pablo@netfilter.org,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@kernel.org,ying.xue@windriver.com,yoshfuji@linux-ipv6.org Cc: From: Date: Fri, 17 Oct 2025 10:05:10 +0200 In-Reply-To: <20251008152946.29285-3-farbere@amazon.com> Message-ID: <2025101710-unclamped-refract-c17a@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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20251017_010555_256857_E1C68529 X-CRM114-Status: GOOD ( 14.69 ) X-BeenThere: linux-um@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-um" Errors-To: linux-um-bounces+linux-um=archiver.kernel.org@lists.infradead.org This is a note to let you know that I've just added the patch titled minmax: Introduce {min,max}_array() 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-introduce-min-max-_array.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 stable+bounces-183614-greg=kroah.com@vger.kernel.org Wed Oct 8 17:31:31 2025 From: Eliav Farber Date: Wed, 8 Oct 2025 15:29:27 +0000 Subject: minmax: Introduce {min,max}_array() To: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Cc: Andy Shevchenko , Christophe Leroy Message-ID: <20251008152946.29285-3-farbere@amazon.com> From: Herve Codina [ Upstream commit c952c748c7a983a8bda9112984e6f2c1f6e441a5 ] Introduce min_array() (resp max_array()) in order to get the minimal (resp maximum) of values present in an array. Signed-off-by: Herve Codina Reviewed-by: Andy Shevchenko Reviewed-by: Christophe Leroy Link: https://lore.kernel.org/r/20230623085830.749991-8-herve.codina@bootlin.com Signed-off-by: Mark Brown Signed-off-by: Eliav Farber Signed-off-by: Greg Kroah-Hartman --- include/linux/minmax.h | 64 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) --- a/include/linux/minmax.h +++ b/include/linux/minmax.h @@ -168,6 +168,70 @@ */ #define max_t(type, x, y) __careful_cmp(max, (type)(x), (type)(y)) +/* + * Remove a const qualifier from integer types + * _Generic(foo, type-name: association, ..., default: association) performs a + * comparison against the foo type (not the qualified type). + * Do not use the const keyword in the type-name as it will not match the + * unqualified type of foo. + */ +#define __unconst_integer_type_cases(type) \ + unsigned type: (unsigned type)0, \ + signed type: (signed type)0 + +#define __unconst_integer_typeof(x) typeof( \ + _Generic((x), \ + char: (char)0, \ + __unconst_integer_type_cases(char), \ + __unconst_integer_type_cases(short), \ + __unconst_integer_type_cases(int), \ + __unconst_integer_type_cases(long), \ + __unconst_integer_type_cases(long long), \ + default: (x))) + +/* + * Do not check the array parameter using __must_be_array(). + * In the following legit use-case where the "array" passed is a simple pointer, + * __must_be_array() will return a failure. + * --- 8< --- + * int *buff + * ... + * min = min_array(buff, nb_items); + * --- 8< --- + * + * The first typeof(&(array)[0]) is needed in order to support arrays of both + * 'int *buff' and 'int buff[N]' types. + * + * The array can be an array of const items. + * typeof() keeps the const qualifier. Use __unconst_integer_typeof() in order + * to discard the const qualifier for the __element variable. + */ +#define __minmax_array(op, array, len) ({ \ + typeof(&(array)[0]) __array = (array); \ + typeof(len) __len = (len); \ + __unconst_integer_typeof(__array[0]) __element = __array[--__len]; \ + while (__len--) \ + __element = op(__element, __array[__len]); \ + __element; }) + +/** + * min_array - return minimum of values present in an array + * @array: array + * @len: array length + * + * Note that @len must not be zero (empty array). + */ +#define min_array(array, len) __minmax_array(min, array, len) + +/** + * max_array - return maximum of values present in an array + * @array: array + * @len: array length + * + * Note that @len must not be zero (empty array). + */ +#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 Patches currently in stable-queue which might be from farbere@amazon.com are queue-5.15/minmax-fix-indentation-of-__cmp_once-and-__clamp_once.patch queue-5.15/minmax-add-in_range-macro.patch queue-5.15/minmax-deduplicate-__unconst_integer_typeof.patch queue-5.15/minmax-avoid-overly-complicated-constant-expressions-in-vm-code.patch queue-5.15/minmax-introduce-min-max-_array.patch