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 BE6E1CCD186 for ; Mon, 6 Oct 2025 12:17:10 +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=GIzXOOEvZKeS6UuNgkU2k1mesw4I+NOSJCqENQl3gzM=; b=fDwfZV/Rq7o8ghqqLXjHsz/M/F PtuaBzpvNdoBgjMc/9gmRHjsbRNEw17CSLm3gBeoMUCETvmpLI0pd3g3aCboccpDn7vK7a1OVN7eY 23kWtg6OCjTMCZfp8jnZNaprqyeBLVEzZqdBE0T4plOefdMzl4+BYUKzH9pZvr8+4aL2gT9QyUZh3 JCi4EI6xaI7N7ggwX1XedLAgFZiafTScs0IYrBCmpgVOd8qSp3KKCC0YjBekcR7Cj4HAjulfO0VTM 85+VlQk9J3wl1QvpqduqjKhcL8DDGDdQVg+fdeEKQlaPuYBg2tCLB1dDdvilVyF/4LriQ0tGyFb6I GHVuQhyw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1v5k9O-0000000Ha1n-1Kv1; Mon, 06 Oct 2025 12:17:10 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1v1W6A-00000003Tla-1hKG for linux-um@bombadil.infradead.org; Wed, 24 Sep 2025 20:28:22 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:Content-Transfer-Encoding :MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From: Sender:Reply-To:Content-ID:Content-Description; bh=GIzXOOEvZKeS6UuNgkU2k1mesw4I+NOSJCqENQl3gzM=; b=ZO6t5N7nmnWo8vjDreYdNGk+w5 Rl2BDzVsgN+M4+uTtbnb/aVNqV9rUcQmhBZ/h+PDEIn9n8Dfxce6BboKdrTtbqqCU0Vh6IzkSQxc6 yed9/2m3h1PLziGsGha/9edToUGiOPHdwTi1l73qDInXrdbd7qIeigWz+vftivoD+BYU7ndhCRGgk 19xvgXrZw0LUyRZux7RH1Yd+AHzKFR1aFHzwH60tkV89fNj9EI2ibgBLh9pFlePRdPI4Z8V+HY8Wq OcMYtiSSs1g2kiy+w2W2YtYdtQH5OQ+r2qbLXrJ2NMBwIGZ7yj2hrwpTuCR3NdMlrW1SZPiXo3/Td YuFSUfhw==; Received: from fra-out-013.esa.eu-central-1.outbound.mail-perimeter.amazon.com ([63.178.132.221]) by desiato.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1v1W5b-00000008qhR-1fpL for linux-um@lists.infradead.org; Wed, 24 Sep 2025 20:28:20 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazoncorp2; t=1758745667; x=1790281667; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=GIzXOOEvZKeS6UuNgkU2k1mesw4I+NOSJCqENQl3gzM=; b=h/gXHiMuw60hHDnW7ICz8zzmixbuSZnTDXO24b527XW6ThHxMisCJ0Qt qynVNUHUMtor8wx0O57WQOiQto0W8A3kmlD3g2ymY3SR/TOHs6VYXbILU 96Wgb8DxakfK2ONOScanG+aw7Rm/ISDocuoT48y+oENSdTgbzy+8IXKi1 UVXX5OEo7bRdNdeF9Q7CK9MO5v56lUkvZPqj0ZTRVFHh94ht3FPWx5WMv zZXhwNmBnEN/ydjrO8SjaSu63rBB5GPvW3gbhXBIh9Tu13tWg2FtgP8Km COR7KrHEf7OUbYwaulUO8wLxH8XepjrnIHZZ5C6UOzQ3PoyBb8bafHGoy A==; X-CSE-ConnectionGUID: DOyQPSVVQ9+MEGuxbzdE4w== X-CSE-MsgGUID: APf9BeIHRW2QvJKm+s4Pyw== X-IronPort-AV: E=Sophos;i="6.18,291,1751241600"; d="scan'208";a="2527364" 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; 24 Sep 2025 20:27:45 +0000 Received: from EX19MTAEUC002.ant.amazon.com [54.240.197.228:5140] by smtpin.naws.eu-central-1.prod.farcaster.email.amazon.dev [10.0.23.230:2525] with esmtp (Farcaster) id 5fcc0229-914a-4de9-bab4-c4b4add23b5e; Wed, 24 Sep 2025 20:27:45 +0000 (UTC) X-Farcaster-Flow-ID: 5fcc0229-914a-4de9-bab4-c4b4add23b5e Received: from EX19D018EUA004.ant.amazon.com (10.252.50.85) by EX19MTAEUC002.ant.amazon.com (10.252.51.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.20; Wed, 24 Sep 2025 20:27:45 +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; Wed, 24 Sep 2025 20:27:09 +0000 From: Eliav Farber To: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , CC: Linus Torvalds , David Laight , Lorenzo Stoakes Subject: [PATCH 06/19 v6.1.y] minmax: simplify and clarify min_t()/max_t() implementation Date: Wed, 24 Sep 2025 20:23:07 +0000 Message-ID: <20250924202320.32333-7-farbere@amazon.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250924202320.32333-1-farbere@amazon.com> References: <20250924202320.32333-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: EX19D037UWB002.ant.amazon.com (10.13.138.121) 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-20250924_212817_683930_69ACBBB0 X-CRM114-Status: UNSURE ( 9.35 ) X-CRM114-Notice: Please train this message. X-Mailman-Approved-At: Mon, 06 Oct 2025 05:16:28 -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: Linus Torvalds [ Upstream commit 017fa3e89187848fd056af757769c9e66ac3e93d ] This simplifies the min_t() and max_t() macros by no longer making them work in the context of a C constant expression. That means that you can no longer use them for static initializers or for array sizes in type definitions, but there were only a couple of such uses, and all of them were converted (famous last words) to use MIN_T/MAX_T instead. Cc: David Laight Cc: Lorenzo Stoakes Signed-off-by: Linus Torvalds Signed-off-by: Eliav Farber --- include/linux/minmax.h | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/include/linux/minmax.h b/include/linux/minmax.h index a7ef65f78933..9c2848abc804 100644 --- a/include/linux/minmax.h +++ b/include/linux/minmax.h @@ -45,17 +45,20 @@ #define __cmp(op, x, y) ((x) __cmp_op_##op (y) ? (x) : (y)) -#define __cmp_once(op, x, y, unique_x, unique_y) ({ \ - typeof(x) unique_x = (x); \ - typeof(y) unique_y = (y); \ +#define __cmp_once_unique(op, type, x, y, ux, uy) \ + ({ type ux = (x); type uy = (y); __cmp(op, ux, uy); }) + +#define __cmp_once(op, type, x, y) \ + __cmp_once_unique(op, type, x, y, __UNIQUE_ID(x_), __UNIQUE_ID(y_)) + +#define __careful_cmp_once(op, x, y) ({ \ static_assert(__types_ok(x, y), \ #op "(" #x ", " #y ") signedness error, fix types or consider u" #op "() before " #op "_t()"); \ - __cmp(op, unique_x, unique_y); }) + __cmp_once(op, __auto_type, x, y); }) #define __careful_cmp(op, x, y) \ __builtin_choose_expr(__is_constexpr((x) - (y)), \ - __cmp(op, x, y), \ - __cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y))) + __cmp(op, x, y), __careful_cmp_once(op, x, y)) #define __clamp(val, lo, hi) \ ((val) >= (hi) ? (hi) : ((val) <= (lo) ? (lo) : (val))) @@ -158,7 +161,7 @@ * @x: first value * @y: second value */ -#define min_t(type, x, y) __careful_cmp(min, (type)(x), (type)(y)) +#define min_t(type, x, y) __cmp_once(min, type, x, y) /** * max_t - return maximum of two values, using the specified type @@ -166,7 +169,7 @@ * @x: first value * @y: second value */ -#define max_t(type, x, y) __careful_cmp(max, (type)(x), (type)(y)) +#define max_t(type, x, y) __cmp_once(max, type, x, y) /* * Do not check the array parameter using __must_be_array(). -- 2.47.3