From patchwork Thu Feb 15 18:58:15 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: 201709 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:c619:b0:108:e6aa:91d0 with SMTP id hn25csp53490dyb; Thu, 15 Feb 2024 10:59:21 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXQrJ+E4pW0QZ1bb8N3eXbU/KESG0N6RB7Pw6yZSrWETm7rOaoNMGKW+C9Qp9A2uNoqvQ2iX6itLf8Zngfyu79BFGur1Q== X-Google-Smtp-Source: AGHT+IE3Iz0+cm6XY6rTIsoy+F98zAdvZO1TW1ir8JXtTewG9ahIsdvHtWbHrmmptDDKRaC38HCG X-Received: by 2002:a0d:d88b:0:b0:607:9d64:d68e with SMTP id a133-20020a0dd88b000000b006079d64d68emr2763483ywe.26.1708023561050; Thu, 15 Feb 2024 10:59:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708023561; cv=pass; d=google.com; s=arc-20160816; b=AGWcrIBiz+cnSb88eXJStTNRMqFTo2SZchJgRdVsNSdAho9Poq1IQ2zul8OCQ7SOB8 bJPyutZCjOe273nbfXrU8647Kqa++yAjC/hF/hxuE4XJVc6crmQzApdt47IOKGxQ0BzG NL58Rhil8F/zh2kpg42AaIy4ruososajxOWWfPiRoinTQgfO+0FtverclGZY/U9roD/a WTE0aQH9LifSBwpY8A0t3QnbmQ0CUrZ2N+/lmiL3QxvE2UbFXeWB9BEQjGqGl+SjGDKi mqrqjn/DMfj5z+BAxJzRg1f+xIjsTLJirhimKR2prOjdUMadNINuHWSea6IAq1Rilt2g 3Xcw== 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67543-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=posteo.net Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id h10-20020a05622a170a00b0042a8967cdb6si2155184qtk.533.2024.02.15.10.59.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 10:59:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-67543-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67543-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id AA8921C23A97 for ; Thu, 15 Feb 2024 18:59:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0418113474D; Thu, 15 Feb 2024 18:59:12 +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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790992513224010441 X-GMAIL-MSGID: 1790992513224010441 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 */