Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp896838rbb; Sun, 25 Feb 2024 08:51:58 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW/knY9/iZxqKdVFlJ5qfyZecOk+hHkvmHXzfHKtCjyuyjZQWp6Y3IBxYAHcfnVkUP20CGQ0/22JP2QpdbDK5RCS31X6CdMiAyRgY5QhA== X-Google-Smtp-Source: AGHT+IH2v3MOSRF2x34/dpI6gsnc5TosubL6uj8oqeMhWO92m71QJ0CZuAtzvQkPmgMDzU0wA4gB X-Received: by 2002:a17:902:e810:b0:1dc:60c6:7eb9 with SMTP id u16-20020a170902e81000b001dc60c67eb9mr5017268plg.37.1708879918437; Sun, 25 Feb 2024 08:51:58 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708879918; cv=pass; d=google.com; s=arc-20160816; b=SUYfuIk5VT/3jt8BKVzNZwoD/0OXTC6CDp6aYfvf3gTahkkZCEP2hVnDQarQJjE7X8 WOc5TDOf7Bpfq9o8aqpIq9299IEMEJ+O7I+73YjJT6SfImsXcVnl5i6oaFFvMRVP/LGj 6H/vCXveKbeqK9WGTMVIXUbOnkCVIEb2RspDBFsJZb6hmqYZtukoDBTBoq17SC93iG7f l0Bclq/yLSOR73QoeEKlvwNncPAnw+phqso6hwD4YZt12SVROQOEF1yObjsQAOVfOWGD UurTn6KFJVVfNJISDyuNv2FWQxTvwINdsVgl/w14yPvti75usNWp1VtfS8qlHZ/9i41n uBug== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:content-language:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:accept-language :in-reply-to:references:message-id:date:thread-index:thread-topic :subject:cc:to:from; bh=PysfMx3M/lsua2xRsU2IKSFclTt0gXvP+r9VfwPa7io=; fh=nGE692sbVdRvha6RYbzMUXtm1nr/30sV7frdtDN2z14=; b=lgxRALj0rO93u+GEDPdmaU5TklXc1DL3tUBpEvEhb/yPXvMOfjnbKESNR4aSGgyW8d fanbb7ZygE8d3zPfiA9b+QMg5NCom3Q2g0qVXD+WuL+ZiZ+6IY9Eafeg+KWFf2G7QACr +9nEcGJqQIfObGPDDAOzhAhUI2rD1DolFNb8I2RyavkpOb0/OWjFO6LBa9K6ETlDbH3a plRkRbIo59wAZh5FXTEW0H/7ivQmE5c3U9T7VwBggBGKF8WKA6HSBpVbAzNYv+Mp2A8Y /ciS9AaFxexADcSfEm6+yLAEwtk4fTNrGqePiezw5X4VXyE/kyYaBSu461wY/KtKrbXY ntQg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=aculab.com dmarc=pass fromdomain=aculab.com); spf=pass (google.com: domain of linux-kernel+bounces-80213-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80213-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id u18-20020a170902e5d200b001dc56fed966si2356748plf.53.2024.02.25.08.51.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Feb 2024 08:51:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80213-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=aculab.com dmarc=pass fromdomain=aculab.com); spf=pass (google.com: domain of linux-kernel+bounces-80213-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80213-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 216392818F0 for ; Sun, 25 Feb 2024 16:51:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 602D1182D4; 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]) (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 3AA6817735 for ; Sun, 25 Feb 2024 16:51:43 +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=1708879905; cv=none; b=hxO4ZXZBiicvqEILlFbU0b9QSf53fu+fOPei0H2daabye2WFfbX2pnBWSY6xjrEx/ChqgmWC4w0FICq5+tkGvMy82rNf6l3A/Kwrq3WO5HuRxzAymqyHQ6m5Xhl2wybKDJESwbu4uMHUmlh+KxSmGOQzf0V6FptxnyA8Twh/G+k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708879905; c=relaxed/simple; bh=fdTN5Jl2KPnVZr1KBcvoZ0inLKUD64eRXNqOy4BklWQ=; h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To: MIME-Version:Content-Type; b=qsgBQ0V/AdLnMC35MeINSXHV35h2dV4HZiSGdJb2zSElI0HdCOZ9+fqVJQsN63SO5veQzk6HKtgoFxvh+J2nQuLV036jAZutru6CMUYveAZBbk8O5UzLhYDfijNgi45PzXKnZh9Tapn0U54BbxtoLsCPTKYRHLHs86bT2PwAXoU= 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-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 Precedence: bulk X-Mailing-List: linux-kernel@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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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) ({=09=09\ =09typeof(x) __x_##uniq =3D (x);=09=09\ =09typeof(y) __y_##uniq =3D (y);=09=09\ -=09_Static_assert(__types_ok(x, y),=09\ -=09=09#op "(" #x ", " #y ") signedness error, fix types or consider u" #op= "() before " #op "_t()"); \ =09__cmp(op, __x_##uniq, __y_##uniq); }) =20 #define __careful_cmp(op, x, y, uniq)=09=09=09=09\ =09__builtin_choose_expr(__is_constexpr((x) - (y)),=09\ =09=09__cmp(op, x, y),=09=09=09=09\ -=09=09__cmp_once(op, x, y, uniq)) +=09=09({ _Static_assert(__types_ok(x, y),=09=09\ +=09=09=09#op "(" #x ", " #y ") signedness error, fix types or consider u" = #op "() before " #op "_t()"); \ +=09=09__cmp_once(op, x, y, uniq); })) =20 /** * min - return minimum of two values of the same or compatible types @@ -139,14 +139,14 @@ =09_Static_assert(__builtin_choose_expr(__is_constexpr((lo) > (hi)),=09\ =09=09=09(lo) <=3D (hi), true),=09=09=09=09=09\ =09=09"clamp() low limit " #lo " greater than high limit " #hi);=09\ -=09_Static_assert(__types_ok(val, lo), "clamp() 'lo' signedness error");= =09\ -=09_Static_assert(__types_ok(val, hi), "clamp() 'hi' signedness error");= =09\ =09__clamp(__val_##uniq, __lo_##uniq, __hi_##uniq); }) =20 -#define __careful_clamp(val, lo, hi, uniq) ({=09=09=09=09\ +#define __careful_clamp(val, lo, hi, uniq)=09=09=09=09\ =09__builtin_choose_expr(__is_constexpr((val) - (lo) + (hi)),=09\ =09=09__clamp(val, lo, hi),=09=09=09=09=09\ -=09=09__clamp_once(val, lo, hi, uniq)); }) +=09=09({ _Static_assert(__types_ok(val, lo), "clamp() 'lo' signedness erro= r");=09\ +=09=09_Static_assert(__types_ok(val, hi), "clamp() 'hi' signedness error")= ;=09\ +=09=09__clamp_once(val, lo, hi, uniq); })) =20 /** * clamp - return a value clamped to a given range with strict typecheckin= g --=20 2.17.1 - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1= PT, UK Registration No: 1397386 (Wales)