This is a note to let you know that I've just added the patch titled
minmax: Introduce {min,max}_array() 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-introduce-min-max-_array.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 <sta...@vger.kernel.org> know about it. >From prvs=3555e8f33=farb...@amazon.com Wed Sep 24 22:25:22 2025 From: Eliav Farber <farb...@amazon.com> Date: Wed, 24 Sep 2025 20:23:03 +0000 Subject: minmax: Introduce {min,max}_array() To: <li...@armlinux.org.uk>, <rich...@nod.at>, <anton.iva...@cambridgegreys.com>, <johan...@sipsolutions.net>, <dave.han...@linux.intel.com>, <l...@kernel.org>, <pet...@infradead.org>, <t...@linutronix.de>, <mi...@redhat.com>, <b...@alien8.de>, <x...@kernel.org>, <h...@zytor.com>, <tony.l...@intel.com>, <qiuxu.z...@intel.com>, <mche...@kernel.org>, <james.mo...@arm.com>, <r...@kernel.org>, <harry.wentl...@amd.com>, <sunpeng...@amd.com>, <rodrigo.sique...@amd.com>, <alexander.deuc...@amd.com>, <christian.koe...@amd.com>, <xinhui....@amd.com>, <airl...@gmail.com>, <dan...@ffwll.ch>, <evan.q...@amd.com>, <james.qian.w...@arm.com>, <liviu.du...@arm.com>, <mihail.atanas...@arm.com>, <brian.star...@arm.com>, <maarten.lankho...@linux.intel.com>, <mrip...@kernel.org>, <tzimmerm...@suse.de>, <robdcl...@gmail.com>, <quic_abhin...@quicinc.com>, <dmitry.barysh...@linaro.org>, <s...@poorly.run>, <jdelv...@suse.com>, <li...@roeck-us.net>, <linus.wall...@linaro.org>, <dmitry.torok...@gmail.com>, <maz@k ernel.org>, <w...@csie.org>, <jernej.skra...@gmail.com>, <sam...@sholland.org>, <a...@redhat.com>, <snit...@kernel.org>, <dm-de...@redhat.com>, <ra...@chelsio.com>, <da...@davemloft.net>, <eduma...@google.com>, <k...@kernel.org>, <pab...@redhat.com>, <peppe.cavall...@st.com>, <alexandre.tor...@foss.st.com>, <joab...@synopsys.com>, <mcoquelin.st...@gmail.com>, <krzysztof.kozlow...@linaro.org>, <malat...@linux.it>, <hdego...@redhat.com>, <markgr...@kernel.org>, <artur.paszkiew...@intel.com>, <j...@linux.ibm.com>, <martin.peter...@oracle.com>, <sakari.ai...@linux.intel.com>, <gre...@linuxfoundation.org>, <fei1...@intel.com>, <c...@fb.com>, <jo...@toxicpanda.com>, <dste...@suse.com>, <j...@suse.com>, <ty...@mit.edu>, <adilger.ker...@dilger.ca>, <dushis...@mail.ru>, <luc.vanoostenr...@gmail.com>, <rost...@goodmis.org>, <mhira...@kernel.org>, <pmla...@suse.com>, <senozhat...@chromium.org>, <andriy.shevche...@linux.intel.com>, <li...@rasmusvillemoes.dk>, <minc...@kernel.org>, <ngupta@vflare. org>, <a...@linux-foundation.org>, <yoshf...@linux-ipv6.org>, <dsah...@kernel.org>, <pa...@netfilter.org>, <kad...@netfilter.org>, <f...@strlen.de>, <jma...@redhat.com>, <ying....@windriver.com>, <and...@kernel.org>, <myko...@fb.com>, <a...@kernel.org>, <dan...@iogearbox.net>, <martin....@linux.dev>, <s...@kernel.org>, <y...@fb.com>, <john.fastab...@gmail.com>, <kpsi...@kernel.org>, <s...@google.com>, <hao...@google.com>, <jo...@kernel.org>, <sh...@kernel.org>, <keesc...@chromium.org>, <w...@chromium.org>, <wi...@infradead.org>, <farb...@amazon.com>, <sas...@kernel.org>, <ruanjin...@huawei.com>, <quic_akhi...@quicinc.com>, <david.lai...@aculab.com>, <herve.cod...@bootlin.com>, <linux-arm-ker...@lists.infradead.org>, <linux-ker...@vger.kernel.org>, <linux-um@lists.infradead.org>, <linux-e...@vger.kernel.org>, <amd-...@lists.freedesktop.org>, <dri-de...@lists.freedesktop.org>, <linux-arm-...@vger.kernel.org>, <freedr...@lists.freedesktop.org>, <linux-hw...@vger.kernel.org>, <linux-input@vge r.kernel.org>, <linux-su...@lists.linux.dev>, <linux-me...@vger.kernel.org>, <net...@vger.kernel.org>, <linux-st...@st-md-mailman.stormreply.com>, <platform-driver-...@vger.kernel.org>, <linux-s...@vger.kernel.org>, <linux-stag...@lists.linux.dev>, <linux-bt...@vger.kernel.org>, <linux-e...@vger.kernel.org>, <linux-spa...@vger.kernel.org>, <linux...@kvack.org>, <netfilter-de...@vger.kernel.org>, <coret...@netfilter.org>, <tipc-discuss...@lists.sourceforge.net>, <b...@vger.kernel.org>, <linux-kselft...@vger.kernel.org>, <sta...@vger.kernel.org> Cc: Andy Shevchenko <andy.shevche...@gmail.com>, Christophe Leroy <christophe.le...@csgroup.eu> Message-ID: <20250924202320.32333-3-farb...@amazon.com> From: Herve Codina <herve.cod...@bootlin.com> [ 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 <herve.cod...@bootlin.com> Reviewed-by: Andy Shevchenko <andy.shevche...@gmail.com> Reviewed-by: Christophe Leroy <christophe.le...@csgroup.eu> Link: https://lore.kernel.org/r/20230623085830.749991-8-herve.cod...@bootlin.com Signed-off-by: Mark Brown <broo...@kernel.org> Signed-off-by: Eliav Farber <farb...@amazon.com> Signed-off-by: Greg Kroah-Hartman <gre...@linuxfoundation.org> --- 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 farb...@amazon.com are queue-6.1/minmax-fix-indentation-of-__cmp_once-and-__clamp_once.patch queue-6.1/minmax-add-in_range-macro.patch queue-6.1/minmax-deduplicate-__unconst_integer_typeof.patch queue-6.1/minmax-introduce-min-max-_array.patch