From patchwork Mon Nov 18 19:12:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Laight X-Patchwork-Id: 13878984 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 B797ED591AD for ; Mon, 18 Nov 2024 19:12:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 51F3E6B0093; Mon, 18 Nov 2024 14:12:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4CF716B0095; Mon, 18 Nov 2024 14:12:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 397886B0096; Mon, 18 Nov 2024 14:12:16 -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 178586B0093 for ; Mon, 18 Nov 2024 14:12:16 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id CBECEACE91 for ; Mon, 18 Nov 2024 19:12:15 +0000 (UTC) X-FDA: 82800160506.04.B5CC3E7 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 84A6A40012 for ; Mon, 18 Nov 2024 19:11:35 +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=1731957043; 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=VLsFOgRWaKjCZEStmR6xIL41uZE8Bm39Z0Bsb4xM78k=; b=rRzz3hAYvV5LK94642VXLI14fjiimgXPHi8IotL76Az1H//3w0bQawkxUIPCPmEGepdX5f rgdIga5JsCUSMNW2nHurTBXtgdroTB+yy/esdc/PJ/wQB8hwkvw2W6Hs6nUqVlamssm9dS iGuuWb/s1PhjMOWuV95hWrgiZBvcHOg= 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 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731957043; a=rsa-sha256; cv=none; b=67j+PxspV+73Pvinn5PZSBS7CmVynqiiH4fhTEpcwLYinUeL4eFZc2vgCb1Vm745kbW8ow gwcd0I2QGbLcgsP7P04KG/rmBmh1CZ7LZv0v+sf1b3S3ut1o/7oeLQ5tXSyhx2eACdsscy 39+/I6bqGy28BkECTYqTshfc6xWBG/M= 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-131-lyN8MeafO_qKA23yXAR8qw-1; Mon, 18 Nov 2024 19:12:08 +0000 X-MC-Unique: lyN8MeafO_qKA23yXAR8qw-1 X-Mimecast-MFC-AGG-ID: lyN8MeafO_qKA23yXAR8qw 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:12:07 +0000 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Mon, 18 Nov 2024 19:12:07 +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 2/7] minmax.h: Update some comments Thread-Topic: [PATCH next 2/7] minmax.h: Update some comments Thread-Index: Ads57cA01trJ5zhURpGnEK/DpxxPAQ== Date: Mon, 18 Nov 2024 19:12:07 +0000 Message-ID: <85b050c81c1d4076aeb91a6cded45fee@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: Gye7onJebyoynL6Yb4X9XFsIISgAcmbMkI1XVDJFG-I_1731957127 X-Mimecast-Originator: aculab.com Content-Language: en-US X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 84A6A40012 X-Stat-Signature: e9ar8ywodj8kiar66p6xzn5rrn6a56wq X-HE-Tag: 1731957095-372668 X-HE-Meta: U2FsdGVkX1920eXoeY+9Auu90mCxuT03tRnNiDLhZCQyUEjvACwpCu5Eo2yfDKnnfZ3LRbNmTpV66gmnsoogS46TEUsJXEA1QtcZYLBmaR2qqCHWaeQwbqfaluSS61KD7sv5vYuTpqx83b/800DRmD9jWMv4H5ImhG4NECv52FeCyUZzHsmt+i4JFQS8qXKtRACDI4W72c6VaBw0TxDHN771mOmJsy45ZuzyeL0RF77/F+ULjWkjftP6+hszqnbhbEeQcRavQ/HssFmx4MDKM87PCWVib1JdeJgxafHLLBRM3WV18ghS096R0XxZ+Jh0igZ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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: - Change three to several. - Remove the comment about retaining constant expressions, no longer true. - Realign to nearer 80 columns and break on major punctiation. - Add a leading comment to the block before __signed_type() and __is_nonneg() Otherwise the block explaining the cast is a bit 'floating'. Reword the rest of that comment to improve readability. Signed-off-by: David Laight --- include/linux/minmax.h | 53 +++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 29 deletions(-) diff --git a/include/linux/minmax.h b/include/linux/minmax.h index 51b0d988e322..24e4b372649a 100644 --- a/include/linux/minmax.h +++ b/include/linux/minmax.h @@ -8,13 +8,10 @@ #include /* - * min()/max()/clamp() macros must accomplish three things: + * min()/max()/clamp() macros must accomplish several things: * * - Avoid multiple evaluations of the arguments (so side-effects like * "x++" happen only once) when non-constant. - * - Retain result as a constant expressions when called with only - * constant expressions (to avoid tripping VLA warnings in stack - * allocation usage). * - Perform signed v unsigned type-checking (to generate compile * errors instead of nasty runtime surprises). * - Unsigned char/short are always promoted to signed int and can be @@ -31,25 +28,23 @@ * bit #0 set if ok for unsigned comparisons * bit #1 set if ok for signed comparisons * - * In particular, statically non-negative signed integer - * expressions are ok for both. + * In particular, statically non-negative signed integer expressions + * are ok for both. * - * NOTE! Unsigned types smaller than 'int' are implicitly - * converted to 'int' in expressions, and are accepted for - * signed conversions for now. This is debatable. + * NOTE! Unsigned types smaller than 'int' are implicitly converted to 'int' + * in expressions, and are accepted for signed conversions for now. + * This is debatable. * - * Note that 'x' is the original expression, and 'ux' is - * the unique variable that contains the value. + * Note that 'x' is the original expression, and 'ux' is the unique variable + * that contains the value. * - * We use 'ux' for pure type checking, and 'x' for when - * we need to look at the value (but without evaluating - * it for side effects! Careful to only ever evaluate it - * with sizeof() or __builtin_constant_p() etc). + * We use 'ux' for pure type checking, and 'x' for when we need to look at the + * value (but without evaluating it for side effects! + * Careful to only ever evaluate it with sizeof() or __builtin_constant_p() etc). * - * Pointers end up being checked by the normal C type - * rules at the actual comparison, and these expressions - * only need to be careful to not cause warnings for - * pointer use. + * Pointers end up being checked by the normal C type rules at the actual + * comparison, and these expressions only need to be careful to not cause + * warnings for pointer use. */ #define __signed_type_use(x, ux) (2 + __is_nonneg(x, ux)) #define __unsigned_type_use(x, ux) (1 + 2 * (sizeof(ux) < 4)) @@ -57,19 +52,19 @@ __signed_type_use(x, ux) : __unsigned_type_use(x, ux)) /* - * To avoid warnings about casting pointers to integers - * of different sizes, we need that special sign type. + * Check whether a signed value is always non-negative. * - * On 64-bit we can just always use 'long', since any - * integer or pointer type can just be cast to that. + * A cast is needed to avoid any warnings from values that aren't signed + * integer types (in which case the result doesn't matter). * - * This does not work for 128-bit signed integers since - * the cast would truncate them, but we do not use s128 - * types in the kernel (we do use 'u128', but they will - * be handled by the !is_signed_type() case). + * On 64-bit any integer or pointer type can safely be cast to '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. * - * NOTE! The cast is there only to avoid any warnings - * from when values that aren't signed integer types. + * This does not work for 128-bit signed integers since the cast would truncate + * 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