From nobody Sat Feb 7 14:57:19 2026 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5583A23183F for ; Fri, 6 Feb 2026 22:26:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770416762; cv=none; b=Kt5URvDs4t9tpXY0QNZD7x/a3+kvyAWZA1koFxW/6ONGeKG/1NVcl0jXRqlitllPQxa79otTc0wKHZVm7JAdENIp8zE5iHeVktAzZ0QXJao3vCM1QxES1+FfyI5ikvunRcQMfzC5p5PslSBgo8U+q1QmMsQHTujEBovPfCiuyA4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770416762; c=relaxed/simple; bh=DGdVTeuNnoFIkLt5t9BIFhbXeQW1zO37Farnf3mGI4k=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=SIVOgfOz4T8F7UKgYFe+k4cBZnRZ3MvRj2pRJsHdp/a8OLQkra9aMxhMWGcVqaf63EC3SZ6TB+tKUfjJpACK0vk2wd7S+4dFvM64d5bBfKPiO4YlS6kj2TGpwwIe04J6JVspHX0GXK0+JqbFql9CSZy6C+HpUnp9T/gqT6+W6hM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Z13g5NOx; arc=none smtp.client-ip=209.85.128.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Z13g5NOx" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-48039fdc8aeso16972835e9.3 for ; Fri, 06 Feb 2026 14:26:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770416761; x=1771021561; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=joQP2N4NuV9dnkGYpq9NOVluOQp6NXMoJLG8V74bkZE=; b=Z13g5NOxsGoSWuJUaeQregFSdbTwMKtxVQmYhUvwo3FbPA5dONrOrBmSgqw2LUxfkm A3MmFmN3VYJUS5x2aclzAA0liYSn5Wj5Eq9QEFCpqoujs/luhd1/nS3AtFw4otczPk3p TF6AKfAdcAiDc5BtG0PaGKyu1FtujBvlfow2mZrIAUkIXQSNLz9Pa4Uiv6XELyb7R9l2 obYPftcVb7EZ8h2EndeLfBxDez7Oaw4mRFG6sOn8d9qVPWSaC6etUZz6t8o40FC9v9PU HTK8LyhrqMapiUVk4F2rmcsExV+OlP8bA/CLs4Z/kZAhIz44Dr5RcMEi5PpbEjN9zlie k7fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770416761; x=1771021561; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=joQP2N4NuV9dnkGYpq9NOVluOQp6NXMoJLG8V74bkZE=; b=QPf0O6jxj5hAe9oHaSkJ8rwES/14nzPQXf6gNuO3Z8NMKiZTJsiEqA5Om05s902OVo t0z9vANwuDoZZeHZVaaDXBTxbU25VTYdPlQq2iE+H4yCfiNEjykacKELpQZGGA5mhqSd Zy68rPMIccR/ykQNfcSR/ypueO3+KgNflX9FNOQC4aLP923x5IbPMoAHrMjAYXi7r28n T8IgF/eJYx5Q23eNDyUnFFDHuu56OLMbThVpyNZGhbpGVI/bJwk+0HONJmKMyc3yQSxk 1JoScv/22mWsPi25XPlcplxvBJqsE2olpE9n5PEN4D9aOWECEEmVcuoyyrtkgLg2qZZl 19nw== X-Forwarded-Encrypted: i=1; AJvYcCX0efI5WpM2IGaENT+DDDLnSAY+AZitT5oWw5bzsIOPIfsNTFI/is7aI8k+aCldX3QnxMDVWWAxrofM/pE=@vger.kernel.org X-Gm-Message-State: AOJu0YwPlz9MjwkC0v6kUGvTMFtfEj5UWSPu9op+Nom1sRCk/GRVpBN3 vSOZ2lA2Xv2eTWrECgYC/FQ/pW8uJ+DWm3CwbkUhkHyXgnmf1e97tlaL X-Gm-Gg: AZuq6aKejA+Gg3fPv7uSMSXlaMMQLB6w6hYYM6Dq/0J2XMX4R2dIHdhog22inlASXXX sfZrz5kCT8MqywzDyCYVy4eKWLLM4Ks/Cbx1WGQcXgeqm/7kXY+7kPcgMFNpEhCmrTmKqroAzk8 TMfy+P1+9oSpEci1kQndZQRtVMylsHednm7uEnm4kK0LJpKiwLyQSpfszyoNxYSfnna6PnSvnZQ 5CMTBdpvhR6DSnhWb73EUOC1LKbGBxfJtbwzwTp+lKaLq8jYDOMXVRnlML8aN/85PbRUlqZcCSq kztxHEdxpjAm3306CqDMvZ8LlpagQrDeyATsgu+vGL1WbeBjgfadzqHUQBoP9X2mzqYLRzBAB9n VA6RpBJ2i3kDsqmV255V2ORtL5GBiV+evPzdMr8jicCfEOhPhTgQtwXwkx01AyqKKrNzlUOBRpp 54fQASp+OaTN7nDRCcx+JP0KR8fYESeSUG7mTkQPff5SRd4JzSJjnCzDYW5wYBj1zF41C0ZB5m X-Received: by 2002:a05:600c:8489:b0:477:73e9:dc17 with SMTP id 5b1f17b1804b1-48320229cdamr64443715e9.35.1770416760450; Fri, 06 Feb 2026 14:26:00 -0800 (PST) Received: from snowdrop.snailnet.com (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-436296b25d5sm9379410f8f.2.2026.02.06.14.26.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Feb 2026 14:26:00 -0800 (PST) From: david.laight.linux@gmail.com To: Peter Anvin , Andy Shevchenko , Arnd Bergmann , Christoph Hellwig , "Jason A . Donenfeld" , Herve Codina , Linus Torvalds , Andrew Morton , linux-kernel@vger.kernel.org Cc: David Laight Subject: [PATCH next] minmax.h: Use auto for variables in __minmax_array() Date: Fri, 6 Feb 2026 22:25:54 +0000 Message-Id: <20260206222554.676171-1-david.laight.linux@gmail.com> X-Mailer: git-send-email 2.39.5 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: David Laight While 'auto __element =3D _array[--__len]' should remove 'const', gcc prior to version 11 are buggy and retain it. However forcing an integer promotion by adding zero does work. Promoting signed/unsigned char and short to int doesn't matter here, that happens as soon as the value is used. Type type of the result (for char/short arrays) changes, but the value will always be promoted to int before it is used (for any purpose) so it isn't even worth casting the type back - all that is likely to do is make the compiler explicitly mask it to 8/16 bits before it is immediately promoted back to int. Signed-off-by: David Laight --- include/linux/minmax.h | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/include/linux/minmax.h b/include/linux/minmax.h index a0158db54a04..7d437f73a6d6 100644 --- a/include/linux/minmax.h +++ b/include/linux/minmax.h @@ -239,20 +239,13 @@ * ... * min =3D min_array(buff, nb_items); * --- 8< --- - * - * The first typeof(&(array)[0]) is needed in order to support arrays of b= oth - * 'int *buff' and 'int buff[N]' types. - * - * The array can be an array of const items. - * typeof() keeps the const qualifier. Use __unqual_scalar_typeof() in ord= er - * to discard the const qualifier for the __element variable. */ -#define __minmax_array(op, array, len) ({ \ - typeof(&(array)[0]) __array =3D (array); \ - typeof(len) __len =3D (len); \ - __unqual_scalar_typeof(__array[0]) __element =3D __array[--__len];\ - while (__len--) \ - __element =3D op(__element, __array[__len]); \ +#define __minmax_array(op, array, len) ({ \ + auto __array =3D &(array)[0]; \ + auto __len =3D len; \ + auto __element =3D __array[--__len] + 0; \ + while (__len--) \ + __element =3D op(__element, __array[__len]); \ __element; }) =20 /** --=20 2.39.5