From patchwork Sun Feb 25 16:51:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Laight X-Patchwork-Id: 13570954 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 F357BC54798 for ; Sun, 25 Feb 2024 16:51:47 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D6A8B10E104; Sun, 25 Feb 2024 16:51:46 +0000 (UTC) Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.85.151]) by gabe.freedesktop.org (Postfix) with ESMTPS id 61AD310E104 for ; Sun, 25 Feb 2024 16:51:44 +0000 (UTC) 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-162-Lu8Z5gaeMJOpXAp0JCRhCA-1; Sun, 25 Feb 2024 16:51:40 +0000 X-MC-Unique: Lu8Z5gaeMJOpXAp0JCRhCA-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:51:39 +0000 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Sun, 25 Feb 2024 16:51:39 +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 05/11] minmax: Move the signedness check out of __cmp_once() and __clamp_once() Thread-Topic: [PATCH next v2 05/11] minmax: Move the signedness check out of __cmp_once() and __clamp_once() Thread-Index: AdpoCtyXoWYCYse4RrSXey2WeynGfg== Date: Sun, 25 Feb 2024 16:51:39 +0000 Message-ID: <996e4d9df3a845488d740b90934a668c@AcuMS.aculab.com> 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 x-originating-ip: [10.202.205.107] MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" There is no need to do the signedness/type check when the arguments are being cast to a fixed type. So move the check out of __xxx_once() into __careful_xxx(). 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 8ee003d8abaf..111c52a14fe5 100644 --- a/include/linux/minmax.h +++ b/include/linux/minmax.h @@ -46,14 +46,14 @@ #define __cmp_once(op, x, y, uniq) ({ \ typeof(x) __x_##uniq = (x); \ typeof(y) __y_##uniq = (y); \ - _Static_assert(__types_ok(x, y), \ - #op "(" #x ", " #y ") signedness error, fix types or consider u" #op "() before " #op "_t()"); \ __cmp(op, __x_##uniq, __y_##uniq); }) #define __careful_cmp(op, x, y, uniq) \ __builtin_choose_expr(__is_constexpr((x) - (y)), \ __cmp(op, x, y), \ - __cmp_once(op, x, y, uniq)) + ({ _Static_assert(__types_ok(x, y), \ + #op "(" #x ", " #y ") signedness error, fix types or consider u" #op "() before " #op "_t()"); \ + __cmp_once(op, x, y, uniq); })) /** * min - return minimum of two values of the same or compatible types @@ -139,14 +139,14 @@ _Static_assert(__builtin_choose_expr(__is_constexpr((lo) > (hi)), \ (lo) <= (hi), true), \ "clamp() low limit " #lo " greater than high limit " #hi); \ - _Static_assert(__types_ok(val, lo), "clamp() 'lo' signedness error"); \ - _Static_assert(__types_ok(val, hi), "clamp() 'hi' signedness error"); \ __clamp(__val_##uniq, __lo_##uniq, __hi_##uniq); }) -#define __careful_clamp(val, lo, hi, uniq) ({ \ +#define __careful_clamp(val, lo, hi, uniq) \ __builtin_choose_expr(__is_constexpr((val) - (lo) + (hi)), \ __clamp(val, lo, hi), \ - __clamp_once(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