From patchwork Sun Feb 25 16:52:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Laight X-Patchwork-Id: 13570969 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.85.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6CE2217BB5 for ; Sun, 25 Feb 2024 16:52:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.58.85.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708879950; cv=none; b=E/YlOZqOkdZ/VNF7TskXwFa8kXq6HTUgAeTXFFNvgkUq5PYZlPevLA1qaZExkvBpLcUeDemg/MA6NjjjEgomq9Qw81pj3OtRjduw5YImRoLgU8j0xKDsR6ba8XOi5OPTlDcyoQhIeAwKNwNzQRg8HsIHLdeJKqBiJSk3q/xoPCk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708879950; c=relaxed/simple; bh=dxzwutw/uYInR/fAygjwtW6vRzUH7ChzCxCY1kqoRdc=; h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To: MIME-Version:Content-Type; b=NINFFiW6v+cKxXkz2pPZsBaJACW8A/SXvQZsX+XObCWfGNDJRCzt4iMtPmUD/F/g9yBd9QWGa7lxoxLaVMoKCo2wbKUjhquWRagwBYm/oG9lUzlpXZ6nsVNZWb9bx7nhxHXhNF2olfSuBItsD8QUiRXAab3PoIh7hTcUIxdLVDw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ACULAB.COM; spf=pass smtp.mailfrom=aculab.com; arc=none smtp.client-ip=185.58.85.151 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ACULAB.COM Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=aculab.com 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-98-15ZuON0NN0C4fR-488HG-w-1; Sun, 25 Feb 2024 16:52:24 +0000 X-MC-Unique: 15ZuON0NN0C4fR-488HG-w-1 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; Sun, 25 Feb 2024 16:52:22 +0000 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Sun, 25 Feb 2024 16:52:22 +0000 From: David Laight To: "'linux-kernel@vger.kernel.org'" , "'Linus Torvalds'" , 'Netdev' , "'dri-devel@lists.freedesktop.org'" CC: 'Jens Axboe' , "'Matthew Wilcox (Oracle)'" , 'Christoph Hellwig' , "'linux-btrfs@vger.kernel.org'" , "'Andrew Morton'" , 'Andy Shevchenko' , "'David S . Miller'" , 'Dan Carpenter' , "'Jani Nikula'" Subject: [PATCH next v2 06/11] minmax: Remove 'constexpr' check from __careful_clamp() Thread-Topic: [PATCH next v2 06/11] minmax: Remove 'constexpr' check from __careful_clamp() Thread-Index: AdpoCvvrOCX/oa+QSiiCG9QfHbI0jw== Date: Sun, 25 Feb 2024 16:52:22 +0000 Message-ID: References: <0fff52305e584036a777f440b5f474da@AcuMS.aculab.com> In-Reply-To: <0fff52305e584036a777f440b5f474da@AcuMS.aculab.com> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Nothing requires that clamp() return a constant expression. The logic to do so significantly increases the .i file. Remove the check and directly expand __clamp_once() from clamp_t() since the type check can't fail. Signed-off-by: David Laight --- include/linux/minmax.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) Changes for v2: - Typographical and spelling corrections to the commit messages. Patches unchanged. diff --git a/include/linux/minmax.h b/include/linux/minmax.h index 111c52a14fe5..5c7fce76abe5 100644 --- a/include/linux/minmax.h +++ b/include/linux/minmax.h @@ -141,12 +141,10 @@ "clamp() low limit " #lo " greater than high limit " #hi); \ __clamp(__val_##uniq, __lo_##uniq, __hi_##uniq); }) -#define __careful_clamp(val, lo, hi, uniq) \ - __builtin_choose_expr(__is_constexpr((val) - (lo) + (hi)), \ - __clamp(val, lo, hi), \ - ({ _Static_assert(__types_ok(val, lo), "clamp() 'lo' signedness error"); \ - _Static_assert(__types_ok(val, hi), "clamp() 'hi' signedness error"); \ - __clamp_once(val, lo, hi, uniq); })) +#define __careful_clamp(val, lo, hi, uniq) ({ \ + _Static_assert(__types_ok(val, lo), "clamp() 'lo' signedness error"); \ + _Static_assert(__types_ok(val, hi), "clamp() 'hi' signedness error"); \ + __clamp_once(val, lo, hi, uniq); }) /** * clamp - return a value clamped to a given range with strict typechecking @@ -168,7 +166,9 @@ * This macro does no typechecking and uses temporary variables of type * @type to make all the comparisons. */ -#define clamp_t(type, val, lo, hi) clamp((type)(val), (type)(lo), (type)(hi)) +#define __clamp_t(type, val, lo, hi, uniq) \ + __clamp_once((type)(val), (type)(lo), (type)(hi), uniq) +#define clamp_t(type, val, lo, hi) __clamp_t(type, val, lo, hi, __COUNTER__) /** * clamp_val - return a value clamped to a given range using val's type