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 29328CCD182 for ; Fri, 3 Oct 2025 13:07:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8566B8E000E; Fri, 3 Oct 2025 09:07:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 806CD8E0009; Fri, 3 Oct 2025 09:07:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6CF8A8E000E; Fri, 3 Oct 2025 09:07:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 540008E0009 for ; Fri, 3 Oct 2025 09:07:28 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 10A1487E98 for ; Fri, 3 Oct 2025 13:07:28 +0000 (UTC) X-FDA: 83956829376.26.59C0B3E Received: from fra-out-005.esa.eu-central-1.outbound.mail-perimeter.amazon.com (fra-out-005.esa.eu-central-1.outbound.mail-perimeter.amazon.com [63.176.194.123]) by imf29.hostedemail.com (Postfix) with ESMTP id A553C120004 for ; Fri, 3 Oct 2025 13:07:25 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=amazon.com header.s=amazoncorp2 header.b=Z5xD79pP; spf=pass (imf29.hostedemail.com: domain of "prvs=364745ad6=farbere@amazon.com" designates 63.176.194.123 as permitted sender) smtp.mailfrom="prvs=364745ad6=farbere@amazon.com"; dmarc=pass (policy=quarantine) header.from=amazon.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1759496846; 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=mgpCG1EjDKhzjraDAwxWg/avNo+BhlXrWo1NM31HVUzZMJ4fb5a1TFpMBBL4D39SbQmqI3 5FUvU0VTuKLdm70+lDcNOW/KpLwXXL7TgdO8+yXS1bbl+tL2sg11YkBw68ZYXoTPfyA7Mt nzUTmojhpnp1chrO6cSHIC2MykX0kIo= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=amazon.com header.s=amazoncorp2 header.b=Z5xD79pP; spf=pass (imf29.hostedemail.com: domain of "prvs=364745ad6=farbere@amazon.com" designates 63.176.194.123 as permitted sender) smtp.mailfrom="prvs=364745ad6=farbere@amazon.com"; dmarc=pass (policy=quarantine) header.from=amazon.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1759496846; a=rsa-sha256; cv=none; b=Xjb5Wh7rJ2wcCmUw+0ZT5DO2P10j4KCrU4FOKiAqLzngBmTajXkdwhonLOo+NU1dXidl0d SxgtGt3TyAy9M2DUw4w1PnfrshIDzr53NOTlrYLgSmscknJJscz+L6/Jw1iCeNxm5LrWNH fpTi3cNdWZPJuUmKoodW/RiwARlWR/E= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazoncorp2; t=1759496845; x=1791032845; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0AzpApDbX8CFEbC2P7WHNPH2gra+XDIh1eSQ6GUhJZw=; b=Z5xD79pPHd6M/jjGKzpSIqgGmt+anrYR8Q3qYbyHmAOcn6SoScnh7kkU 880mdSEJaOQQOCmLZovfP0ybL5Rn931nM3EI7rag2IFqsJFtvKGwF/7JZ yw8Rn2tAwBEonMAEvtevgMSN8NUknrAhrYF2xY1DWtDSIUB8KR1UG7tHe mhIYgi36eIhoOT37IYXfUna2iRPVTXgycSW+QZlWKkoehHFmEH3uULqHF /hCZVGQncS3TceGEZsil1+DyJP3lWx6l+pOxFAv459J542ldf6AEttSlD WN9F7klNgRW4Uxd9MSXsHUI4x5BFbzf+4dBT3FzPCESA5ne71S+qx9CMz g==; X-CSE-ConnectionGUID: 5M94BRBwSnS66mVzRApKLw== X-CSE-MsgGUID: fIkkoo1YSaeiXfD03qJifw== X-IronPort-AV: E=Sophos;i="6.18,312,1751241600"; d="scan'208";a="3063657" Received: from ip-10-6-11-83.eu-central-1.compute.internal (HELO smtpout.naws.eu-central-1.prod.farcaster.email.amazon.dev) ([10.6.11.83]) by internal-fra-out-005.esa.eu-central-1.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Oct 2025 13:07:23 +0000 Received: from EX19MTAEUC001.ant.amazon.com [54.240.197.225:11484] by smtpin.naws.eu-central-1.prod.farcaster.email.amazon.dev [10.0.19.222:2525] with esmtp (Farcaster) id 286331e4-5516-4ed1-81e3-c1196b39067a; Fri, 3 Oct 2025 13:07:23 +0000 (UTC) X-Farcaster-Flow-ID: 286331e4-5516-4ed1-81e3-c1196b39067a Received: from EX19D018EUA004.ant.amazon.com (10.252.50.85) by EX19MTAEUC001.ant.amazon.com (10.252.51.193) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.20; Fri, 3 Oct 2025 13:07:13 +0000 Received: from dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (172.19.116.181) by EX19D018EUA004.ant.amazon.com (10.252.50.85) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.20; Fri, 3 Oct 2025 13:06:47 +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 v2 14/19 5.15.y] minmax.h: update some comments Date: Fri, 3 Oct 2025 13:00:01 +0000 Message-ID: <20251003130006.41681-15-farbere@amazon.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251003130006.41681-1-farbere@amazon.com> References: <20251003130006.41681-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: EX19D036UWB003.ant.amazon.com (10.13.139.172) To EX19D018EUA004.ant.amazon.com (10.252.50.85) X-Stat-Signature: qp7kjqb9uex8agftw973nhbdobtgojud X-Rspam-User: X-Rspamd-Queue-Id: A553C120004 X-Rspamd-Server: rspam04 X-HE-Tag: 1759496845-398896 X-HE-Meta: U2FsdGVkX18oE2PYkDoBg9I+e4rXOWQlqCpTxeL2Q0jMqZ+wZfMgpkGvy+tLrY8bWhc0Hg5SMvh0RMjBDgi8rktYdL9rFa+jJ0BbZfuXqtcH0K29MwWHrgWGih3iJzsGwxc+Y+MzRuv2rl590DQ+NigtP5Usi8yAH9G6SFYvY0I0oPSzAvdA7uJPyfcqRa99syfG+56w3eCRx2FK1MQIbFPRi8m2joMSDgWgvYc83fJzAY5MrE0KAw816GiPPAkvxvXB+BK3/mdZZInR1xy50jAEwA0RCnpWEkWgpyHDSbqjdsP4xxw4LJ2ykchCUd0swDUcuJTIHh+zOdPdgbQwc3LZ5HbuXPU0U70N+k5P5C8l3XWbmzb4wU1xH8m1kFCjBIugujimRYR5+bX+Ewdrcu1LReTmFzu30AY6jklWuaffTK+j5AYP8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uf5V0JjHblaZvYCEXj1CfGpe27sQyTeepGWV+oRXnwb0JBgVr1s3CkF3UzfzyVMqWarlgR7BM8AV7wHkFSzBtm2Y8ae+/Fnr6ca/RKtLbg05TN6dtlQy4IQgki6c7do/RYrHTUuOOAO+DmlZKG6pGKUz70+SeLnzIgaYtujlhJX6tUj0dyeFOAFeB80UALbiVZtLrrbvMytbugL0lbr2eHW0+gMncaPRYxl9oEa8xcN0cFKdYsSjhzVAMIAVszkDM03YINxyFln22aNoI8Ai3Hn/78wnQv1y97qI3p8eBDgp2yk0GKoa7JSUUjNm3Us3sAUwTeAnXVzpu5b0IVR82cvNfxTjzh2TfNwllhkriugs67VdFdIlPfyqWWurma+syO15hq+1jf40/cqS1U/czuWvJpmqWLGihqF0LoILpwxPRyYf/jvd26ACrWzfcu9gpOUzgs4kMchplhua93zf0 ikr0NxRG YKMKW0CWHn7T5xJuoFZXNbgDBrdC2a/VTpz5QpIbgB9c0uVOFfnTzMy5ey3pZC601IwSCuXLIFzTOL7V+midShCIB4XO82lNUdGGOZOoP0kpjw3ZyooQkixIqnHx6gnc970AUs80zmC7g9tofyybCetxYv7qdW/3GeLqYggzR50nD8exzNRzhw== 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