Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp2252368rdd; Fri, 12 Jan 2024 04:16:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IGsisfOjaCKlf0lAQFfQqYb/5bR3jWH5l1kQHbjoZfH6gAMXXL9UNgJxq8FQ/i4KEx6PsFa X-Received: by 2002:a62:cd04:0:b0:6d9:3b54:b37a with SMTP id o4-20020a62cd04000000b006d93b54b37amr560834pfg.1.1705061793880; Fri, 12 Jan 2024 04:16:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705061793; cv=none; d=google.com; s=arc-20160816; b=SkEZ9wsEUnkj2eiSFXsadTkUxmRfuS+zvvT8IR80rySIshtOTraIxbt1SDNm5W5N+h GTFoIeihxq4aFTm9uwZfcemK3sYVveiBKYrb5cQl34KhOZCfJmb78AcWPpzZxoMe0Ya0 PGyR0OZNJsh1+01O2v7f7LSqh40Ii5+EPxcQuX5Frb+7Ko6dCJJrl3cySj4nj+J3pyWN NHWMI/lEvSTbk25tkiMDE08HCgckSWK0B826YwDQjnUGZav/l/IpyRAkTlrRBVc9D2TZ z01LvgM0ozghZVhizkQpbAMp3dUW9eLfjuG4h8XBuy7aPTWlxv7hVAOQlZeniKfJaybq /Pug== ARC-Message-Signature: i=1; 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=xznFHgUskEFNX4kmvAUoIqZwFb6jtTMCtfBtXR+fHrQ=; fh=X9mAGPl2ev/UYMtscTnkIwJ7XY2XMCpCjy/CeoerKjY=; b=UebGPQ1qJaHKh+T0YiTwsiLJQ/7BmoDMKnOPWg99QYps8GQtE9xirFINRM/jZxRyve GVhXjjk2awT+a7/OQVvzmEnkHzgQcjfnnTdC/2n6MD7Oi/XVbiZmpJ4vrULLuV00Kwae ZyKSjqHTrdwIol8AmO6SHBhoJ9L2vH3Y28WqBWR6iQXWfKxY0BhUhYHcejX59+NO28Fn XeNpZ3/iQfSiTos0gMBge+oFQtAeWxZCqFovbs8SkJg5GOC/tJhtnqDLt+p8JI2r2r5O RUf0MozPvvIYk/fOeaAXOIOe/pU7thWCnchxNJgfzo8dyl66gx6YULKVKD32327VkoOX WpMw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-24645-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24645-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id x67-20020a636346000000b005ced66d07c3si3315772pgb.41.2024.01.12.04.16.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jan 2024 04:16:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-24645-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-24645-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24645-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 6629C287845 for ; Fri, 12 Jan 2024 12:16:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 901016A02F; Fri, 12 Jan 2024 12:16:27 +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 1B08E6A026 for ; Fri, 12 Jan 2024 12:16:20 +0000 (UTC) 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-237-4YI_s87pMKKZUk4f2e5Iig-1; Fri, 12 Jan 2024 12:16:17 +0000 X-MC-Unique: 4YI_s87pMKKZUk4f2e5Iig-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; Fri, 12 Jan 2024 12:16:00 +0000 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Fri, 12 Jan 2024 12:16:00 +0000 From: David Laight To: 'Dan Carpenter' CC: "linux-kernel@vger.kernel.org" , "Linus Torvalds" , 'Andy Shevchenko' , 'Andrew Morton' , "'Matthew Wilcox (Oracle)'" , 'Christoph Hellwig' , "'Jason A. Donenfeld'" Subject: RE: [PATCH next v4 0/5] minmax: Relax type checks in min() and max(). Thread-Topic: [PATCH next v4 0/5] minmax: Relax type checks in min() and max(). Thread-Index: AdnqB/CwAvMQ3gkdSO607JUF4aSKdhbL6D2AAAV0aXA= Date: Fri, 12 Jan 2024 12:16:00 +0000 Message-ID: <97e6fe43318b4cad865feadace402880@AcuMS.aculab.com> References: <918545c4-0870-4ea5-ab11-53eaed91aec7@moroto.mountain> In-Reply-To: <918545c4-0870-4ea5-ab11-53eaed91aec7@moroto.mountain> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable From: Dan Carpenter > Sent: 12 January 2024 09:13 >=20 > I've often wondered why so many people use min_t(int, size, limit) when > they really do not want negative sizes... Is there a performance reason? > git grep 'min_t(int,' says there are 872 instances of this. Probably > some do want negatives but it's a quite small percent. But you really don't a negative 'size' converted to a large unsigned value above the limit - that would be worse. All the type checking is there to stop that happening. Even with my changes min(int_var, sizeof()) is a compile error. To do otherwise would really requite the sizeof() to be converted to int - leaving the other type alone. Easiest done by using 'int' instead of 'typeof(y)' for the local variable inside cmp_once(). However Linus didn't like that change so I removed it from the version that got committed. It would also bloat the expansion even more. That could be reduced by expecting min(var, const) not min(const, var) and only doing all the constant checks on the second argument. FWIW min_t() should really skip all the type checks. Once both value have been cast the 'same type' test will pass. =09David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1= PT, UK Registration No: 1397386 (Wales)