From mboxrd@z Thu Jan 1 00:00:00 1970 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]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5D1AFCCA470 for ; Wed, 8 Oct 2025 15:34:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B73208E0038; Wed, 8 Oct 2025 11:34:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B4AA98E0002; Wed, 8 Oct 2025 11:34:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A60FB8E0038; Wed, 8 Oct 2025 11:34:24 -0400 (EDT) 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 961EA8E0002 for ; Wed, 8 Oct 2025 11:34:24 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 34D7E1A05B5 for ; Wed, 8 Oct 2025 15:34:24 +0000 (UTC) X-FDA: 83975343648.16.BC7190D Received: from pdx-out-012.esa.us-west-2.outbound.mail-perimeter.amazon.com (pdx-out-012.esa.us-west-2.outbound.mail-perimeter.amazon.com [35.162.73.231]) by imf28.hostedemail.com (Postfix) with ESMTP id D99C2C0011 for ; Wed, 8 Oct 2025 15:34:21 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=amazon.com header.s=amazoncorp2 header.b=tgRuiBKk; dmarc=pass (policy=quarantine) header.from=amazon.com; spf=pass (imf28.hostedemail.com: domain of "prvs=36971892a=farbere@amazon.com" designates 35.162.73.231 as permitted sender) smtp.mailfrom="prvs=36971892a=farbere@amazon.com" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1759937662; 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:dkim-signature; bh=0AzpApDbX8CFEbC2P7WHNPH2gra+XDIh1eSQ6GUhJZw=; b=LULtgbbVIp1sBJ/3DgMJyd+T1KcxMpM88pP2jQZl67+bEg5eCzI3/e8zq+mHznuaXX6ecJ yF9afAL5wxGjYFRNeAbKmYeTebeg6WjVqTl1cSpH9hmUgiH9B9HM5vvmll0trPOaI5fwOz 9fMzf62L9edpMWdqIhmh0NAt8rk9sJM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1759937662; a=rsa-sha256; cv=none; b=kFMt//eVtmSAEknr40FAEIj2zgq5nwIw53KEWEBhdPCVQDMihNiGYpv8Sh7tKsZ/Ssjrbk 8KommXoALP69ULAxFxWjpIYg+N1z+rb6Y8neXOdkHmiiIdmTc6oornxK0uNUjYcDOl7Zbt +fue9Zv/wNjOESfXQoLtl56/21VWd4M= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=amazon.com header.s=amazoncorp2 header.b=tgRuiBKk; dmarc=pass (policy=quarantine) header.from=amazon.com; spf=pass (imf28.hostedemail.com: domain of "prvs=36971892a=farbere@amazon.com" designates 35.162.73.231 as permitted sender) smtp.mailfrom="prvs=36971892a=farbere@amazon.com" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazoncorp2; t=1759937661; x=1791473661; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0AzpApDbX8CFEbC2P7WHNPH2gra+XDIh1eSQ6GUhJZw=; b=tgRuiBKkhE/uRe/ULkG9ePg53bzLv11Zoa/SePyz0reQN2tZKY6X295R 1czjd/yL5ZCKSAqlc09n838EOafk/sVSKW31lM5YYqDgqF/fvWLEXkomt Wh9/V2sPMeTapCNT7ySIq1y1LHD9eZXr/HXZaMgn22UZuyeexqGPivg9M vnvFOIlND7WILzYFA8KDlQn5gIM3cV8uptdk8b+84x/3Y5qYbBgIcNv9B grcynAMd0cTi4nHTdwuyy7cH4dJlgPhMPQkqKZQ9Y6iwa7W8HV62cNL/8 fiewFCyor3J9r+KqPuiOBNxWo8yAJRa+J1bxHAXoFGWZqem5OZfq+6vTm A==; X-CSE-ConnectionGUID: gLukBxtNQKGGct94M4/5Uw== X-CSE-MsgGUID: uUIyK8i9TEafYIklmFnKXg== X-IronPort-AV: E=Sophos;i="6.19,213,1754956800"; d="scan'208";a="4335130" Received: from ip-10-5-9-48.us-west-2.compute.internal (HELO smtpout.naws.us-west-2.prod.farcaster.email.amazon.dev) ([10.5.9.48]) by internal-pdx-out-012.esa.us-west-2.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Oct 2025 15:34:20 +0000 Received: from EX19MTAUWA001.ant.amazon.com [10.0.7.35:14896] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.35.225:2525] with esmtp (Farcaster) id 6f1d6760-0446-4fdc-a5e2-0aa8f0cefc04; Wed, 8 Oct 2025 15:34:20 +0000 (UTC) X-Farcaster-Flow-ID: 6f1d6760-0446-4fdc-a5e2-0aa8f0cefc04 Received: from EX19D001UWA001.ant.amazon.com (10.13.138.214) by EX19MTAUWA001.ant.amazon.com (10.250.64.204) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.20; Wed, 8 Oct 2025 15:34:16 +0000 Received: from dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (172.19.116.181) by EX19D001UWA001.ant.amazon.com (10.13.138.214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.20; Wed, 8 Oct 2025 15:34:03 +0000 From: Eliav Farber To: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , CC: Arnd Bergmann , Christoph Hellwig , Dan Carpenter , "Jason A. Donenfeld" , Jens Axboe , Lorenzo Stoakes , Mateusz Guzik , "Pedro Falcato" Subject: [PATCH v3 14/19 5.15.y] minmax.h: update some comments Date: Wed, 8 Oct 2025 15:29:39 +0000 Message-ID: <20251008152946.29285-15-farbere@amazon.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251008152946.29285-1-farbere@amazon.com> References: <20251008152946.29285-1-farbere@amazon.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [172.19.116.181] X-ClientProxiedBy: EX19D042UWB004.ant.amazon.com (10.13.139.150) To EX19D001UWA001.ant.amazon.com (10.13.138.214) X-Rspam-User: X-Rspamd-Queue-Id: D99C2C0011 X-Rspamd-Server: rspam02 X-Stat-Signature: hci1bixq83zbnmsfixge6gqyfyhfq6bw X-HE-Tag: 1759937661-19625 X-HE-Meta: U2FsdGVkX182v7aHT8E6LKR5WSlJ51oiYBIFPUffJZdJaMijBbnlae3YIuHe7XGQJ4LAhDffDfrKdzZcbVcT3c147LWPAfZMMZG9m4LYOftNmu1IhPAneUcEPe95/VOBiRGC7Vi+xBKCzuxKtLRkX1+vBIDVrNUWO+pXeaG0G9a59N1gM5nBgeirZKCeIpBO+ClFLDz35XJMJGMDk4F+H3pArJc3btaTBDcdZDbDSd6Y8JPYR/GgQAhxEZRU5erRRylq0QZZG8VYNzltijhUoHd2iiCal2aId1zVKPzbiIGuIyk7rrP9UX0HvolSnLx/SIKQzyFoqwChcsHNTWUGqJbPo5gDoBcw+YzNWouR3LIhWutGmNYmUsFzGLQaUoIhwxs5GkhSuCiGW88JNJX4GRG6kZvzskaVmdkAIxv+fIiqc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4LhdTx6E7FIFfaPbhslLS8UZ/KvqSwfSRclWWvNw0L4PuK7LcqFHk76NSsv0tCrBXegircfVy3JsNJHyI+ZCnEczpolTx86cjc4EYy4PkOHLQj3uUY85ToD75xA6zf0ecVMv3gqOusv6Pb7I8bWl+zdtfZP3RdstL46JLt7pyJF8/sA7ubaBIGHBEsfezmi9RuTRiop718e3RfXDZH/OMMqF/DXxT88Xni/sAxrugrw8xVc+GXU/bkIGxJEKb+cOvA+nIK2EE1KXY5ueuV0rzrCDCuQIelXkjI9zBjfaGm+jWm4rYYCqlSHanNwB6U0FRLDc1q0Tv+oumt86t79NekUzB+gIzisCFDSWzid2u4WZNTAp/crB8P98Axo8ygIUWe+T4oghXzDRORVpEt6A53P0ibiy7w+I9SNJK+JTVT46f+Jlc4kAiUdrzK1+HUI7/rvzjiVRTk0NuBwAOl0gbEOKf+vS Cq8CUntN QheFxnzNPyWNVcg2jARGcZ7PkHUS3h88x21TWB+v/7vCDdsPwDpP7kHv/V33SbTLd9lNQBlJB3YSfsut79OeRl1wQ8ZIv4lUPNkymMAtn00ruCocJ+abNm7jVfn/kSzz5aPh5KsA0d2/241LKwj0FPp3EikabP0nLac8redGJIiuR/mcGdL+jezNv3Hr42QkN08jq9EazSIf+3x7ZJmN4+aD4O8oXJLITTcMTC7v/MbjieGZXObOHLEaPuV+bQLwiRMSF9ee5lEI5GnVsF6yUQ== 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: From: David Laight [ Upstream commit 10666e99204818ef45c702469488353b5bb09ec7 ] - 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. Link: https://lkml.kernel.org/r/85b050c81c1d4076aeb91a6cded45fee@AcuMS.aculab.com Signed-off-by: David Laight Cc: Andy Shevchenko Cc: Arnd Bergmann Cc: Christoph Hellwig Cc: Dan Carpenter Cc: Jason A. Donenfeld Cc: Jens Axboe Cc: Lorenzo Stoakes Cc: Mateusz Guzik Cc: Matthew Wilcox Cc: Pedro Falcato Signed-off-by: Andrew Morton Signed-off-by: Eliav Farber --- 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 -- 2.47.3