From nobody Sun Feb 8 11:16:31 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 E7B7D137C5E for ; Thu, 15 Feb 2024 16:08:24 +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=1708013307; cv=none; b=qLsCjIbxNmcCnvovtw+ZR5a//Rbydr3q6nlksCqYyfwc138E0aYn02Rc+SCn2OQ9kii7MoTOm98SIbwEW6IvA6tAlRkVnPurL5PCTeLwQlxJtfLnuWmQdKC6kFQDurXLF57gku15ceKVtD1s5+IXHYvKTyqnx80+bchePNs7h9E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708013307; c=relaxed/simple; bh=ur7gFVD70mLlwTc0wM06u3j1P5Yr4YCTQ5oi2mHpDZY=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=UJodG2l5nsOpzYMMzx9a89cWNiMdEIrgtJ9/nMcjUSnDcfGl0XfOS6OsQHEgIc1SvjtzMA86WpMQsghzfCtS8fK4YS13VkPkV0gXRLUeKu3cAMfuuLPiSmTV9wnTSrKGN7vnygAz7EX59V1e8WYeiv6b/vVCSnggIwW5fMcYtxs= 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=K4d7CeIH; 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="K4d7CeIH" Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 7FA32240103 for ; Thu, 15 Feb 2024 17:08:17 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1708013297; bh=ur7gFVD70mLlwTc0wM06u3j1P5Yr4YCTQ5oi2mHpDZY=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version: Content-Transfer-Encoding:From; b=K4d7CeIHp5bVoLYhZFXM8a5mzWQhV+21BofAx3N1nnU+IBpNUsIgfLY2ImAdzA86+ oXaDhkretH0gZd4Coo18EdKs+/e4ypEmDD6HOr4xpJ0iJELbfGQX9CHNI/K43XdpO2 dTy/VS9ELeZn7WmM7u/f9tGMxf6grOAH+fhbSDfoHjvF5UtfRakY1KGw3IHX3B4mS/ TFzt+BGGPw5qjgf3rcwhXAxDWmgnX2y+uD43lrRfHF/LuhPIIOLQWDGUeX3YZGlBC6 H0xbdf+biBJKVlpafZbf7fBlDNhGcHmSF+qVIT1Rf/bqDtQkcMw3DoAQzUHAu7lKTV UW6owzfI/NwPg== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4TbKjT3ttfz9rxD; Thu, 15 Feb 2024 17:08:13 +0100 (CET) From: Yueh-Shun Li To: Andrew Morton , Mark Brown Cc: Yueh-Shun Li , Andy Shevchenko , Herve Codina , Christophe Leroy , linux-kernel@vger.kernel.org Subject: [PATCH] minmax: substitute local variables using __UNIQUE_ID() Date: Thu, 15 Feb 2024 16:07:21 +0000 Message-ID: <20240215160726.2254451-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..70b740b76f73 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