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 8A1EDCCD195 for ; Fri, 17 Oct 2025 08:05:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DA5D8900003; Fri, 17 Oct 2025 04:05:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D56C58E0016; Fri, 17 Oct 2025 04:05:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C43DF900003; Fri, 17 Oct 2025 04:05:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id A6A238E0016 for ; Fri, 17 Oct 2025 04:05:57 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 537A5479CC for ; Fri, 17 Oct 2025 08:05:57 +0000 (UTC) X-FDA: 84006872754.04.B5040F2 Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by imf25.hostedemail.com (Postfix) with ESMTP id 8FE8FA0006 for ; Fri, 17 Oct 2025 08:05:55 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=fail ("body hash did not verify") header.d=linuxfoundation.org header.s=korg header.b=JcEpuLh2; spf=pass (imf25.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=1760688355; 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=Bng1/1BVXUk1NKCno716V5LgVGQ1BNvdNFZ4NcMDgJ0=; b=Kcjlu6ECYwfRJ//xc66vpaEDTE1rr4H2Uaq7TsW9SrR7QTvM4OJG6r1QrQbpECVh9y3p/7 hpUm3O/I02UZKdOOHRF78KjMiw2X0SDAQdlLjI6pYLYFj2I2M8kW4XbFQ+YZQgCeWw8sbC ytUr+7aGDZbqC/8tMx1hI8uOjUjFSYE= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=fail ("body hash did not verify") header.d=linuxfoundation.org header.s=korg header.b=JcEpuLh2; spf=pass (imf25.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=1760688355; a=rsa-sha256; cv=none; b=DZBTVfNHUipXrVaQ7nWsT6ha+ixGU4j91rj9mc48DVwZWJv7NxiSuMurimVOY2qRJFbwie dH+4JHwFYUAWs5MuIt0JiVS2JVWmQ8IRVC2l2lm8Lr9dfS20q4YSjZDNEEMNYY0f0DGC/y Wlfv6CFY4K+vxilBF6guUM4pLB92ZEI= 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-stagin g@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-Stat-Signature: g843mxqw8nt9yx4739czdkfwsdz7rnec X-Rspam-User: X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 8FE8FA0006 X-HE-Tag: 1760688355-20165 X-HE-Meta: U2FsdGVkX1+sld9mRJ/6BcyMWsrXK6oBF3QLcLKOZi/P8OxhsvS9g8CTZKiXgMMOFdVniRdggoLDfjsqO616HbbUZ+uFIv5ozKl4qeagRIuy/xlM8JTo1YSzyUV2wJfF+5BgdP439c6C+kmLLbUucWKy6330J2YYtYxUhQrKMTEl2Melg5WK5Iwyp6LhTB47FNNFB/kFZHWFxM2cBeziH5oWxtRidIQxFNopQK/Xvy/H1p6P6g719TKYBv7f7uVE5q/nEHZOf1l7Ya7NDwCEFUg80yShqV9nXd9vVa5d06YShvPJPAgcuEHm81P1NDpVmyKViAu0kZSrcdnNI7MzjFt+3oqapzBx40fLMpeEu9JMgjWr4ojewDBWDqRrF89UqLIo6TVf+jsXys+GsVz8Ryzs2l+BgakwntahbxxlYZ6aUeGZbGcu1wQa6bFZT4fxNJC6n2Ifz0IMl2B7N1o6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H8Vn2H9YvpTLrOP9v8ND3fy0qM5p0Qp4dygiV2qar1c0y5g8Q3xYqDJKhdSL15Acm4cXX8uFsE49QncDSKr0WqA6ImEEjRL55bdud2LU/Eso0iyrZrmmW1+ivgoCUvUBjgDWetg+BQKmk9S60abFY8yqWC0/M7k+0HPykzu/2FCPw4HKZN0UCCHdvf08sf1BPBZbsUH2ozGsN6+KgncIXjOxIoLbFZEJSgfN/qnX1AV70qQ7c= 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: 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