From nobody Sun Feb 8 16:12:13 2026 Received: from mout02.posteo.de (mout02.posteo.de [185.67.36.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 34AFA1386B3 for ; Thu, 15 Feb 2024 18:59:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.67.36.66 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708023548; cv=none; b=sYB79rEz3qi6ZYoTy/QNnUPx83MiGZefOL2K3e3onxI33Lb8OmUF16KnSDuQKGKZIomxy8xTNawqmwLj0Yi0n413eyvrxzbp6q1WoElhrFzxWAZtmdyDb1x0Z13VAk5HV53MwYPkicqMqU+TKGa3bald9V8KbQ5wRBlw17IW8qg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708023548; c=relaxed/simple; bh=kmiOofdVKBZVE7X7tgel+gK+VIQLaBji30JFdTlsCpE=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=QM44DWSah3W+l5XbNrxK535ZkzrDyOae9nGpbjO0NG37ei3OMEDgQOTN3uUzOBq4UdoHZB4qYwjOAz6gbx8kUfI1/p2jfsWRYY0awGF22BMIBIf2Su3avTCKQan47m4NBqQ3CXGTsE2HdH4U4LGqPfNcwfnCNyxj1CAhecnL6wc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=posteo.net; spf=pass smtp.mailfrom=posteo.net; dkim=pass (2048-bit key) header.d=posteo.net header.i=@posteo.net header.b=UMhNdIoJ; arc=none smtp.client-ip=185.67.36.66 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=posteo.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=posteo.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=posteo.net header.i=@posteo.net header.b="UMhNdIoJ" Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id A8752240103 for ; Thu, 15 Feb 2024 19:59:03 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1708023543; bh=kmiOofdVKBZVE7X7tgel+gK+VIQLaBji30JFdTlsCpE=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version: Content-Transfer-Encoding:From; b=UMhNdIoJX+oPIy9wjgs8iWrbai1s3wc/ZJRKPbMdeadqavkK9jVNbBpGdRHve5KR8 v+nmVTghcjYPWr7f2gz6b/cXhOvnU1/+QhIiCvfHN56JB7/JyGhR0MeTeGWDSCUAAT rK6EoYAoMwe3MLH8szK1PYHDWZ+Mt58WYjzhdrlSjQxk699XsJ/LxQrZ9JXRL2c9pN o6bbqXNsfzxDJamuyfla2solZu9SU0m17YWnfhrzVwjyqCKc6bzjESobFQ4xHLO5wQ D0C3VclvwlyA5IhL1XdnrXq/YUz65LA4dhAu+/4C61HoIBPrKbd1uoCfGVoBydwLRi h2qd9BfnOS8xA== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4TbPVX19dJz6tx2; Thu, 15 Feb 2024 19:58:59 +0100 (CET) From: Yueh-Shun Li To: Andrew Morton , Mark Brown , Andy Shevchenko Cc: Yueh-Shun Li , Herve Codina , Christophe Leroy , linux-kernel@vger.kernel.org Subject: [PATCH v2] minmax: substitute local variables using __UNIQUE_ID() Date: Thu, 15 Feb 2024 18:58:15 +0000 Message-ID: <20240215185820.2285834-1-shamrocklee@posteo.net> 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" Substitute identifier names of local variables used in macro definitions inside minmax.h with those generated by __UNIQUE_ID(prefix) to eliminate passible naming collisions. Identifier names like __x, __y and __tmp are everywhere inside the kernel source. This patch ensures that macros provided by minmax.h will work even when identifiers of these names appear in the expanded input arguments. Signed-off-by: Yueh-Shun Li --- include/linux/minmax.h | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/include/linux/minmax.h b/include/linux/minmax.h index 2ec559284a9f..df7e45106c3a 100644 --- a/include/linux/minmax.h +++ b/include/linux/minmax.h @@ -129,10 +129,14 @@ * @x: value1 * @y: value2 */ -#define min_not_zero(x, y) ({ \ - typeof(x) __x =3D (x); \ - typeof(y) __y =3D (y); \ - __x =3D=3D 0 ? __y : ((__y =3D=3D 0) ? __x : min(__x, __y)); }) +#define min_not_zero(x, y) \ + __min_not_zero_impl(x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y)) +#define __min_not_zero_impl(x, y, __x, __y) \ + ({ \ + typeof(x) __x =3D (x); \ + typeof(y) __y =3D (y); \ + __x =3D=3D 0 ? __y : ((__y =3D=3D 0) ? __x : min(__x, __y)); \ + }) =20 /** * clamp - return a value clamped to a given range with strict typechecking @@ -185,13 +189,19 @@ * 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]); \ - __element; }) +#define __minmax_array(op, array, len) \ + __minmax_array_impl(op, array, len, __UNIQUE_ID(__array), \ + __UNIQUE_ID(__len), __UNIQUE_ID(__element)) +#define __minmax_array_impl(op, array, len, __array, __len, __element) \ + ({ \ + 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]); \ + __element; \ + }) =20 /** * min_array - return minimum of values present in an array @@ -267,7 +277,12 @@ static inline bool in_range32(u32 val, u32 start, u32 = len) * @a: first value * @b: second value */ -#define swap(a, b) \ - do { typeof(a) __tmp =3D (a); (a) =3D (b); (b) =3D __tmp; } while (0) +#define swap(a, b) __swap_impl(a, b, __UNIQUE_ID(__tmp)) +#define __swap_impl(a, b, __tmp) \ + do { \ + typeof(a) __tmp =3D (a); \ + (a) =3D (b); \ + (b) =3D __tmp; \ + } while (0) =20 #endif /* _LINUX_MINMAX_H */ --=20 2.42.0