Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp653017rdb; Thu, 15 Feb 2024 10:59:15 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXeqKhTBCdldUSofPjgV/LNRj44Cqfp0gNJpe0koT9nurAHkuOMlwhEfY44y2d39MRdr4OYicW81h60s9Jgua0XSkaa3mpN5/5jSrWtWQ== X-Google-Smtp-Source: AGHT+IEhfM7iMMJAYq/NC+jFVPtqpfVklCLuB8MNip7Ta8CxGEinUnVwYNZOYjhtFmfgiPovHXZ5 X-Received: by 2002:a17:906:d0c9:b0:a2d:a6a7:b3bc with SMTP id bq9-20020a170906d0c900b00a2da6a7b3bcmr1739682ejb.4.1708023555031; Thu, 15 Feb 2024 10:59:15 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708023555; cv=pass; d=google.com; s=arc-20160816; b=UFOYdOtS8D+6UsKt+CbczKOx1RitKQCU8Vl6S2aJkdSPYvHqD1DQVbe7jc/cIBrGlV 9QyotudvLKg7V03vDhGVednlUI9wVlAjyK/EstRNilSF/Teyxrsk+3co9JP1PicFkGTm NBlakAP1MyCJwm4WL/0E6MyqKqQ0t7bZGjMM5WxQryu8uAQplMxsMqmKyuSKRqRBZhne fGf4blBIZzPn6+ij9ZW53Y0pqgz82z0w5pcjnMhcQJAvp0Gb7RUxtGtbETVJmYKxtbBJ FqkvMi9Gsqz9E+joSw+Lw4AaiKWrPza3/fZ6tVxb9B64DcCAewSEeCB6Ms0s9SI/JDNa 1RZw== 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=q1VDcPV2WtUl0gI/MGbaH+Oij7iiJG6d+hhaWb++wk0=; fh=jGh4y155E91Rcr9DUlKA4yqdHI+d+Kd4GXa2lVdWDrU=; b=twfqlb+U9jU/AGmHDfpnbYI7lBUNDzVZqYUiKNmeZkIWYloOptmkVtfz7xLt9idwR2 9Jjw831WfOWBsCbzWRYB+NvWNgGwvK2yBc62wsGYZeHL+YzLCJLwCcMm6oAlcF5wa7bF uWJosIdcazG9yJb8BHuW8BekiGUf5PFLqZM996RUeJne3HqUTHcOJJK8OF0WLgpN7rHH WOwDBWxWZHIlrIxRbP61CSJFSSIdqrFAiXaP3QBM7/vzzPlurr2wX6vxVbFfmDmXHWUS 3T57nRM41qRcz4f0iMUdLYzF8umz8D85scW8HnlTMHu3yi0Ktr5nAQO5xJm4/cxNuQtI g5bQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@posteo.net header.s=2017 header.b=UMhNdIoJ; 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-67543-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67543-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=posteo.net Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id va29-20020a17090711dd00b00a3d084eaa4asi847354ejb.493.2024.02.15.10.59.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 10:59:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-67543-linux.lists.archive=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=UMhNdIoJ; 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-67543-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67543-linux.lists.archive=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 C0DD11F21693 for ; Thu, 15 Feb 2024 18:59:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0616C1386DF; Thu, 15 Feb 2024 18:59:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=posteo.net header.i=@posteo.net header.b="UMhNdIoJ" 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 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: 8bit 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 = (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 */ -- 2.42.0