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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4894CCCA476 for ; Mon, 6 Oct 2025 12:16:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date :Subject:CC:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=8djAgabF22BDsxfYcNFa72Q6mXnC3doUyHk+thXHzBc=; b=OYgTUhh+V2sCzx2G1SWnhsRrgV 4/QuL8XjBuMPR/xmDhR3UsGlu55dMu7a5MCa7Jw4eQMV58B7iwcR9zdOcaxyZbjHK7lDahWP1KEef /NAXR2pj9gt2h+SzAw1yBmGbK3QpEDauYoA3p/dwU5C2Am4kV0z4tBiMb6CBj5NXb1BnDtNT+N4Qe Mrb7J1YdGR5m7jz3+33j0G4LD9T78qENeOlWN1bs5CShRcexjyVZeMaE3rZp11phZ6Rl1Pr8ZhygZ Yknysqaj7vkT0Vg/zm8TWgQa996KNW14PDdPkroOqbAFCesebNg/exjsDj76rcNln2I9spPDYzQiC 9PCgXwqA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1v5k8z-0000000HZS4-2z66; Mon, 06 Oct 2025 12:16:45 +0000 Received: from fra-out-013.esa.eu-central-1.outbound.mail-perimeter.amazon.com ([63.178.132.221]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1uzYQI-00000002act-2xuE for linux-um@lists.infradead.org; Fri, 19 Sep 2025 10:33:04 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazoncorp2; t=1758277982; x=1789813982; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8djAgabF22BDsxfYcNFa72Q6mXnC3doUyHk+thXHzBc=; b=O7qKbSHhV3N8qZjaaDIXhMKr+5PN65DJGzbXbxi1aKn0ryYvaCvEGbP0 70VcuEmtDOGo56ze6UJz/8syoUlJ47YZbAqDYwyXSbaYlM61nAfkc8dTS XtIr1IchEWjuN1sO/nA912/UKC6vPjHgYr62nkofoY6t9lf739PYQgEwY i3zz4Fc5dIv9gys+PS1cTPPloLhKvD7qldDyvl5+MEYxYYmQkPVfH5Alo gC0iHJDkEGhjf+8LyeF3P2TukTj3u0uX2MfSCe9tgnzwCkd5iiZ5fiUWk +jw7LLVEFgicbar0pOVubKz9aEC+PZAqI2Q2n+jKLt8+x+DNG0GhtQ17g w==; X-CSE-ConnectionGUID: UW5gnmkdQTiXSYEIfmGLQQ== X-CSE-MsgGUID: g8u952lXQ0CQOdRubqmsLw== X-IronPort-AV: E=Sophos;i="6.18,277,1751241600"; d="scan'208";a="2264951" Received: from ip-10-6-6-97.eu-central-1.compute.internal (HELO smtpout.naws.eu-central-1.prod.farcaster.email.amazon.dev) ([10.6.6.97]) by internal-fra-out-013.esa.eu-central-1.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Sep 2025 10:33:00 +0000 Received: from EX19MTAEUA002.ant.amazon.com [54.240.197.232:19477] by smtpin.naws.eu-central-1.prod.farcaster.email.amazon.dev [10.0.8.212:2525] with esmtp (Farcaster) id 3cacb80e-2d3f-4963-bb11-96fbee5fabe1; Fri, 19 Sep 2025 10:33:00 +0000 (UTC) X-Farcaster-Flow-ID: 3cacb80e-2d3f-4963-bb11-96fbee5fabe1 Received: from EX19D018EUA004.ant.amazon.com (10.252.50.85) by EX19MTAEUA002.ant.amazon.com (10.252.50.126) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.20; Fri, 19 Sep 2025 10:32:59 +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, 19 Sep 2025 10:32:30 +0000 From: Eliav Farber To: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , CC: , Arnd Bergmann , Christoph Hellwig , Dan Carpenter , Jens Axboe , Lorenzo Stoakes , "Mateusz Guzik" , Pedro Falcato Subject: [PATCH 26/27 5.10.y] minmax.h: simplify the variants of clamp() Date: Fri, 19 Sep 2025 10:17:26 +0000 Message-ID: <20250919101727.16152-27-farbere@amazon.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250919101727.16152-1-farbere@amazon.com> References: <20250919101727.16152-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: EX19D038UWC002.ant.amazon.com (10.13.139.238) To EX19D018EUA004.ant.amazon.com (10.252.50.85) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250919_033303_041876_898BB3F2 X-CRM114-Status: GOOD ( 14.38 ) X-Mailman-Approved-At: Mon, 06 Oct 2025 05:16:27 -0700 X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-um" Errors-To: linux-um-bounces+linux-um=archiver.kernel.org@lists.infradead.org From: David Laight [ Upstream commit 495bba17cdf95e9703af1b8ef773c55ef0dfe703 ] Always pass a 'type' through to __clamp_once(), pass '__auto_type' from clamp() itself. The expansion of __types_ok3() is reasonable so it isn't worth the added complexity of avoiding it when a fixed type is used for all three values. Link: https://lkml.kernel.org/r/8f69f4deac014f558bab186444bac2e8@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 | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/include/linux/minmax.h b/include/linux/minmax.h index 75fb7a6ad4c6..2bbdd5b5e07e 100644 --- a/include/linux/minmax.h +++ b/include/linux/minmax.h @@ -183,29 +183,29 @@ #define __clamp(val, lo, hi) \ ((val) >= (hi) ? (hi) : ((val) <= (lo) ? (lo) : (val))) -#define __clamp_once(val, lo, hi, uval, ulo, uhi) ({ \ - __auto_type uval = (val); \ - __auto_type ulo = (lo); \ - __auto_type uhi = (hi); \ +#define __clamp_once(type, val, lo, hi, uval, ulo, uhi) ({ \ + type uval = (val); \ + type ulo = (lo); \ + type uhi = (hi); \ BUILD_BUG_ON_MSG(statically_true(ulo > uhi), \ "clamp() low limit " #lo " greater than high limit " #hi); \ BUILD_BUG_ON_MSG(!__types_ok3(uval, ulo, uhi), \ "clamp("#val", "#lo", "#hi") signedness error"); \ __clamp(uval, ulo, uhi); }) -#define __careful_clamp(val, lo, hi) \ - __clamp_once(val, lo, hi, __UNIQUE_ID(v_), __UNIQUE_ID(l_), __UNIQUE_ID(h_)) +#define __careful_clamp(type, val, lo, hi) \ + __clamp_once(type, val, lo, hi, __UNIQUE_ID(v_), __UNIQUE_ID(l_), __UNIQUE_ID(h_)) /** - * clamp - return a value clamped to a given range with strict typechecking + * clamp - return a value clamped to a given range with typechecking * @val: current value * @lo: lowest allowable value * @hi: highest allowable value * - * This macro does strict typechecking of @lo/@hi to make sure they are of the - * same type as @val. See the unnecessary pointer comparisons. + * This macro checks @val/@lo/@hi to make sure they have compatible + * signedness. */ -#define clamp(val, lo, hi) __careful_clamp(val, lo, hi) +#define clamp(val, lo, hi) __careful_clamp(__auto_type, val, lo, hi) /** * clamp_t - return a value clamped to a given range using a given type @@ -217,7 +217,7 @@ * This macro does no typechecking and uses temporary variables of type * @type to make all the comparisons. */ -#define clamp_t(type, val, lo, hi) __careful_clamp((type)(val), (type)(lo), (type)(hi)) +#define clamp_t(type, val, lo, hi) __careful_clamp(type, val, lo, hi) /** * clamp_val - return a value clamped to a given range using val's type @@ -230,7 +230,7 @@ * type and @lo and @hi are literals that will otherwise be assigned a signed * integer type. */ -#define clamp_val(val, lo, hi) clamp_t(typeof(val), val, lo, hi) +#define clamp_val(val, lo, hi) __careful_clamp(typeof(val), val, lo, hi) /* * Do not check the array parameter using __must_be_array(). -- 2.47.3