From patchwork Mon Nov 18 19:15:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Laight X-Patchwork-Id: 13878989 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3196FD591AE for ; Mon, 18 Nov 2024 19:15:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BD8746B0085; Mon, 18 Nov 2024 14:15:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B88296B0088; Mon, 18 Nov 2024 14:15:57 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A50536B008A; Mon, 18 Nov 2024 14:15:57 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 8944C6B0085 for ; Mon, 18 Nov 2024 14:15:57 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 348D740473 for ; Mon, 18 Nov 2024 19:15:57 +0000 (UTC) X-FDA: 82800168864.25.C42DF80 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.86.151]) by imf17.hostedemail.com (Postfix) with ESMTP id D653A4002D for ; Mon, 18 Nov 2024 19:15:16 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=aculab.com; spf=pass (imf17.hostedemail.com: domain of david.laight@aculab.com designates 185.58.86.151 as permitted sender) smtp.mailfrom=david.laight@aculab.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731957206; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JRytXLO7xuf/PIyuFUZIElyqtU4MFdHGWBtvkM4EmaQ=; b=CmjlDkTKtrwtVSklvzmNIdxdY+vmEUW6QKbMzSJ4sKYcwvYfO01bJsiwtm0n/g6bkWLoYr GFw0uxVCmnTny06NB7zHANGfeukbQn9JNoRdyrIbziZDKNmeQT89eO3zGPDAF5BgQL6Xw2 8Nil/gAfE79azkSCiRRUuHvyIXOJph4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731957206; a=rsa-sha256; cv=none; b=enAUSo8r5YBSPVwehIN5GvOAc4avAj4fygvaranxBbrcIpgPnwVYeKTFSQKzArlOFwikIE sv4aT2d+pOn3YarTFZ/9RzmkVEOnLYHyZvJCvFMXSxnSvMELYbI90YCJYKTirOibmaKrbg CsUNf3bQJr768N8qrnD+/+2srI8qAH4= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=aculab.com; spf=pass (imf17.hostedemail.com: domain of david.laight@aculab.com designates 185.58.86.151 as permitted sender) smtp.mailfrom=david.laight@aculab.com Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with both STARTTLS and AUTH (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mta-53-13-iqr8aPEKNwrfrKL2jEg-1; Mon, 18 Nov 2024 19:15:52 +0000 X-MC-Unique: 13-iqr8aPEKNwrfrKL2jEg-1 X-Mimecast-MFC-AGG-ID: 13-iqr8aPEKNwrfrKL2jEg Received: from AcuMS.Aculab.com (10.202.163.6) by AcuMS.aculab.com (10.202.163.6) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Mon, 18 Nov 2024 19:15:51 +0000 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Mon, 18 Nov 2024 19:15:51 +0000 From: David Laight To: Linus Torvalds CC: 'Arnd Bergmann' , "'linux-kernel@vger.kernel.org'" , 'Jens Axboe' , "'Matthew Wilcox'" , 'Christoph Hellwig' , 'Andrew Morton' , 'Andy Shevchenko' , 'Dan Carpenter' , "'Jason A . Donenfeld'" , "'pedro.falcato@gmail.com'" , 'Mateusz Guzik' , "'linux-mm@kvack.org'" , "'Lorenzo Stoakes'" Subject: [PATCH next 7/7] minmax.h: Remove some #defines that are only expanded once Thread-Topic: [PATCH next 7/7] minmax.h: Remove some #defines that are only expanded once Thread-Index: Ads57kK39EnzR0zLSLWjfI7GoDxEdQ== Date: Mon, 18 Nov 2024 19:15:51 +0000 Message-ID: <9386d1ebb8974fbabbed2635160c3975@AcuMS.aculab.com> References: In-Reply-To: Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: cM51TGWZnUWE8lghKGuE9TVUVMsNMV8NfDN7l_e__1g_1731957351 X-Mimecast-Originator: aculab.com Content-Language: en-US X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: D653A4002D X-Stat-Signature: rtk4bcdmq6gq1hbff1rce8atkb81o3fg X-HE-Tag: 1731957316-285146 X-HE-Meta: U2FsdGVkX18s4O4NDnWZGCL1PZaIxVGhzEPK+VN6OB90mxTj8Zu8xnsoiZxjVRuzotcldaMghnRs0jWmlHdlaAkpKPrwZKnbO2ea/ibCR4uv0lEssLbB0leYxZflaDgaOsRSYDw5KJK6L+PlsLv4CfYE+jEefwTBShh4/9pvnQdlajCDsMOxvRlXMqInjQOj+OKGHeLxpP60nv15yQB9Zrrs+eVFtLA2yqQMd0OBnfIxPYTpb15WV2Ht5PcShDHYJckLkXYWIueJg+lfUut3QrNVt3vtXqAAbEWGeGV9l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qwgOqG4olAh8pgSUIQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: The bodies of __signed_type_use() and __unsigned_type_use() are much the same size as their names - so put the bodies in the only line that expands them. Similarly __signed_type() is defined separately for 64bit and then used exactly once just below. Change the test for __signed_type from CONFIG_64BIT to one based on gcc defined macros so that the code is valid if it gets used outside of a kernel build. Signed-off-by: David Laight --- include/linux/minmax.h | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/include/linux/minmax.h b/include/linux/minmax.h index 2bbdd5b5e07e..eaaf5c008e4d 100644 --- a/include/linux/minmax.h +++ b/include/linux/minmax.h @@ -46,10 +46,8 @@ * comparison, and these expressions only need to be careful to not cause * warnings for pointer use. */ -#define __signed_type_use(ux) (2 + __is_nonneg(ux)) -#define __unsigned_type_use(ux) (1 + 2 * (sizeof(ux) < 4)) #define __sign_use(ux) (is_signed_type(typeof(ux)) ? \ - __signed_type_use(ux) : __unsigned_type_use(ux)) + (2 + __is_nonneg(ux)) : (1 + 2 * (sizeof(ux) < 4))) /* * Check whether a signed value is always non-negative. @@ -57,7 +55,7 @@ * A cast is needed to avoid any warnings from values that aren't signed * integer types (in which case the result doesn't matter). * - * On 64-bit any integer or pointer type can safely be cast to 'long'. + * On 64-bit any integer or pointer type can safely be cast to 'long long'. * But on 32-bit we need to avoid warnings about casting pointers to integers * of different sizes without truncating 64-bit values so 'long' or 'long long' * must be used depending on the size of the value. @@ -66,12 +64,12 @@ * them, but we do not use s128 types in the kernel (we do use 'u128', * but they are handled by the !is_signed_type() case). */ -#ifdef CONFIG_64BIT - #define __signed_type(ux) long +#if __SIZEOF_POINTER__ == __SIZEOF_LONG_LONG__ +#define __is_nonneg(ux) statically_true((long long)(ux) >= 0) #else - #define __signed_type(ux) typeof(__builtin_choose_expr(sizeof(ux) > 4, 1LL, 1L)) +#define __is_nonneg(ux) statically_true( \ + (typeof(__builtin_choose_expr(sizeof(ux) > 4, 1LL, 1L)))(ux) >= 0) #endif -#define __is_nonneg(ux) statically_true((__signed_type(ux))(ux) >= 0) #define __types_ok(ux, uy) \ (__sign_use(ux) & __sign_use(uy))