From patchwork Sun Feb 25 16:49:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Laight X-Patchwork-Id: 206090 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1656590dyb; Sun, 25 Feb 2024 08:49:39 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUjT0og53IBSw414zTSW2CZmOGUd82eu4kd1ZVSqi5AS0yXB9km+AsJ7bkgXxPY4rMCgXnemBIUh0h8PwkU28hmq80K3A== X-Google-Smtp-Source: AGHT+IFDB1ZF9qO6MyicHOkVMxuFTJ7ijFBPxFpuALxwbVstfWoIgucetjddlmkWM5ldKguOlDXc X-Received: by 2002:a05:6402:1607:b0:564:71:ccf0 with SMTP id f7-20020a056402160700b005640071ccf0mr3325519edv.2.1708879779183; Sun, 25 Feb 2024 08:49:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708879779; cv=pass; d=google.com; s=arc-20160816; b=BHj1nfyiTkzYsOhBoUyv462vpomdd/pT5fqYWVL43/GdQf07SHd2gM8CnLiBmfhBhV DtnCwz2fHHSuK+OZgQGS0VjCpR7otfSgNnOuAFKS+37DjCRCCZP3GFXeeMNPvym9aHru m/rxUY4BbMiNoktMfDsEYDNe4lf6iqduKaFA0C/1cao5UcSzAnrWMOmcSHiWEVZbQk9a z+lQN53ICeSl4++WWT8IQQw8QfvuGQKXty2kv5uPBchiVQUewjX9c/GS9y3VJoJCYXaM JKYG8irqk3byzECVz1n0vANEFrJ0gwG/FX41pyQ4ouuCPhf7sichgb5ZkVYya+0HH3KE Oz3g== 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=C3LKmkJkN8dkZ0RHNjijjC6uoAGGE0xrQwkKifLFDjY=; fh=nGE692sbVdRvha6RYbzMUXtm1nr/30sV7frdtDN2z14=; b=W9OZoznk4+vsB/oXbrBL02QFc26saYcso9kmtn7l6t4jpfGjfcpZDB1dCHjSM+yKHX pwuKsoGI2Jg8n8xsBUBpjge7h2QyT1hQx4XfRvoCjD1Om3EkB5BaH4JHNtZ1i8erkxsU StzdaZ6wi16LWhyaui4NbqCmswfiF22B1VODnEQ2mwYklafBHHQMiul3EJl5jelyobD0 ovUGpFEUvsgNmI8LTFUxJapDC5rnxRUOULZhRp+/vosOzlCWLLvOv8898v11Jg+tAm4F dJxKHSFSbnK3W2NSLcok817ZFTFKaKp/k0HziOhWjc4BQ1mq66UqHWp3gcVICbm1X288 JuHw==; 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-80210-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80210-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id u29-20020a50c05d000000b0056568fe52eesi1335110edd.565.2024.02.25.08.49.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Feb 2024 08:49:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80210-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; 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-80210-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80210-ouuuleilei=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 am.mirrors.kernel.org (Postfix) with ESMTPS id CA6C21F21403 for ; Sun, 25 Feb 2024 16:49:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3DA1C18B1A; Sun, 25 Feb 2024 16:49:18 +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 E6F1817BB4 for ; Sun, 25 Feb 2024 16:49:14 +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=1708879756; cv=none; b=YhFVnCO1KG4SfpOkaFiyXo6SbWf7/McgetMCsy/LeF/fE3HrNDCCJeLwWJgipYzDSo9qqH9hQGPkEkZpdIZVGuRdImKUM9G9VZAkeht6QAvmcxTqvK8W9pIWKeGxKQK5gc7GbrXYqAxxe0mTlYnHOOgzOcdvRh4wXOwcB8zPbtA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708879756; c=relaxed/simple; bh=8ye8TjxJr7Qpfxmc8F8Nww5LIwfQZHhRr6Lbkiz0KUc=; h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To: MIME-Version:Content-Type; b=FD3/YCHf1VYBsHaK3/U/wD9/GlO1iT9k3yxql8h62cl0T5XwggnJOPTFu4/hm7Q198NSEkfk2O1MYUh4SNum1ElmcL3PBb04GBwwboCXO4iZEmNIM1PBj84oyXAbJ1OFJnhWWiIoWqO2MARt07kxFIi2FM3mSxXzlQ0OpJWTZNs= 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-198-BfGlJeiVOxaAMdciN2scyQ-1; Sun, 25 Feb 2024 16:49:11 +0000 X-MC-Unique: BfGlJeiVOxaAMdciN2scyQ-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:49:10 +0000 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Sun, 25 Feb 2024 16:49:10 +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 02/11] minmax: Use _Static_assert() instead of static_assert() Thread-Topic: [PATCH next v2 02/11] minmax: Use _Static_assert() instead of static_assert() Thread-Index: AdpoComWnYboZopTTWeIFfAWCv2rOw== Date: Sun, 25 Feb 2024 16:49:10 +0000 Message-ID: <8059bc04da1a45bc810ac339a1129a4c@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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791890323156389268 X-GMAIL-MSGID: 1791890323156389268 The wrapper just adds two more lines of error output when the test fails. Signed-off-by: David Laight --- include/linux/minmax.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 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 63c45865b48a..900eec7a28e5 100644 --- a/include/linux/minmax.h +++ b/include/linux/minmax.h @@ -48,7 +48,7 @@ #define __cmp_once(op, x, y, unique_x, unique_y) ({ \ typeof(x) unique_x = (x); \ typeof(y) unique_y = (y); \ - static_assert(__types_ok(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); }) @@ -137,11 +137,11 @@ typeof(val) unique_val = (val); \ typeof(lo) unique_lo = (lo); \ typeof(hi) unique_hi = (hi); \ - static_assert(__builtin_choose_expr(__is_constexpr((lo) > (hi)), \ + _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"); \ + _Static_assert(__types_ok(val, lo), "clamp() 'lo' signedness error"); \ + _Static_assert(__types_ok(val, hi), "clamp() 'hi' signedness error"); \ __clamp(unique_val, unique_lo, unique_hi); }) #define __careful_clamp(val, lo, hi) ({ \ From patchwork Sun Feb 25 16:49:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Laight X-Patchwork-Id: 206091 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1656879dyb; Sun, 25 Feb 2024 08:50:29 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUOOzMNREV9Lhz8bXoz/QOEKdoxIBGmKDlfguew+OVTLXaHl3GZ0j63fARKtQ5VZhPdxB7vEgfPfcJtahRwfNM1Oy9jNA== X-Google-Smtp-Source: AGHT+IEO47544gzhsEzSEH94A8c6B8fk9Ts9hMe7cHOlwMJ5vJVySHVUjP/ABDA+5jE7xfwp0oTC X-Received: by 2002:a17:906:3618:b0:a3e:55e6:35db with SMTP id q24-20020a170906361800b00a3e55e635dbmr3318102ejb.45.1708879829241; Sun, 25 Feb 2024 08:50:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708879829; cv=pass; d=google.com; s=arc-20160816; b=dxJ3+U4FkEYnUSoAW3Mdt/xphiWxIfMxd+btSsQQEveLDeBj2MZTxSVL+lC58hZ53q ccvq3yMcOX63S4KXiSg4YX28VxJyhDwtxBHs5oQHpe1gu6ZhiOYY4I2KUWQlNOFLh4Gn Lh9rwjT5O2ePAHDXLnMmjtV/USvuLpo5N1c97h18Bvr+rvXeeGpJh/nNJPbVdhk2mJQK TLkSj86DbiS5n/wzikOyMxjh3wxoqP/x5OmAKWgWnSdSZ1Ksm/jp49ce9juxDeVM9cxn jCjGAlBweNHtb0ZOrWacWbNfbUOO5TjVgVbysY/IZ1pxVy/WmTuo3cLze8+sGkVTPlpp tYkg== 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=Tl95No0Gjei3R+OvX6WRb5W/BRSAwiJ28HXr42thZUg=; fh=nGE692sbVdRvha6RYbzMUXtm1nr/30sV7frdtDN2z14=; b=lm5r9wNv8gxGILBJ1WQQrI5WskdoyXQN9q7cKSFkVuE+pOnr4PY/Ypkk7mellNZM8F T2s3Pt7yW5EbPS0wU7+txTFM+HJyvgMWShZwPG/MwfNDEYnr4UCSqaai4bh2VSCupolK moZjQur8kH25kLCYvcKHsUnizjoJRVShN9l21nrdmDPaS9XSVSSwGzP5KB5xfoG5bVJf IF5OaYTDxZFlq/WWnC5WlJX/0LDM2JV/0PGdX3LEYJH/EDMILq10jMY1sIbVfjMwIchw To2rRPHDY3qwzJzt6GhZB+2xOff+2rzxVF2DrGEv8dfhMgs4uCGgpQfVER2m17sl2GJ5 zkQw==; 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-80211-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80211-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id z13-20020a1709063acd00b00a3e5053186dsi1353315ejd.206.2024.02.25.08.50.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Feb 2024 08:50:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80211-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; 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-80211-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80211-ouuuleilei=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 am.mirrors.kernel.org (Postfix) with ESMTPS id D89091F21A8E for ; Sun, 25 Feb 2024 16:50:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A3E23199B8; Sun, 25 Feb 2024 16:50:07 +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 7A45D14006 for ; Sun, 25 Feb 2024 16:50:04 +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=1708879806; cv=none; b=FzPzRN9LoVNGe14IMTPG/uEiF5Y1gLsilVTa65TriPzoeMPen42+CDbqzr9JFTIR3ElIEW/ayx50ESEVMLXt4JvbyL8D4mkJBtwGiSHkg7jcAP1CM2/TfC7d1qrkE4yIifNZQ1cqMBoIRPSRwdjaWgr4/TvmG2wGiuwxkIZtxt8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708879806; c=relaxed/simple; bh=URi7AE+I5CngHeVQukg72Q07R1uxCOMsGMofCc3A+30=; h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To: MIME-Version:Content-Type; b=blEsXP66cBYuRUbt7a+Mf0k6IjsUDHr84WT5921wPD4xgN2LBH3MY2Njdd+LZOA/YVl23Lw+tnvfDovE03WnBVZ3sXJlNdZ/VMpV2dsCObJdFzjcUrNtdcZmaEC/zAEREpm+Leych5tpCdLDDfmET2zc/r8g3nMgkoyZ93ZwgGs= 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-43-W8RGFR3EPR-AcuGUd8JL4Q-1; Sun, 25 Feb 2024 16:50:00 +0000 X-MC-Unique: W8RGFR3EPR-AcuGUd8JL4Q-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:49:59 +0000 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Sun, 25 Feb 2024 16:49:59 +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 03/11] minmax: Simplify signedness check Thread-Topic: [PATCH next v2 03/11] minmax: Simplify signedness check Thread-Index: AdpoCqfCgp/0gHjwSqumBl0qZkMqdg== Date: Sun, 25 Feb 2024 16:49:59 +0000 Message-ID: <8657dd5c2264456f8a005520a3b90e2b@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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791890375689695338 X-GMAIL-MSGID: 1791890375689695338 It is enough to check that both 'x' and 'y' are valid for either a signed compare or an unsigned compare. For unsigned they must be an unsigned type or a positive constant. For signed they must be signed after unsigned char/short are promoted. The predicate for _Static_assert() only needs to be a compile-time constant not a constant integeger expression. In particular the short-circuit evaluation of || && ?: can be used to avoid the non-constantness of (pointer_type)1 in is_signed_type(). The '+ 0' in '(x) + 0 > = 0' is there to convert 'bool' to 'int' and avoid a compiler warning because max() gets used for 'bool' in one place (a very expensive 'or'). (The code is optimised away by two earlier checks - but the compiler still bleats.) Signed-off-by: David Laight --- include/linux/minmax.h | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 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 900eec7a28e5..c32b4b40ce01 100644 --- a/include/linux/minmax.h +++ b/include/linux/minmax.h @@ -8,7 +8,7 @@ #include /* - * min()/max()/clamp() macros must accomplish three things: + * min()/max()/clamp() macros must accomplish several things: * * - Avoid multiple evaluations of the arguments (so side-effects like * "x++" happen only once) when non-constant. @@ -26,19 +26,17 @@ #define __typecheck(x, y) \ (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1))) -/* is_signed_type() isn't a constexpr for pointer types */ -#define __is_signed(x) \ - __builtin_choose_expr(__is_constexpr(is_signed_type(typeof(x))), \ - is_signed_type(typeof(x)), 0) +/* Allow unsigned compares against non-negative signed constants. */ +#define __is_ok_unsigned(x) \ + (is_unsigned_type(typeof(x)) || (__is_constexpr(x) ? (x) + 0 >= 0 : 0)) -/* True for a non-negative signed int constant */ -#define __is_noneg_int(x) \ - (__builtin_choose_expr(__is_constexpr(x) && __is_signed(x), x, -1) >= 0) +/* Check for signed after promoting unsigned char/short to int */ +#define __is_ok_signed(x) is_signed_type(typeof((x) + 0)) -#define __types_ok(x, y) \ - (__is_signed(x) == __is_signed(y) || \ - __is_signed((x) + 0) == __is_signed((y) + 0) || \ - __is_noneg_int(x) || __is_noneg_int(y)) +/* Allow if both x and y are valid for either signed or unsigned compares. */ +#define __types_ok(x, y) \ + ((__is_ok_signed(x) && __is_ok_signed(y)) || \ + (__is_ok_unsigned(x) && __is_ok_unsigned(y))) #define __cmp_op_min < #define __cmp_op_max > From patchwork Sun Feb 25 16:50:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Laight X-Patchwork-Id: 206092 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1657142dyb; Sun, 25 Feb 2024 08:51:19 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWfIguzj4qly7KlUWsdQBsT3XT5DnqxU9E9B3qGnosUvnnIvnoJfEH2szQVP7xsaRO6Ct9yObKY70yU941SqUkm5Mu7LQ== X-Google-Smtp-Source: AGHT+IFuKAnpLUw+FhK+HWa/+5q1gaubj5XfXHIKxRMfpYRl3KfK5MuhDwmyVHmO3SchL0p3DG30 X-Received: by 2002:a05:620a:2a12:b0:787:caee:4309 with SMTP id o18-20020a05620a2a1200b00787caee4309mr3196874qkp.31.1708879878871; Sun, 25 Feb 2024 08:51:18 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708879878; cv=pass; d=google.com; s=arc-20160816; b=KttschBkeCGqQFI2zZy2rqw3mxa6ylcKBaPkPV5Ii6L5DUUku4WkAE0DAKh/lgwxyq CiwlFIYE5X38W3zwytIHkgOHT22PZcztJjHzU7XRXytXxMSviphRFjcg5K6Nq1OsK5W7 4z7Ysud4InTs+JybOnpo/y0dXMVmGznC5KPpQgHi5tClbcaJmt+63TkZhS/asGwwOdSx 3YZgNAVFWg2JDidlcGrGrzAo7WAhwOVizO76TCMj7bAN9gF4WVbtbvBctdQVOFVEIgnK TprOxG3n8Wm9qdmKvvk9Bz5qGUGuy5YJxVlvBZutbp+1p/xekBUqSL7Wi3Y9qo8mtXaf cDkQ== 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=+lOMyrz3Pc3RSh+srEYELe1hGEgmgpaasYGAX0sPieA=; fh=nGE692sbVdRvha6RYbzMUXtm1nr/30sV7frdtDN2z14=; b=lfBUx6rEZdNDfSkAstq+X47BI5NZPMNvL/xm6jTyw/nlCmW3IFmoUzhkYO6fpouG5U WGnudO2qMRjEW+UeuKULAcb/D6/H7z1UaM7M3wV3y9J6YENprS0U7sOkjwYOOtZKogA9 ZG9Z6ujtgdJI/BLNQzKPY7c+6ZlLZML4fCuwryLLbOks1BhMadEAZVqwxiAah+zxfG84 XxC1SmUMz5sqCrCdHLsmKJp2XoLFneF+k3DuvOyBRtkBEFmIVUeKoQBIENY5RtjajsRG ZroO8Jb5thSpfQjBEzk5aQCkLzBZWT91gD8kP+9mwFHO9dGq+FPPG0gwYzQxDc3i4pcw R7/g==; 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-80212-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80212-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id i7-20020a37c207000000b00787c0e79d2dsi3387693qkm.572.2024.02.25.08.51.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Feb 2024 08:51:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80212-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::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-80212-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80212-ouuuleilei=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 9A84B1C2112F for ; Sun, 25 Feb 2024 16:51:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D1CF9199B8; Sun, 25 Feb 2024 16:50:56 +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 EF54379D3 for ; Sun, 25 Feb 2024 16:50:51 +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=1708879854; cv=none; b=bn2Pc5xRj/vaCKT9ttr8qkXVmoESE843s+5PfEKBWNnBYO6wiKrkJlrwGvv5Kjnl/XEjS3jWxqQmZfydym8oe70sPO1CTNayvoqAjaAfVgcAg6iuogGTbP7hIE5kAbafTFXJKiBzgnVBNHFem4rgcipjIxU7ivhuoem+8fV7Z68= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708879854; c=relaxed/simple; bh=+atgDbr45v2v/fK8FAQruXtzObgP16hiBnUi3W5GHsA=; h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To: MIME-Version:Content-Type; b=I8OqGg3kEWdl0LWSiWRL86+DH6uBOAaLMgJSj1ipEbC0068e9dvOUYb9n3vvdnFxJHYJP6zu1SrL+cgkMBRkt32iFLNtC4CtZVUdCNDqsFCdki+VUYNBj85uTenjEb2GOBzbNn5PIviU6TLhCk26GrHgaf/ZJFiGap/ho9TN3YI= 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-262-6W1dHPmgNxKn61PI8Ye6Yg-1; Sun, 25 Feb 2024 16:50:48 +0000 X-MC-Unique: 6W1dHPmgNxKn61PI8Ye6Yg-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:50:47 +0000 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Sun, 25 Feb 2024 16:50:47 +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 04/11] minmax: Replace multiple __UNIQUE_ID() by directly using __COUNTER__ Thread-Topic: [PATCH next v2 04/11] minmax: Replace multiple __UNIQUE_ID() by directly using __COUNTER__ Thread-Index: AdpoCsQOvIgG9TyzTYmUjuthkRVCRw== Date: Sun, 25 Feb 2024 16:50:47 +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-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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791890427815977736 X-GMAIL-MSGID: 1791890427815977736 Provided __COUNTER__ is passed through an extra #define it can be pasted onto multiple local variables to give unique names. This saves having 3 __UNIQUE_ID() for #defines with three locals and look less messy in general. Stop the umin()/umax() lines being overlong by factoring out the zero-extension logic. Signed-off-by: David Laight --- include/linux/minmax.h | 48 +++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 24 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 c32b4b40ce01..8ee003d8abaf 100644 --- a/include/linux/minmax.h +++ b/include/linux/minmax.h @@ -8,7 +8,7 @@ #include /* - * min()/max()/clamp() macros must accomplish several things: + * min()/max()/clamp() macros must accomplish three things: * * - Avoid multiple evaluations of the arguments (so side-effects like * "x++" happen only once) when non-constant. @@ -43,31 +43,31 @@ #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); \ - _Static_assert(__types_ok(x, y), \ +#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, unique_x, unique_y); }) + __cmp(op, __x_##uniq, __y_##uniq); }) -#define __careful_cmp(op, x, y) \ +#define __careful_cmp(op, x, y, uniq) \ __builtin_choose_expr(__is_constexpr((x) - (y)), \ __cmp(op, x, y), \ - __cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y))) + __cmp_once(op, x, y, uniq)) /** * min - return minimum of two values of the same or compatible types * @x: first value * @y: second value */ -#define min(x, y) __careful_cmp(min, x, y) +#define min(x, y) __careful_cmp(min, x, y, __COUNTER__) /** * max - return maximum of two values of the same or compatible types * @x: first value * @y: second value */ -#define max(x, y) __careful_cmp(max, x, y) +#define max(x, y) __careful_cmp(max, x, y, __COUNTER__) /** * umin - return minimum of two non-negative values @@ -75,8 +75,9 @@ * @x: first value * @y: second value */ +#define __zero_extend(x) ((x) + 0u + 0ul + 0ull) #define umin(x, y) \ - __careful_cmp(min, (x) + 0u + 0ul + 0ull, (y) + 0u + 0ul + 0ull) + __careful_cmp(min, __zero_extend(x), _zero_extend(y), __COUNTER__) /** * umax - return maximum of two non-negative values @@ -84,7 +85,7 @@ * @y: second value */ #define umax(x, y) \ - __careful_cmp(max, (x) + 0u + 0ul + 0ull, (y) + 0u + 0ul + 0ull) + __careful_cmp(max, __zero_extend(x), _zero_extend(y), __COUNTER__) /** * min3 - return minimum of three values @@ -108,7 +109,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) __careful_cmp(min, (type)(x), (type)(y), __COUNTER__) /** * max_t - return maximum of two values, using the specified type @@ -116,7 +117,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) __careful_cmp(max, (type)(x), (type)(y), __COUNTER__) /** * min_not_zero - return the minimum that is _not_ zero, unless both are zero @@ -131,22 +132,21 @@ #define __clamp(val, lo, hi) \ ((val) >= (hi) ? (hi) : ((val) <= (lo) ? (lo) : (val))) -#define __clamp_once(val, lo, hi, unique_val, unique_lo, unique_hi) ({ \ - typeof(val) unique_val = (val); \ - typeof(lo) unique_lo = (lo); \ - typeof(hi) unique_hi = (hi); \ +#define __clamp_once(val, lo, hi, uniq) ({ \ + typeof(val) __val_##uniq = (val); \ + typeof(lo) __lo_##uniq = (lo); \ + typeof(hi) __hi_##uniq = (hi); \ _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(unique_val, unique_lo, unique_hi); }) + __clamp(__val_##uniq, __lo_##uniq, __hi_##uniq); }) -#define __careful_clamp(val, lo, hi) ({ \ +#define __careful_clamp(val, lo, hi, uniq) ({ \ __builtin_choose_expr(__is_constexpr((val) - (lo) + (hi)), \ __clamp(val, lo, hi), \ - __clamp_once(val, lo, hi, __UNIQUE_ID(__val), \ - __UNIQUE_ID(__lo), __UNIQUE_ID(__hi))); }) + __clamp_once(val, lo, hi, uniq)); }) /** * clamp - return a value clamped to a given range with strict typechecking @@ -156,7 +156,7 @@ * * This macro checks that @val, @lo and @hi have the same signedness. */ -#define clamp(val, lo, hi) __careful_clamp(val, lo, hi) +#define clamp(val, lo, hi) __careful_clamp(val, lo, hi, __COUNTER__) /** * clamp_t - return a value clamped to a given range using a given type @@ -168,7 +168,7 @@ * This macro does no typechecking and uses temporary variables of type * @type to make all the comparisons. */ -#define clamp_t(type, val, lo, hi) __careful_clamp((type)(val), (type)(lo), (type)(hi)) +#define clamp_t(type, val, lo, hi) clamp((type)(val), (type)(lo), (type)(hi)) /** * clamp_val - return a value clamped to a given range using val's type 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: 206093 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1657368dyb; Sun, 25 Feb 2024 08:52:08 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX2qvzqAelCHv4pNvllhHQHO4WX2oaZ1aMzksq7d9wzCDte5uuTvMXhYGtlDghcQzoHLGf4ckW2CNvzyKT3lRWbwx2cEg== X-Google-Smtp-Source: AGHT+IG5K6ALasBnoH8eaJhJjBYXxCn9AzB8N+KmOAgXK9VK3EqV8NCs1u/iwC7C0y6dA5rnAiBi X-Received: by 2002:a05:6a00:4f84:b0:6e5:30d1:dd33 with SMTP id ld4-20020a056a004f8400b006e530d1dd33mr239095pfb.21.1708879928232; Sun, 25 Feb 2024 08:52:08 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708879928; cv=pass; d=google.com; s=arc-20160816; b=o6WodLJbk1kQBmCS+HVXmZibEJaRypUDFmAGdgPXvFLxf+xG41uFjm2ZZ+MjEnoiIi bio9I5gKJuiFYeXpNJeovw3ce/CGx0ekjrnuapAIa2xpVuuIOgdn2VXyWX/g2rsfxnCx SBG4qZp/HzbperMdqnxqg4qjjxax8foEajdR6m0mQ6cgZGrodtgDB+rtzKXsTH73v75e cYHSezWe/iF+WgZpSL7yRyVPXyQcP8J2apFuDrVMMK5Q3cSfSr6LyBKhLM81tTnAa4gn hzYuSHAVufucM7B9/hekRFc3vTQJEAWEUNA2H9UX2GxGzjkzWTiWlHKyYzdoLMJS07vZ t8tQ== 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-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80213-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id s16-20020a056a00179000b006e4be8d1a22si2416391pfg.144.2024.02.25.08.52.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Feb 2024 08:52:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80213-ouuuleilei=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-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80213-ouuuleilei=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 12078281AC5 for ; Sun, 25 Feb 2024 16:52:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 64893199B8; Sun, 25 Feb 2024 16:51:47 +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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791890479200598263 X-GMAIL-MSGID: 1791890479200598263 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 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: 206094 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1657584dyb; Sun, 25 Feb 2024 08:52:51 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXwyyHr7OQluKbDSj8C+0q2htcCE/OI6lg3CGvqYUUd94JiigPqX/wDPLFY9TfmDSZuqFViSGBiz+LTh4JcTm4aEl/e9g== X-Google-Smtp-Source: AGHT+IFk2KSjyZ5ROBtfGJMV7GnuGG52VshGJEVjJvFBj1iPG3ofLh5EH5qWyvpckZhfvrDxW7Fi X-Received: by 2002:a05:6214:daa:b0:68f:359a:896e with SMTP id h10-20020a0562140daa00b0068f359a896emr7006543qvh.12.1708879971778; Sun, 25 Feb 2024 08:52:51 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708879971; cv=pass; d=google.com; s=arc-20160816; b=CpXDu2IwNADP2pOcIw7jAFcQQjdwyzut+XGzNpmNXsIfy6mSo9MGn2aITOIsvvnQLi Y7zuryqTC12C7sXPAg8ZO910TEeokKC5HqK9RZKowijnw88YkP/Bw9CjYKpCjOBDGdQV j3GZhl/ltBjL73LFm5a1ngVfEpzw+j1iusa9BghDpFmAYat84YOAyh1PlZVYxQGpCBA1 bNt0KRgZdJWydWvf3CQIu/l4vnBqcaiqcnql2oliSRsXM+qv5HMG6QYTx5NL27Zp7lof BIoP1Vl21xI8oaW1tg9v9QzzHEh5DfMmaB5dI9nHCciX675WIlaQUyZERRCm6FDlmm2h qrSg== 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=p1h/WKmE5TF4FCWJPfWjd31PeI+Z8RvU39ecIF5kChM=; fh=nGE692sbVdRvha6RYbzMUXtm1nr/30sV7frdtDN2z14=; b=yDESht/dOYE2ZwJbZYsA85Vijh52PwzLkAQBAJLMmEdH2CglMM1t3wp61kQ8H3Pj5H tb7nmHnKoLGNoj+9Ezm7UAoAE0X8uz4W7xX4UrjJvWUIGLO9S6/ZIH5k0m0vRPTb2NAM tTg2cTB/x51T4MFIjB5MT/zKEuFsKYpmzC+U6RUPohc18wZoZCfRzvnwazX5ds0bKLGa ipICITbOPEwXKYPyvmoPOJLSR14SNZn2y4l3zj1LscqECvT6QuNnboRwwhNt9WL/QjCu CHHFLcwA83OX+FHurelG9phsq2YURLrzrygbY+VGcK1+tpT77Wypbs/d14/+uI9cmvP6 aJvQ==; 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-80215-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80215-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 3-20020a05621420a300b0068f8b9e1ad4si3337884qvd.388.2024.02.25.08.52.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Feb 2024 08:52:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80215-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::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-80215-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80215-ouuuleilei=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 912B81C20402 for ; Sun, 25 Feb 2024 16:52:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2D4AB1A27E; Sun, 25 Feb 2024 16:52:32 +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 6CE5717BC2 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-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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791890525240965219 X-GMAIL-MSGID: 1791890525240965219 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 From patchwork Sun Feb 25 16:53:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Laight X-Patchwork-Id: 206095 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1657782dyb; Sun, 25 Feb 2024 08:53:33 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX7MjJE4/BGbLgeAEmJwDg0HEKM6gWDOZ/dNF63JIr/F0smHDcuHR2DK6xVxoC+doG4MqF+Pba79kmfKzC52pr7otw1iA== X-Google-Smtp-Source: AGHT+IEGJnpP9/5J2c/kCZJOZF/1opFArbnTBWr8XdONBOg1H6qdnhaiENJli5Cn7Nyrm2B0v+cw X-Received: by 2002:a17:906:3411:b0:a43:1415:2f1e with SMTP id c17-20020a170906341100b00a4314152f1emr1527190ejb.69.1708880013358; Sun, 25 Feb 2024 08:53:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708880013; cv=pass; d=google.com; s=arc-20160816; b=YyXxqG/JRvVhcZ3Cacp4890j2cUyL0fkuEuVlMCgmaBoksJc/u794wCkj8K2GfVfCg lY5SK9jlq4RekH6Evqc3MHR5glUfvPA/YCyiYdRkseOGEtsJBcRDdckqAwRxON1ZBhyA K/OTSyTmtQXTAjfrf+Z0jwwM6gU0qkfPjqNfUJ/Gk15sZHF04cDRI6vDBhZLrUIJZ2XR SZb9zSJeL+1eTG1E2W1+SMg6syELS7HmiSWNDibMzScIMlCZjOlBc1TsUb2/tMk0KRIk kvIkiwwDkuxQ0UTUl4AxW5yqEOoko5OzW7Gj4mcqEGwLEuWTcoQGzxr/cl+8E60KIljC FlVQ== 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=E2uR/kIA1sSyBwch0S3wiEnZ2YjEle8TjIPSX/UDRjY=; fh=nGE692sbVdRvha6RYbzMUXtm1nr/30sV7frdtDN2z14=; b=GSLEPybM2fekhd1MHdYVJmErsZbVIsD3iCvCauiKiRm7dXbrOh0IrSt9+lFLHwXU7Y d0o6JOsCqRN3q2NoPJplbn24Wvb4qv4XVnOBfasCg0mKn3T3/qHdDga8WkjtYqnMO1HV BT1Ae7lggP2QgLrlYUpNe8Gt+0o4mEm90bvNisWfGsw8T0tuWXoAYlvG9zJcePTDjRB2 84rZOpxscT2sgtHf+XSKPTXucJMfwzRl62knfSqOstkyAY2skExKUnXOZ9Ax/ayQG21Q e5ztzz0U7ToskKgX8hfhxn6OQSgxIoCAzfMvHjUsgaJsxcwaa+tcReYfNmrcw1soPv/N 6Q2A==; 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-80216-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80216-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id r21-20020a170906365500b00a42f385aed9si1251447ejb.561.2024.02.25.08.53.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Feb 2024 08:53:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80216-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; 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-80216-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80216-ouuuleilei=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 am.mirrors.kernel.org (Postfix) with ESMTPS id CBA721F2163E for ; Sun, 25 Feb 2024 16:53:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 230521AAA5; Sun, 25 Feb 2024 16:53:12 +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 14A6D17BD4 for ; Sun, 25 Feb 2024 16:53:07 +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=1708879990; cv=none; b=koGTeg7itJeDGJ4I4YsDciiaoCX6eiYX7w9TUIVb2YBIzd+34BdhS5qo3hoTvv7ppB6bclrSCO3q/leNPn5os1hymgECF9PGrlAV1LJnG9ub8wPHOpTwBwcKTxO0BM17BnkzRZyY7fpATfXpWbHpRA5hrKtBY7w5a1ug1cyClvk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708879990; c=relaxed/simple; bh=KLXPJ9GI3IiXMwtDo1lDQylD+73wL23r9MozaWaBREk=; h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To: MIME-Version:Content-Type; b=Ta+cCKTjPyqilkIn5fOREZtWQ/rzb4WCLuypt7RsrYhQ/UD/7THTT5qEFQwrUITdR8e43XJp/Gc9xMkLKIwsQq8h5IU3Tnkg2OHOKnpUdWPHEKFL8Sgv1v0nUkPKB9pFJ5dUCoR86fVMr8bes1jcP7YI4Qwj8ljqC2Bk+eWGQuQ= 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-274-USz1BRr9PyCo79CglO0c6g-1; Sun, 25 Feb 2024 16:53:04 +0000 X-MC-Unique: USz1BRr9PyCo79CglO0c6g-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:53:03 +0000 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Sun, 25 Feb 2024 16:53:03 +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 07/11] minmax: minmax: Add __types_ok3() and optimise defines with 3 arguments Thread-Topic: [PATCH next v2 07/11] minmax: minmax: Add __types_ok3() and optimise defines with 3 arguments Thread-Index: AdpoCxYgUiRnRfJCT+mB8NVd2q416Q== Date: Sun, 25 Feb 2024 16:53:03 +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-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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791890569176660579 X-GMAIL-MSGID: 1791890569176660579 min3() and max3() were added to optimise nested min(x, min(y, z)) sequences, but only moved where the expansion was requiested. Add a separate implementation for 3 argument calls. These are never required to generate constant expressions to remove that logic. Signed-off-by: David Laight --- include/linux/minmax.h | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 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 5c7fce76abe5..278a390b8a4c 100644 --- a/include/linux/minmax.h +++ b/include/linux/minmax.h @@ -38,6 +38,11 @@ ((__is_ok_signed(x) && __is_ok_signed(y)) || \ (__is_ok_unsigned(x) && __is_ok_unsigned(y))) +/* Check three values for min3(), max3() and clamp() */ +#define __types_ok3(x, y, z) \ + ((__is_ok_signed(x) && __is_ok_signed(y) && __is_ok_signed(z)) || \ + (__is_ok_unsigned(x) && __is_ok_unsigned(y) && __is_ok_unsigned(z))) + #define __cmp_op_min < #define __cmp_op_max > @@ -87,13 +92,24 @@ #define umax(x, y) \ __careful_cmp(max, __zero_extend(x), _zero_extend(y), __COUNTER__) +#define __cmp_once3(op, x, y, z, uniq) ({ \ + typeof(x) __x_##uniq = (x); \ + typeof(x) __y_##uniq = (y); \ + typeof(x) __z_##uniq = (z); \ + __cmp(op, __cmp(op, __x_##uniq, __y_##uniq), __z_##uniq); }) + +#define __careful_cmp3(op, x, y, z, uniq) ({ \ + static_assert(__types_ok3(x, y, z), \ + #op "3(" #x ", " #y ", " #z ") signedness error"); \ + __cmp_once3(op, x, y, z, uniq); }) + /** * min3 - return minimum of three values * @x: first value * @y: second value * @z: third value */ -#define min3(x, y, z) min((typeof(x))min(x, y), z) +#define min3(x, y, z) __careful_cmp3(min, x, y, z, __COUNTER__) /** * max3 - return maximum of three values @@ -101,7 +117,7 @@ * @y: second value * @z: third value */ -#define max3(x, y, z) max((typeof(x))max(x, y), z) +#define max3(x, y, z) __careful_cmp3(max, x, y, z, __COUNTER__) /** * min_t - return minimum of two values, using the specified type @@ -142,8 +158,7 @@ __clamp(__val_##uniq, __lo_##uniq, __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"); \ + _Static_assert(__types_ok3(val, lo, hi), "clamp() signedness error"); \ __clamp_once(val, lo, hi, uniq); }) /** From patchwork Sun Feb 25 16:53:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Laight X-Patchwork-Id: 206096 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1657977dyb; Sun, 25 Feb 2024 08:54:06 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV+TYOZ0UUxSdyAQ3qxpKgwRxusquZwbR92G3tKsNrHeoM5OUtvVUZsJGqmEQ5APsuzXuwysY425I8oW0eMm42UbsyX5w== X-Google-Smtp-Source: AGHT+IHOJAGb/8pK4YK677rj3CZLT8VxUmvX0zej5tqNpFcgxClHHCWtIdGfdxAEbjlEAqJurCyw X-Received: by 2002:a50:ed98:0:b0:565:dce3:66f6 with SMTP id h24-20020a50ed98000000b00565dce366f6mr936985edr.39.1708880046400; Sun, 25 Feb 2024 08:54:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708880046; cv=pass; d=google.com; s=arc-20160816; b=Gyx4wn8WL/VxqnlliH+OeiOmd87YY0uHe3dsMQkFTVCKz7/acmRiW6xxg/XMJc6ND2 7zFzdDWDNAq7kXPk8kWA29IV2CeMdjFfnIDr9DTer3QEio+96dKt57uT03wI3J7xDL9n yVWAh07t+O2f2/bu4X9LXfWrQHqjVN4Ol3BFEozwmOf9zRpqJObo1BKWHQe9ZRrm9RZk qW9RFg9T8pfjePpyYYgbchEEKtYpcuMtWbCOZQN43uf1uu4oVZpOIanuEIO8R2E2BosK UcFfd0FhvfuUcJRayUIfUT/DhA0prxpbsWEVEa5mWOlEQanJVY+2V2QICjge0s0shtVI YQVg== 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=JVmH/+xaN9Z7r45x71mh1tq1KbNTZpCh/GRiBQtXED0=; fh=nGE692sbVdRvha6RYbzMUXtm1nr/30sV7frdtDN2z14=; b=DXbSE+GlFQmTN0XXIyvnvwfLl1Q0jJjyVSzJmKBMynHzP3FoIacRhZOagZ2hEyv505 oFx8SwPTSRQ+ugPOEubf8U94iU7LahXRtSugf+LY1aJ17HEptKiCg/0uqzVF9iXGdj0s j/rqqLw6GtLQ4FDM7wU3QukB4XxmzTVEfaYaOFciMAeVPrkphgJpQkN1shs5XC3zcfZT bYG0JEVsHX07zttXEz5ZScYUjfdO7pZAg27FBTTajwbLDFlnmm4L2hBZP8kQD9keZC4C pDB3e8PYp6wukXXaN59NvQGXwotKJS43ReXIUFohTsvHrsHIxTSYWN4puLDUx/oITI8w gDRg==; 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-80217-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80217-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id l13-20020a056402254d00b00565af2ed18esi1151965edb.80.2024.02.25.08.54.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Feb 2024 08:54:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80217-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; 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-80217-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80217-ouuuleilei=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 am.mirrors.kernel.org (Postfix) with ESMTPS id 0A6F81F21CFD for ; Sun, 25 Feb 2024 16:54:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 43CD618EB3; Sun, 25 Feb 2024 16:53:48 +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 1771017BDC for ; Sun, 25 Feb 2024 16:53:44 +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=1708880026; cv=none; b=EdTmzlKCJBVw8JnohLD2NCRG/a9TgwUiKE3D4kil3qQU2GCq6SRgp9XlcgOCIvrN+59HiegFd/QeTyip+KqWp87OvuLT/la50d9I9xlPomRCS/6dEUJRamgHCvQFWdsB7Q1STU58S5lXuTtYN4Up3WVW6s4ZVP1XPaSgV19c4hY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708880026; c=relaxed/simple; bh=yzk8hJGS5EAJboFzprtLjoWXpcFk7Mo9VpW2lpjOHHE=; h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To: MIME-Version:Content-Type; b=tbhcj8o6+VU53Xnupdx8JdVDr2+BDlpbNQ0DaxZoTmuCnM9PL7edSV7H+7DCC/OWri6ORCh1htHEoGvuIwFhhslbVKVMns0BWCEETh5zYFPN1xIRQaMkj9/Q5YSJm+uR9IJHnMg6QIgZr0uYZaONmPdRFnMZ9w5dLeCE0t7+kNU= 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-66-E8tAd1F8OPi8n5OgxZplNA-1; Sun, 25 Feb 2024 16:53:41 +0000 X-MC-Unique: E8tAd1F8OPi8n5OgxZplNA-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:53:41 +0000 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Sun, 25 Feb 2024 16:53:41 +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 08/11] minmax: Add min_const() and max_const() Thread-Topic: [PATCH next v2 08/11] minmax: Add min_const() and max_const() Thread-Index: AdpoCy246SYrYUdtTu+AtQRSWe90RA== Date: Sun, 25 Feb 2024 16:53:40 +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-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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791890603421629752 X-GMAIL-MSGID: 1791890603421629752 The expansions of min() and max() contain statement expressions so are not valid for static intialisers. min_const() and max_const() are expressions so can be used for static initialisers. The arguments are checked for being constant and for negative signed values being converted to large unsigned values. Using these to size on-stack arrays lets min/max be simplified. Zero is added before the compare to convert enum values to integers avoinding the need for casts when enums have been used for constants. Signed-off-by: David Laight --- include/linux/minmax.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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 278a390b8a4c..c08916588425 100644 --- a/include/linux/minmax.h +++ b/include/linux/minmax.h @@ -60,19 +60,34 @@ #op "(" #x ", " #y ") signedness error, fix types or consider u" #op "() before " #op "_t()"); \ __cmp_once(op, x, y, uniq); })) +#define __careful_cmp_const(op, x, y) \ + (BUILD_BUG_ON_ZERO(!__is_constexpr((x) - (y))) + \ + BUILD_BUG_ON_ZERO(!__types_ok(x, y)) + \ + __cmp(op, (x) + 0, (y) + 0)) + /** * min - return minimum of two values of the same or compatible types * @x: first value * @y: second value + * + * If @x and @y are constants the return value is constant, but not 'constant + * enough' for things like static initialisers. + * min_const(@x, @y) is a constant expression for constant inputs. */ #define min(x, y) __careful_cmp(min, x, y, __COUNTER__) +#define min_const(x, y) __careful_cmp_const(min, x, y) /** * max - return maximum of two values of the same or compatible types * @x: first value * @y: second value + * + * If @x and @y are constants the return value is constant, but not 'constant + * enough' for things like static initialisers. + * max_const(@x, @y) is a constant expression for constant inputs. */ #define max(x, y) __careful_cmp(max, x, y, __COUNTER__) +#define max_const(x, y) __careful_cmp_const(max, x, y) /** * umin - return minimum of two non-negative values From patchwork Sun Feb 25 16:54:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Laight X-Patchwork-Id: 206097 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1658313dyb; Sun, 25 Feb 2024 08:55:17 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWZHdAgeF3ibJEmullZLuFChvP3Do+B5ZxSBlD+pDd7fdyubDStx4PJmPWQ3Im0xeyZU3vrFK31BKbpNY6DvEpKNcgoaA== X-Google-Smtp-Source: AGHT+IGW8ip+hf7joXaAQMRrmNON3hkB5lsGMwX1huORFvC3GU09i60aKxTgE0F2VRkDUBPt5ezq X-Received: by 2002:ac2:4c49:0:b0:512:e704:44bc with SMTP id o9-20020ac24c49000000b00512e70444bcmr3756813lfk.23.1708880117040; Sun, 25 Feb 2024 08:55:17 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708880117; cv=pass; d=google.com; s=arc-20160816; b=aBXPw15NQznDcVGdDZLn0nbQQ7KszL9FxLL7oqCvhgJx0l55fLUxvuMjZtqe8Akbiz W4lpUwfx7skWRU4RUMAna+taAxajGURwkAueI3AvxcdgdpBIHBNxDgziCe6KcoNnN6KD G1GdEFyrTTrkbcDMl5TY9LuwgdemXtyT7VanjNqHS5McgcHv/eU/mMf/f1GlE2/9BnQO eYCY42mDuedOgP2vMoXm7kJvOsSjxlSk4v/Jv9b86l0yQ2LVzj+T9V9ST0vOZtPjO770 qN2N0zluDadqtc81/Pqf1yOSbgGGeXE0qO41DMcRAL+g0WW1JQNu9QBvXRoJtKfuMauX UJRA== 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=F98xCTVkzRhs/Efn8kmg+8jPcvt0XpdKh2Y2vrISD+w=; fh=nGE692sbVdRvha6RYbzMUXtm1nr/30sV7frdtDN2z14=; b=NAxZw0DD5h/wBiIvX2Pezryk9WEJ7z/HSk9xW/QfaDJiqrk7rdjv3S2KOlLsHX0QnR tCqEvcWzft2LXjj4W4BCIP4dCk+WfLoumNo/cSRi/TuvXUqRTyfsbzdEaBpePAQ2zaSm mSknykETc7Owe5qU3g5jOHgZyYqtrta/9uOp3Ag9gJZ/jo/qucaWNit+Uxp0TXcGREUA a/iqQaKknw+dIVn6c04LcKj1NaYp8Y6XrDwnfsMndd+MpWbKgkp22hbqitZPwFOYlecH eKsaFTAiiYogf7GHuEgQoxLMqejAIca1e3kqyNtFN5p1B2BK+7vU7drsdt5gZiVeq9g9 iQWw==; 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-80218-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80218-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id ce22-20020a170906b25600b00a3ec216c61bsi1346998ejb.530.2024.02.25.08.55.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Feb 2024 08:55:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80218-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; 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-80218-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80218-ouuuleilei=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 am.mirrors.kernel.org (Postfix) with ESMTPS id 799D61F21CBA for ; Sun, 25 Feb 2024 16:55:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9F2AA19BCA; Sun, 25 Feb 2024 16:54:53 +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 CD2921772D for ; Sun, 25 Feb 2024 16:54:49 +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=1708880091; cv=none; b=HIU+oeYCBUgc3y0AW2517QgVH87emhLQFDr/j5QPkfcAY1JvI0It+KYA3u0q6V/21UBRKEWVhAcNV5+tFUS+XTusQBFUmqlBg9Ef3U71ul9rysHyypxbgiWYrg9Wq67JVi4qOeOUqqgTxuKU16Ll8NlNEyMEmRfukTzbPv0JLFo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708880091; c=relaxed/simple; bh=HYmYptU+uSUe8xvs+wnLG3Dq3f5gzj4spCQhIyLt2vM=; h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To: MIME-Version:Content-Type; b=THmyjjHSMMwF7ZNrs590mBr0xRhvXijOOLWONLLKsfDpTfHBq2h4NqFPn4euHG/thfCS/cb07hLhYlyvZ/IK/H0td1tjnHDZXAfbG+fS3YUSHabXUZyBv9DUKKqk79hYNCBEqTa9U//HUsyUe9B+qEB7b0lO60yNvvkOACEzxsQ= 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-102-MER6aJkKPaSjPChmSL3lxw-1; Sun, 25 Feb 2024 16:54:46 +0000 X-MC-Unique: MER6aJkKPaSjPChmSL3lxw-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:54:45 +0000 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Sun, 25 Feb 2024 16:54:45 +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 09/11] tree-wide: minmax: Replace all the uses of max() for array sizes with max_const() Thread-Topic: [PATCH next v2 09/11] tree-wide: minmax: Replace all the uses of max() for array sizes with max_const() Thread-Index: AdpoC1PeUhR3U90kTRae/PLire4h2g== Date: Sun, 25 Feb 2024 16:54:45 +0000 Message-ID: <346b7e12ee6d4f728bcdb7d15ea1ee52@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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791890677606666457 X-GMAIL-MSGID: 1791890677606666457 These are the only uses of max() that require a constant value from constant parameters. There don't seem to be any similar uses of min(). Replacing the max() by max_const() lets min()/max() be simplified speeding up compilation. max_const() will convert enums to int (or unsigned int) so that the casts added by max_t() are no longer needed. Signed-off-by: David Laight --- drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c | 2 +- drivers/gpu/drm/drm_color_mgmt.c | 4 ++-- drivers/input/touchscreen/cyttsp4_core.c | 2 +- drivers/net/can/usb/etas_es58x/es58x_devlink.c | 2 +- fs/btrfs/tree-checker.c | 2 +- lib/vsprintf.c | 4 ++-- net/ipv4/proc.c | 2 +- net/ipv6/proc.c | 2 +- 8 files changed, 10 insertions(+), 10 deletions(-) Changes for v2: - Typographical and spelling corrections to the commit messages. Patches unchanged. diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c b/drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c index 00cd615bbcdc..935fb4014f7c 100644 --- a/drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c +++ b/drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c @@ -708,7 +708,7 @@ static const char *smu_get_feature_name(struct smu_context *smu, size_t smu_cmn_get_pp_feature_mask(struct smu_context *smu, char *buf) { - int8_t sort_feature[max(SMU_FEATURE_COUNT, SMU_FEATURE_MAX)]; + int8_t sort_feature[max_const(SMU_FEATURE_COUNT, SMU_FEATURE_MAX)]; uint64_t feature_mask; int i, feature_index; uint32_t count = 0; diff --git a/drivers/gpu/drm/drm_color_mgmt.c b/drivers/gpu/drm/drm_color_mgmt.c index d021497841b8..43a6bd0ca960 100644 --- a/drivers/gpu/drm/drm_color_mgmt.c +++ b/drivers/gpu/drm/drm_color_mgmt.c @@ -532,8 +532,8 @@ int drm_plane_create_color_properties(struct drm_plane *plane, { struct drm_device *dev = plane->dev; struct drm_property *prop; - struct drm_prop_enum_list enum_list[max_t(int, DRM_COLOR_ENCODING_MAX, - DRM_COLOR_RANGE_MAX)]; + struct drm_prop_enum_list enum_list[max_const(DRM_COLOR_ENCODING_MAX, + DRM_COLOR_RANGE_MAX)]; int i, len; if (WARN_ON(supported_encodings == 0 || diff --git a/drivers/input/touchscreen/cyttsp4_core.c b/drivers/input/touchscreen/cyttsp4_core.c index 7cb26929dc73..c6884c3c3fca 100644 --- a/drivers/input/touchscreen/cyttsp4_core.c +++ b/drivers/input/touchscreen/cyttsp4_core.c @@ -871,7 +871,7 @@ static void cyttsp4_get_mt_touches(struct cyttsp4_mt_data *md, int num_cur_tch) struct cyttsp4_touch tch; int sig; int i, j, t = 0; - int ids[max(CY_TMA1036_MAX_TCH, CY_TMA4XX_MAX_TCH)]; + int ids[max_const(CY_TMA1036_MAX_TCH, CY_TMA4XX_MAX_TCH)]; memset(ids, 0, si->si_ofs.tch_abs[CY_TCH_T].max * sizeof(int)); for (i = 0; i < num_cur_tch; i++) { diff --git a/drivers/net/can/usb/etas_es58x/es58x_devlink.c b/drivers/net/can/usb/etas_es58x/es58x_devlink.c index 635edeb8f68c..28fa87668bf8 100644 --- a/drivers/net/can/usb/etas_es58x/es58x_devlink.c +++ b/drivers/net/can/usb/etas_es58x/es58x_devlink.c @@ -215,7 +215,7 @@ static int es58x_devlink_info_get(struct devlink *devlink, struct es58x_sw_version *fw_ver = &es58x_dev->firmware_version; struct es58x_sw_version *bl_ver = &es58x_dev->bootloader_version; struct es58x_hw_revision *hw_rev = &es58x_dev->hardware_revision; - char buf[max(sizeof("xx.xx.xx"), sizeof("axxx/xxx"))]; + char buf[max_const(sizeof("xx.xx.xx"), sizeof("axxx/xxx"))]; int ret = 0; if (es58x_sw_version_is_valid(fw_ver)) { diff --git a/fs/btrfs/tree-checker.c b/fs/btrfs/tree-checker.c index 6eccf8496486..aec4729a9a82 100644 --- a/fs/btrfs/tree-checker.c +++ b/fs/btrfs/tree-checker.c @@ -615,7 +615,7 @@ static int check_dir_item(struct extent_buffer *leaf, */ if (key->type == BTRFS_DIR_ITEM_KEY || key->type == BTRFS_XATTR_ITEM_KEY) { - char namebuf[max(BTRFS_NAME_LEN, XATTR_NAME_MAX)]; + char namebuf[max_const(BTRFS_NAME_LEN, XATTR_NAME_MAX)]; read_extent_buffer(leaf, namebuf, (unsigned long)(di + 1), name_len); diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 552738f14275..6c3c319afd86 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -1080,8 +1080,8 @@ char *resource_string(char *buf, char *end, struct resource *res, #define FLAG_BUF_SIZE (2 * sizeof(res->flags)) #define DECODED_BUF_SIZE sizeof("[mem - 64bit pref window disabled]") #define RAW_BUF_SIZE sizeof("[mem - flags 0x]") - char sym[max(2*RSRC_BUF_SIZE + DECODED_BUF_SIZE, - 2*RSRC_BUF_SIZE + FLAG_BUF_SIZE + RAW_BUF_SIZE)]; + char sym[max_const(2*RSRC_BUF_SIZE + DECODED_BUF_SIZE, + 2*RSRC_BUF_SIZE + FLAG_BUF_SIZE + RAW_BUF_SIZE)]; char *p = sym, *pend = sym + sizeof(sym); int decode = (fmt[0] == 'R') ? 1 : 0; diff --git a/net/ipv4/proc.c b/net/ipv4/proc.c index 5f4654ebff48..a4aff27f949b 100644 --- a/net/ipv4/proc.c +++ b/net/ipv4/proc.c @@ -43,7 +43,7 @@ #include #include -#define TCPUDP_MIB_MAX max_t(u32, UDP_MIB_MAX, TCP_MIB_MAX) +#define TCPUDP_MIB_MAX max_const(UDP_MIB_MAX, TCP_MIB_MAX) /* * Report socket allocation statistics [mea@utu.fi] diff --git a/net/ipv6/proc.c b/net/ipv6/proc.c index 6d1d9221649d..7fedb60aaeac 100644 --- a/net/ipv6/proc.c +++ b/net/ipv6/proc.c @@ -27,7 +27,7 @@ #include #define MAX4(a, b, c, d) \ - max_t(u32, max_t(u32, a, b), max_t(u32, c, d)) + max_const(max_const(a, b), max_const(c, d)) #define SNMP_MIB_MAX MAX4(UDP_MIB_MAX, TCP_MIB_MAX, \ IPSTATS_MIB_MAX, ICMP_MIB_MAX) From patchwork Sun Feb 25 16:56:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Laight X-Patchwork-Id: 206098 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1659036dyb; Sun, 25 Feb 2024 08:57:46 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXWiEfYZHvdGGTWBM7/Y3yOZtxB3Z089sTB9FASYeOcv7bPZysPwhh4VVA0lJWD1UEgnBQjJTedEexEVf7o0fsce7doEA== X-Google-Smtp-Source: AGHT+IEM9Jti4dhG8br1JfkOxfwaCSLGR9N0Rrz4SjLwOOB0oGw3wm3pIPtBcGpVz+QumNxZAfXu X-Received: by 2002:a17:907:1de0:b0:a3e:5ebf:345c with SMTP id og32-20020a1709071de000b00a3e5ebf345cmr4069048ejc.21.1708880266310; Sun, 25 Feb 2024 08:57:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708880266; cv=pass; d=google.com; s=arc-20160816; b=ZzayXyrx7BOoPa/f33aNmZGjPSGU+niLKU6oAGTs4DOukRvIv4UuIVGD/j5bAOTIcH qsYxVQHjINDg+7RmbEaMv5/VBuNgqAk5ke264FEBNZu5utRfsQxVOs1FXbrlpPVfhQvW 8knPX388HRVDZFgpoR4H9dUe9Xj0eRZyomcK0SunudTYv9376JjGlqjmkIrVaSqa0IRd GonTrHye/pUdLwDHeehuVKupM6hxbHR7QcNADqrml7iAgnhdaCaLkwPPuMLROcDSz8ud 4A1mYM1mw0hOYMp7CniE9CueWHx/hKwu4SvwDlry+NKsEMhpL00LqwhL2hhYGIug01PH pkSg== 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=kLObBfzrrymijIw+aLKmED41fp+jo11zk4huTr4eB4w=; fh=nGE692sbVdRvha6RYbzMUXtm1nr/30sV7frdtDN2z14=; b=ovrGqace5GZIJ2bUeow1KEQhYASqsBbCV8/OHyvNGs8b4S1+1yhcPih0i+rH5W8Kb5 3Bx6j6tyqpjwFejCcD+yP2sEWWZClH/jmlGgXF2i89lxiFjIRHShLhPGoHB3J9C5TCRQ GYBh7EB7MEZmjx9jBbFf7ct0bX5dZZkot8objutB6JINP87t69IomXe40d1FJR97eON5 Ghm8Nz+0ZQLFjkUi9SFD8H/jwdmh9XBbnnkacG6wVFdacTtxSxCUDTffkxtGEJxqndv/ ocmz9SzSXXkht6lMhGUoRy8765ZHjbYrZZyku6gf72NpScalZ4L6ibMAo7eSCXELcZlO ICfw==; 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-80219-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80219-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id m6-20020a1709060d8600b00a433c7a39fdsi349761eji.94.2024.02.25.08.57.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Feb 2024 08:57:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80219-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; 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-80219-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80219-ouuuleilei=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 am.mirrors.kernel.org (Postfix) with ESMTPS id CC2811F21DA9 for ; Sun, 25 Feb 2024 16:57:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5818E1B948; Sun, 25 Feb 2024 16:56:23 +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 2B1111802E for ; Sun, 25 Feb 2024 16:56:20 +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=1708880181; cv=none; b=uJgxffw8Tx37FFkNgSsqYxgBpnRFqVwk5T62NpRcbkD+iJQzIOYTYbRdKW5WYjpaX6LzPVpFnZ4IA6kMVcGEd/F9gEOfzOS4g1O3f59udR+uX5gy1+7NXbynfCWpMU0UMcnN/2wIsvN/+JwFNw0q0iv6oRLCr0wEYqOv/KAP30E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708880181; c=relaxed/simple; bh=zOWFqzB7N0pb8vLD4U0rutFH4q0ufXT6YzwjVxhLXv0=; h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To: MIME-Version:Content-Type; b=am6ga1zFqipkVcxcrlHgfZIYr/5+ZmwKEjXc/p8MrLu3xCyT5cUXU7RrAB6V1DpJOJ7sLjriqqvjg4WS5VAdS1bfrXui5EuuLWRkHbwCvd3k/tnqAFSxZym4dIOiqNZWByV7NLmMuShtrFBuwfTJEGOwiTxtK1dgAdzV7BxIM4Q= 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-258-4eUIVhTQPOq-JwK6Hr19cA-1; Sun, 25 Feb 2024 16:56:17 +0000 X-MC-Unique: 4eUIVhTQPOq-JwK6Hr19cA-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:56:16 +0000 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Sun, 25 Feb 2024 16:56:16 +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 10/11] block: Use a boolean expression instead of max() on booleans Thread-Topic: [PATCH next v2 10/11] block: Use a boolean expression instead of max() on booleans Thread-Index: AdpoC3sh/004JKwJQQKikvnz7Zkpuw== Date: Sun, 25 Feb 2024 16:56:16 +0000 Message-ID: <9561641946f1404b931d97a576bfbb28@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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791890834252878882 X-GMAIL-MSGID: 1791890834252878882 blk_stack_limits() contains: t->zoned = max(t->zoned, b->zoned); These are bool, so can be replaced by bitwise or. However it generates: error: comparison of constant '0' with boolean expression is always true [-Werror=bool-compare] inside the signedness check that max() does unless a '+ 0' is added. It is a shame the compiler generates this warning for code that will be optimised away. Change so that the extra '+ 0' can be removed. Signed-off-by: David Laight --- block/blk-settings.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) Changes for v2: - Typographical and spelling corrections to the commit messages. Patches unchanged. diff --git a/block/blk-settings.c b/block/blk-settings.c index 06ea91e51b8b..9ca21fea039d 100644 --- a/block/blk-settings.c +++ b/block/blk-settings.c @@ -688,7 +688,7 @@ int blk_stack_limits(struct queue_limits *t, struct queue_limits *b, b->max_secure_erase_sectors); t->zone_write_granularity = max(t->zone_write_granularity, b->zone_write_granularity); - t->zoned = max(t->zoned, b->zoned); + t->zoned = t->zoned | b->zoned; return ret; } EXPORT_SYMBOL(blk_stack_limits); From patchwork Sun Feb 25 16:56:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Laight X-Patchwork-Id: 206099 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1659145dyb; Sun, 25 Feb 2024 08:58:07 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWzsGBMIl2qZwdJ0hv8sVQv4WPmTFwGFKhZ1tWy/ClWcx0cw9T/4ms1Ify6x9XPtfwr4N5INUYVQpnK099DKtsKnujt6A== X-Google-Smtp-Source: AGHT+IEqXz/gJQoYurO5wTHDyK0PG7kfJy9mP+QVp1hmDp47jB6aZ244v2sonwOkICiXMr2v5L+d X-Received: by 2002:a05:620a:40ca:b0:783:e30b:3759 with SMTP id g10-20020a05620a40ca00b00783e30b3759mr6992867qko.35.1708880286936; Sun, 25 Feb 2024 08:58:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708880286; cv=pass; d=google.com; s=arc-20160816; b=zgCbggsTIZ9tN+9AmG6xWudoK4LEtVaVlMEGVlWlsDkRVKmXJ3HRWXp2c60JnR/o9B gXXdURNJOoiHogGaB5uBE2AUD7k+M+AdjwrR/CYXLc8mpkLoEWD7k2crszkS5sssf4DL T0oIjoszqCONm59mwbuWyI77+FtJJ5C9RqbvIzRD7INVYus6lJugyn7nfo+906fuH5y0 y6JPMuSqfE5XN4wknKd/nBtz0Bd0LnWAMmbe1E9RKtfTikBpTNlwofbHG9KT+gkdIUnB jN0ENAJxVRES62sPuXKGI/vXm4kvpFTY8UpO8DePcEy4o1cjdz8LwQovFzB9jkV3A1j+ mmdQ== 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=rsRmR/5ns1TyNV7cG+3v8oWYZhfwk+FvC/YgG4vlK0I=; fh=nGE692sbVdRvha6RYbzMUXtm1nr/30sV7frdtDN2z14=; b=fe0uEvxDMi3WZh28S2NpHMiGZgfd0bMxOGvkqU6wA+5n6Z0PH4A2N/4VCPrnMOohCk bP5XWafM786GJmqNfCkbKFytmN0C5xVF0ctaq6BRzo6q72oHBaXg+DpFQoJcsEHY5XKI upBzxDG03hi2hHP4X3SI/2KibOxWlZjy503sIzBWvqb8V3M1CvU1xLm6hDyb+b7tbOaL lotGhLUlCAcSIRCk3frIsnIPxUhtreMu/BEOisxdlT8l0FUYIgqQVneH9g4TH0BjJeXk oKKZ4QJXwqhn87j30JuoJmgenqZiu/UeHxTusoJzeCaRA5iFh/m0bxezi4JQ8JuD+7sL 71Mg==; 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-80220-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80220-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id t11-20020a05620a450b00b00787cc7e1c7dsi1705590qkp.137.2024.02.25.08.58.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Feb 2024 08:58:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80220-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; 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-80220-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80220-ouuuleilei=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 91A8B1C2040D for ; Sun, 25 Feb 2024 16:58:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9D3BA156C2; Sun, 25 Feb 2024 16:57:13 +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 0ABE1182D4 for ; Sun, 25 Feb 2024 16:57:09 +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=1708880232; cv=none; b=KjBekuj2Yl4gVKTGZ6o55r+1pUvxKFbafedZJ6dlrDv7YeSE89OBHpLHvbUD9j7O6UQyjCpkwtMfpresrdku99GOjA38AIYIdl6U0KsSV277+tYjkXHnevCtY/2ywwQzrfhxC4TlFOkKIOG/FN2Zo3x+Il4FUeQuWg4WoZVTemc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708880232; c=relaxed/simple; bh=ldiOEy1AqqZRm2jpxplq9I8qQHwbubdPAOsFwLgRl3Q=; h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To: MIME-Version:Content-Type; b=UZ4KMA78Pkf0Xx4aIBjXSX5UVT3zLrXbA9LLdBBJ+A306e+5+MgilN90aZJW9A0G4l/YIXZ3nu84yHHgoJffJsAULZvNPTjIGenC8IdPKCBvxlS/zXlFXUWHYNyfB0kR5USXpu6Z1E8N7MPIM1Ja6M1hkveTiDiv2WtvviSnV3M= 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-209-DBxHGHkZP8yW0XsruhqEOw-1; Sun, 25 Feb 2024 16:57:00 +0000 X-MC-Unique: DBxHGHkZP8yW0XsruhqEOw-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:56:59 +0000 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Sun, 25 Feb 2024 16:56:59 +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 11/11] minmax: min() and max() don't need to return constant expressions Thread-Topic: [PATCH next v2 11/11] minmax: min() and max() don't need to return constant expressions Thread-Index: AdpoC6KUHy5Z1N7yRkiaBkc7ZdEdRQ== Date: Sun, 25 Feb 2024 16:56:58 +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-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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791890855688637758 X-GMAIL-MSGID: 1791890855688637758 After changing the handful of places max() was used to size an on-stack array to use max_const() it is no longer necessary for min() and max() to return constant expressions from constant inputs. Remove the associated logic to reduce the expanded text. Remove the 'hack' that allowed max(bool, bool). Fixup the initial block comment to match current reality. Signed-off-by: David Laight --- include/linux/minmax.h | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 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 c08916588425..5e65c98ff256 100644 --- a/include/linux/minmax.h +++ b/include/linux/minmax.h @@ -8,13 +8,10 @@ #include /* - * min()/max()/clamp() macros must accomplish three things: + * min()/max()/clamp() macros must accomplish several things: * * - Avoid multiple evaluations of the arguments (so side-effects like * "x++" happen only once) when non-constant. - * - Retain result as a constant expressions when called with only - * constant expressions (to avoid tripping VLA warnings in stack - * allocation usage). * - Perform signed v unsigned type-checking (to generate compile * errors instead of nasty runtime surprises). * - Unsigned char/short are always promoted to signed int and can be @@ -22,13 +19,19 @@ * - Unsigned arguments can be compared against non-negative signed constants. * - Comparison of a signed argument against an unsigned constant fails * even if the constant is below __INT_MAX__ and could be cast to int. + * + * The return value of min()/max() is not a constant expression for + * constant parameters - so will trigger a VLA warging if used to size + * an on-stack array. + * Instead use min_const() or max_const() which do generate constant + * expressions and are also valid for static initialisers. */ #define __typecheck(x, y) \ (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1))) /* Allow unsigned compares against non-negative signed constants. */ #define __is_ok_unsigned(x) \ - (is_unsigned_type(typeof(x)) || (__is_constexpr(x) ? (x) + 0 >= 0 : 0)) + (is_unsigned_type(typeof(x)) || (__is_constexpr(x) ? (x) >= 0 : 0)) /* Check for signed after promoting unsigned char/short to int */ #define __is_ok_signed(x) is_signed_type(typeof((x) + 0)) @@ -53,12 +56,10 @@ typeof(y) __y_##uniq = (y); \ __cmp(op, __x_##uniq, __y_##uniq); }) -#define __careful_cmp(op, x, y, uniq) \ - __builtin_choose_expr(__is_constexpr((x) - (y)), \ - __cmp(op, x, y), \ - ({ _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); })) +#define __careful_cmp(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); }) #define __careful_cmp_const(op, x, y) \ (BUILD_BUG_ON_ZERO(!__is_constexpr((x) - (y))) + \