[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <97e6fe43318b4cad865feadace402880@AcuMS.aculab.com>
Date: Fri, 12 Jan 2024 12:16:00 +0000
From: David Laight <David.Laight@...LAB.COM>
To: 'Dan Carpenter' <dan.carpenter@...aro.org>
CC: "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>, "Linus
Torvalds" <torvalds@...ux-foundation.org>, 'Andy Shevchenko'
<andriy.shevchenko@...ux.intel.com>, 'Andrew Morton'
<akpm@...ux-foundation.org>, "'Matthew Wilcox (Oracle)'"
<willy@...radead.org>, 'Christoph Hellwig' <hch@...radead.org>, "'Jason A.
Donenfeld'" <Jason@...c4.com>
Subject: RE: [PATCH next v4 0/5] minmax: Relax type checks in min() and max().
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.
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.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
Powered by blists - more mailing lists