From patchwork Thu Feb 15 16:07:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yueh-Shun Li X-Patchwork-Id: 201630 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:b825:b0:106:860b:bbdd with SMTP id da37csp507116dyb; Thu, 15 Feb 2024 08:14:33 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXzrHIYhrt1FayKwS8UmahDgQEHgoviJtZC10s+a5ajM+8GPaFmdIbNcfyE+3OG8wvQ0aWw0NB/iGKL4yID/eU1M/QQSw== X-Google-Smtp-Source: AGHT+IGTBZJreCHgSzXfXEM1EpfrjiWDHoR7+fWp36MVPAdk/9LdPP/6wrFfJ9qNqPYTlJtLceGg X-Received: by 2002:a17:907:76ac:b0:a3c:a4ba:6b02 with SMTP id jw12-20020a17090776ac00b00a3ca4ba6b02mr1720023ejc.1.1708013673489; Thu, 15 Feb 2024 08:14:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708013673; cv=pass; d=google.com; s=arc-20160816; b=qlVFdQafr5qfSOX3TaGZgE7nKIvBhNeYclxvdij4ZbjZyLLflHNsCIXT1g9JLGnrVR iPUVW0oD4cE8hYt9MXKxsAdtf5G8K+up6Lrr1QugIEq/eEn2BkOOP6gRuNFarenMWDkJ QbSu5MdYsxja9HO8fmMhhW6e46z5nmCiTOiDOjw+yLEkdQTMPOQWy9xSZnSdJJxEFnJK 8lmcudUmfa46jCEAafcXrz1NVSRRHMP+dA8KIlJ5E5LZoA0buqyB6jYdCK1yenVBtNiw ME4QumX17omqht8SDAaOeT/IdlGjdMCXFeaNs2vjxwFkRV4L/winKoDQnWf4Kby3ay9r xv2w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=PxhUtEgDg9QjAIgimUmdxYUEm6oEAlpH7vt/kjRHl6I=; fh=CTJmxXLZ81irHnArKWsuZ6bon0O3U51ogc44XoQOcHk=; b=0QyPzcsOR4I/jRRzlcr9nXbMz7NRjgD5iZVfT2EYWhLgdQP3I2xlaJHK0tDnPhC8N1 0nLcUtzmW0AxDNPHEF7WDh89zTwUYF+GdckBBDBSXxr4TUtNIXQgvXQFAkMJ0zNHYqot T+Ov6EELwV24U0ZnF/05zXTN3oofeGndZW+Brcc67nm0VdjrMjIOwgn19qfL9EsCcBX7 ubq4okA7hnRBeTVqfwQqy7+0KXUBk/U/Ow2G7/Umx0JBwMP8wIJ+vWIgIlPNRhUZaZWO XLleqpLJGfpdLGNydGz92s9yaulZYLO6BdT1nj437VHg1WHPE5p2r9mZmq1lpIdRD0xC G1Fg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@posteo.net header.s=2017 header.b=K4d7CeIH; arc=pass (i=1 spf=pass spfdomain=posteo.net dkim=pass dkdomain=posteo.net dmarc=pass fromdomain=posteo.net); spf=pass (google.com: domain of linux-kernel+bounces-67287-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67287-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=posteo.net Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id o12-20020a17090611cc00b00a3d6bd8c167si765118eja.714.2024.02.15.08.14.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 08:14:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-67287-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@posteo.net header.s=2017 header.b=K4d7CeIH; arc=pass (i=1 spf=pass spfdomain=posteo.net dkim=pass dkdomain=posteo.net dmarc=pass fromdomain=posteo.net); spf=pass (google.com: domain of linux-kernel+bounces-67287-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67287-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=posteo.net Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 1A4901F22FE0 for ; Thu, 15 Feb 2024 16:14:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B3A46138497; Thu, 15 Feb 2024 16:08:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=posteo.net header.i=@posteo.net header.b="K4d7CeIH" 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 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790982145167240841 X-GMAIL-MSGID: 1790982145167240841 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 = (x); \ - typeof(y) __y = (y); \ - __x == 0 ? __y : ((__y == 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 = (x); \ + typeof(y) __y = (y); \ + __x == 0 ? __y : ((__y == 0) ? __x : min(__x, __y)); \ + }) /** * 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 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]); \ - __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 = (array); \ + typeof(len) __len = (len); \ + __unqual_scalar_typeof(__array[0]) \ + __element = __array[--__len]; \ + while (__len--) \ + __element = op(__element, __array[__len]); \ + __element; \ + }) /** * 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 = (a); (a) = (b); (b) = __tmp; } while (0) +#define swap(a, b) __swap_impl(a, b, __UNIQUE_ID(__tmp)) +#define __swap_impl(a, b, __tmp) \ + do { \ + typeof(a) __tmp = (a); \ + (a) = (b); \ + (b) = __tmp; \ + } while (0) #endif /* _LINUX_MINMAX_H */