Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp21444rdb; Sun, 28 Jan 2024 11:30:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IFF7Qr3qk0wXZM0ZaihPD662GvesCU2d/rJS+/Cce5KCYFB/njE5Hs0UDhj9YSGEAKd4Q+F X-Received: by 2002:a05:6a20:938e:b0:19c:95f6:f1bc with SMTP id x14-20020a056a20938e00b0019c95f6f1bcmr4392024pzh.58.1706470221938; Sun, 28 Jan 2024 11:30:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706470221; cv=pass; d=google.com; s=arc-20160816; b=CS6vLTaOhhYPSo9GyZd2vUavG+gA1CKUEbSy2cmq1AFYrJBod5DXH7s9DySHmejrnz ud/Ow3qXwzYpQohRG/s/z7zZaA6KBsCVBvzr5oyz0tJ8M8ew5I/m+R1jTjGwiiWjH88F i/ppPndQ/yvBu6y2X7c76seSlIgBkT0WyDAkCStwDG3tJLz31521chZvw1SWBU8EPsET c/Q2cbo2SQMks1RERiHJj8vsEHqAS0fQY51sqXC4f09yMjEJHx2+gXI32UYvE2QWwPSQ No9TUXa309XVDKFUnjKn8UYzHbkRcj0NfpOel9xf1ohUKCC4Q/JL1xODFN/3Dbrgb/av LjSg== 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=4e2UZ1tGQXCk5EFu6Hsli4NZhoNTUn8mG8QRjh03G2M=; fh=jAOu/RGlQxfhPk7PcGNzOfYLHKZO+STAaG1daOB/TAU=; b=WPbfh3hlFOCyVHO7iYqbESpmvzCkq7IrqzZrOT8CJ8EOCx7suyLn3YsYDiaCilyKOf 43ILz2DxPnkJx/OjCC4DHDUzsZpjHoma1jhb4PCA56AnR4QWgDwzlki3o7T29jPYCyzx qy+T5Z8+yVtwuQ98fjP6MZzkP9+OlZvcpqn5L4n731XjdEVPzKBnJV6FGHDiB25TPbQD RVlIQLkw7xg0bOp92MM87ASlPnfC7JhRQEqliu0E2ylnfbEZ1O9r2QJ0v3VJoYXre1Ns VaSx7s9YJ9elwQzsFAR4zRiTj8jmfSRlSYrrjSqwMdNklvt1qLSs3RUWLkVqfr7WFUD8 8sYQ== 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-41902-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-41902-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. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id k30-20020a63ba1e000000b005cecafd3c43si4477751pgf.218.2024.01.28.11.30.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Jan 2024 11:30:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-41902-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; 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-41902-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-41902-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 626E1282D3E for ; Sun, 28 Jan 2024 19:30:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 347B7328DB; Sun, 28 Jan 2024 19:30:16 +0000 (UTC) Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.86.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 097D631A66 for ; Sun, 28 Jan 2024 19:30:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.58.86.151 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706470215; cv=none; b=JnYLSHF1c5XMGYyniYVA8H+ZQHSME31k35fchq2ZbXzIzShkbXGMJsDQGc5PBA4qvN6W15hoemNZVXeby7lRwNd9J/FCG2BTehL6igKUPiFxAGnoTlgpC+aOyTjcrm7gQ32It6zBaZU1Ch6YSv9M6gYsFKLNHDJkdJTxhic1ODk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706470215; c=relaxed/simple; bh=h/Jo5w49YxsW6ApsWUJtLxw87C6r+AFIqrEgPftthiI=; h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To: MIME-Version:Content-Type; b=QO+hk8IY6moi7XBCJOv1fl31zG7j8Jz48n0ay7UeDORdntwZdIGz//wzLPhUJrudK6QwrZNokz9OkeUsngMfPMtl9jfYjcWOySE0EAmT51iJ9BbVGhtjQLenFKuD2+Kehf/rpChOdvUa9nbh000phBluB8HFnKZ3P6mMhvrZ92I= 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.86.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-287-f69A8d_oMo2hOZ4JNgzJSw-1; Sun, 28 Jan 2024 19:30:09 +0000 X-MC-Unique: f69A8d_oMo2hOZ4JNgzJSw-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, 28 Jan 2024 19:29:45 +0000 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Sun, 28 Jan 2024 19:29:45 +0000 From: David Laight To: "'linux-kernel@vger.kernel.org'" , "'Linus Torvalds'" , 'Netdev' , "'dri-devel@lists.freedesktop.org'" CC: 'Andy Shevchenko' , 'Andrew Morton' , "'Matthew Wilcox (Oracle)'" , 'Christoph Hellwig' , "'Dan Carpenter'" , 'Linus Walleij' , "'David S . Miller'" , "'linux-btrfs@vger.kernel.org'" , 'Jens Axboe' Subject: RE: [PATCH next 05/11] minmax: Move the signedness check out of __cmp_once() and __clamp_once() Thread-Topic: [PATCH next 05/11] minmax: Move the signedness check out of __cmp_once() and __clamp_once() Thread-Index: AdpSIGH+4MQss22qSoGjj8lEgu0knw== Date: Sun, 28 Jan 2024 19:29:45 +0000 Message-ID: References: <0ca26166dd2a4ff5a674b84704ff1517@AcuMS.aculab.com> In-Reply-To: <0ca26166dd2a4ff5a674b84704ff1517@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(-) 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)