From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (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 C86BE302756 for ; Sat, 7 Feb 2026 10:50:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770461453; cv=none; b=ejB1rpj8Hv1lhyUqf7/JxkFOI5VUnBfSIPoDYpTipyvnspPKi/cVrT01IbocdscMPadzp91pFxBifQ93CPfref2CBHyO0pkdKAVrW495quHClBoB7yr/tjMt+y8o2+5rpuphHr7iaEKHhqfxyeM6/C/R7eF8Xx67ugFVbgs3058= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770461453; c=relaxed/simple; bh=nPL1yGLXgRXjWEkANRmLrSpEUF6YpDDCIhRmBVxcGRI=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=SKF9X9cINqxXuz5ZBXrVtHJ21KaJgKG85pa8vFPITlomxbW8Ixrlydptk+x0PBkrosF0MAlnbLbzGI1ujsRF3euqa2V7Fdj67yD9NaIrvltdrpmQj5lt2Byq7pY+pUEt1I+bbtI0q9aPvN17fCLVMfgNkGG84fWEomqBh+TB3Jc= 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=hVvEFcIU; arc=none smtp.client-ip=209.85.128.49 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="hVvEFcIU" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-482f2599980so35265385e9.0 for ; Sat, 07 Feb 2026 02:50:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770461451; x=1771066251; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=cehASASwwGUn2N+bfvWu/GkEiLcfp8vxrcSEN/K/pwA=; b=hVvEFcIUG+K2XFgtapMafFPXraUD9ItpZCihQ9Uz0D8LZ1/P4iFBcHJOiuvQk3XIew 7s07YOl4biwSdnF46t0cUlNCyMjIDQtFufLWN3TRYrerU/7PEDoFCMJbl2ByA1gd5do6 Z1MJU1KetI4ARfmqkISf5RkhtIHDbkvCITqw2qupPZjgtgAfwW4RNI3e6JPPG8PorPtx jTuTYh2YU8TdPdoON5fuKhVCl56WsasBDjPbE1M29iwJXJQi0b9E2gPHETFOKZkLDxtE ZWQmkIs/AB4m8TwbDN+KAg53r/zvloMT5G/v+6jPXbNjE4CLHy++p6p2CHuPJEjHfB/Q d8HA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770461451; x=1771066251; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=cehASASwwGUn2N+bfvWu/GkEiLcfp8vxrcSEN/K/pwA=; b=A3pfpJHuv15UV0Ks8bBPZswZMZblZTGFw9RgXv0lbGgr8krkpB1wdfJ6qEevairmgK Wzj3GHfwnOtvNooO3dlKqqXrZHYI8+d4pr9QSNmgv23zjboslFaH/7ZEHlHHjNTuj+dW QCxuA77f2uhhr9VANcYG58IKpKJjI93kEzSREDKx6ggw33JK29pHm5lqwsxbjqX4a1Cc b1HsZ70f7QL26K1zPjYHJPaiUHmRQH+GjyZgVhs2EhEE7tmYt4w2QfXIKvhC+AAYRuUN M6s3ouDzckNliiH9Y8mQeXadN20mkIoJOOP2HLbnRPIiP/E3KHOzrYM8+/Cev578k7C6 RrRg== X-Forwarded-Encrypted: i=1; AJvYcCVyQ6b4VKy4spqAvdMm6zoQf0exgmPb3baDX3boPwMAbxJrfPbG/muUDAARz4LEOTKKUpE+xVfZnz84NhM=@vger.kernel.org X-Gm-Message-State: AOJu0YxwGW9rxeGiRvbF1ZM7E8uLpQu/Y5Dtt7fB/U6wx6uaT+6Pr+Vz fd7hYC/lybbIdXluAcvUo48nB9Kk09lStcz7B3FT9/GosHV+JMKxWz3K X-Gm-Gg: AZuq6aIhQq4Vwn+eNS1cZCTPh9aPAmtl3E05+xzcUMgsNKhBLaCMk5UCdDcKKFaPGhX niTpqJvJWEKuQ1CNOShW0JBOLcqDgsHpT5DOgJMnpe8ckI4jBTkIWUlT4VDznSv8mkFeAwaA4ng eAuTT1JBPaV6T7+GX3PzoKIw1LwuFfWA3YtLias2GFFbqbbnD3nIcLvmMRMWXprOXYu40Fj670Z fSHpZppd1X9FtP4O9CvHnPam/7UG3n0GHOZunIbOedpF5ZicQeTpXHSxWT58RaRfxBJsQVrCBQ6 1IVNbyOuhPfXvF7O4F4AiGd5naDS3p6t960rW/IeBJSPigpZxC+oc5tWJp2u4i5czhyLCTywtoV 043JwsP97Hz4GnRVZ4k+1zhn3Qq1Xh451d4kKTs3YHOvYXqcrUoLVg1/H3b+Khi9ErU6s8SYahb 8uvac8m3a43ANH0O/zVcxT9ouRTglmLVLA31S9WVFdHVrTBFv/Wk3e X-Received: by 2002:a05:600c:3f08:b0:477:a246:8398 with SMTP id 5b1f17b1804b1-483201dcfc4mr81538235e9.2.1770461451206; Sat, 07 Feb 2026 02:50:51 -0800 (PST) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4832097e05bsm38839685e9.10.2026.02.07.02.50.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Feb 2026 02:50:50 -0800 (PST) Date: Sat, 7 Feb 2026 10:50:49 +0000 From: David Laight To: Peter Anvin , Andy Shevchenko , Arnd Bergmann , Christoph Hellwig , "Jason A . Donenfeld" , Herve Codina , Linus Torvalds , Andrew Morton , linux-kernel@vger.kernel.org Cc: Marco Elver , Will Deacon , Peter Zijlstra Subject: Re: [PATCH next] minmax.h: Use auto for variables in __minmax_array() Message-ID: <20260207105049.09c67177@pumpkin> In-Reply-To: <20260206222554.676171-1-david.laight.linux@gmail.com> References: <20260206222554.676171-1-david.laight.linux@gmail.com> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Fri, 6 Feb 2026 22:25:54 +0000 david.laight.linux@gmail.com wrote: Cc the people discussing unqual_scalar_typeof() for arm64 LTO READ_ONCE(). > From: David Laight > > While 'auto __element = _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 = 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 __unqual_scalar_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); \ > - __unqual_scalar_typeof(__array[0]) __element = __array[--__len];\ > - while (__len--) \ > - __element = op(__element, __array[__len]); \ > +#define __minmax_array(op, array, len) ({ \ > + auto __array = &(array)[0]; \ > + auto __len = len; \ > + auto __element = __array[--__len] + 0; \ > + while (__len--) \ > + __element = op(__element, __array[__len]); \ > __element; }) > > /**