Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp2265141rdd; Fri, 12 Jan 2024 04:40:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IEfNvanN8FHVQposDtI8rStMTkL/qgM2FW6nZLlLNO4jQucF/0TAeW5I0+UWdw3uLJvpwSy X-Received: by 2002:a05:620a:d81:b0:783:2b49:bb7f with SMTP id q1-20020a05620a0d8100b007832b49bb7fmr1798128qkl.27.1705063248001; Fri, 12 Jan 2024 04:40:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705063247; cv=none; d=google.com; s=arc-20160816; b=b/w5IDQIKsTJl2VaP3nR1OL4j6Ew3e5FlyAipDmlwASCBMyFkZvKrNqcUS3N7W/Zx1 EhlJla11Q9k1F4+NkLyekjvgAKHsAmHDNrIoIq7XPVr7aDCtr7mdehXkPj0s/MeEk0bR nZk3qvER5YywRSSRg9MXWtHaD1attikPFcdS/4xBi+SDbEQMZHOLVxwvnBN+Qyz1Y54u Eax9wL0OxqXJiqk8C40VvyZIyQ2dSk2K3T6WSgcjDsoW+hQTpQdFJgdQJ/8fPKKjQxSN HitM7g1LiQEa/3dthnWM2IoEeyQoU15KOo2/fg6tvFXP0qvYuGCssb3d61RcRyYxOdv7 4hgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=geEkxPaDW5GCpv1WqkMn5Bcqr64LHTF65oGNQRrTPxM=; fh=qGAKtm2PD+NxJ1Hk/Ovt7q824zeHFTw93aNWsehQ8wc=; b=mEPspxguUNONEGeMQUYyLh6SUE9ASTBDs44Pu7qGOCqjQ54Pz9fNleZsdOjOJdiuCY hAwEFXnvbat2qRtmQKaKEZZBdmeritXfc8PJmgX4E/HC2dKAkSBsUMkriEYoWoc8O/a4 I++6f3PM5jDpNf73RTdnhO4q9xVEpWOA51c8mLQ8U9YXKM3zVw867orbtxKp5qAs/WYM HeoK9skNgzdoAPZ7dc1DV/C0sB+hn9WtYJ5WX6j4xH9b4mr2qT1hlxMesbaW0ZHazCrF 5eBM6l0kUQS6IWzgP62EqQPHqUIuH51okMheIAuH7cL28ME9q89RxIJcO98z3SGYZ4yK njgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OFOQk6Bf; spf=pass (google.com: domain of linux-kernel+bounces-24660-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24660-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id l5-20020a37f505000000b0078310e092bfsi2771057qkk.678.2024.01.12.04.40.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jan 2024 04:40:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-24660-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OFOQk6Bf; spf=pass (google.com: domain of linux-kernel+bounces-24660-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24660-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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 BF8B31C22D23 for ; Fri, 12 Jan 2024 12:40:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A1BEA59B51; Fri, 12 Jan 2024 12:40:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="OFOQk6Bf" Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F13965917D for ; Fri, 12 Jan 2024 12:40:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-40e636fd3d2so8401495e9.1 for ; Fri, 12 Jan 2024 04:40:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1705063238; x=1705668038; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=geEkxPaDW5GCpv1WqkMn5Bcqr64LHTF65oGNQRrTPxM=; b=OFOQk6Bfem7IXz7Vt1eg0DkBxas4os6xqvwgkwTQ8P98LGH5qdHf7qe9gNE5nwlqj5 zSh18vw6dmDGYLCclz4lAyDUyhvcxLTla3ThAS99ZV+/zuauR/kIU5gAn+A1ra5mWvAd sOjnw013CqSNEiIXKUNWYCE+PiEJCcm0GGOLkG7+716luLHw3MMwABmS1/VLwJ/x0PfH Mln39Aup34D/VRisztxPeYq4MGNKU0MUlzpY1NV3xE1jUw8ZwJpoPonVpF5lqPSQNJ06 rPcgxq4buGL9VbenOjlO7LmPZ/2gdP3q3BspflecjVJZThZKLeWYgOvL/dQkt6WIyA/G eUQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705063238; x=1705668038; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=geEkxPaDW5GCpv1WqkMn5Bcqr64LHTF65oGNQRrTPxM=; b=Isu2kALkZSby9rPlbjqWxwBQkU2TlN5k7dDhf1U9TXHHy1r/RnMy+eCExX9vVkOs5s p4bOUi48UnPaTfsD3df3oevng76LVddZN9o/HAu4bKSRZG2IuZTL8KX/Jt0L4lVLV2B6 v4aotzbnhpoz2fcVPEE3P+DfsNNGfMFPxv8ANnLFl2mNkepYfu2Qp69KCXa+97J2Kdat to/GmvJPzYALtghdcDyrsQGaWvVKRCPs5GYgkx412KFLONk+C4xH35oqnDMg24Okzch/ HDhsCAvjeHtC9JIqYRaafShwgIP2VtwXDdHuzLTtZjgQIIR5X99YkG4/yBDcNzCU16fy Miug== X-Gm-Message-State: AOJu0YwXI+WzeO4aI5MlGSwD7GBbMzk04xfhUfW7Zf8a+CISgJbBy8tq HTtomAlvxnUzw7o/bRDXBpWEl3v/1wjTNw== X-Received: by 2002:a05:600c:a083:b0:40e:549c:1752 with SMTP id jh3-20020a05600ca08300b0040e549c1752mr738314wmb.13.1705063238091; Fri, 12 Jan 2024 04:40:38 -0800 (PST) Received: from localhost ([102.140.209.237]) by smtp.gmail.com with ESMTPSA id j7-20020a05600c190700b0040e52cac976sm9419713wmq.29.2024.01.12.04.40.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jan 2024 04:40:37 -0800 (PST) Date: Fri, 12 Jan 2024 15:40:34 +0300 From: Dan Carpenter To: David Laight 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(). Message-ID: <8ae34aa0-ffcc-43c9-9192-393cf2707c38@moroto.mountain> References: <918545c4-0870-4ea5-ab11-53eaed91aec7@moroto.mountain> <97e6fe43318b4cad865feadace402880@AcuMS.aculab.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <97e6fe43318b4cad865feadace402880@AcuMS.aculab.com> On Fri, Jan 12, 2024 at 12:16:00PM +0000, David Laight wrote: > From: Dan Carpenter > > Sent: 12 January 2024 09:13 > > > > 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. > I understand your changes, it seems like a really nice API. I was just asking about min_t(int, in old code. Just to take the first example from my git grep: arch/arm/mach-orion5x/ts78xx-setup.c 160 sz = min_t(int, 4 - off, len); 161 writesb(io_base, buf, sz); If len is negative then we write negative bytes to writesb(). What was the thinking here? > 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(). I think I would maybe like a mins() which returns signed values, and then we would convert all the min() usages to either minu() or mins() and delete min(). regards, dan carpenter