lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <9f8c979a7a2c4b78961297ee2fae380e@AcuMS.aculab.com>
Date: Thu, 5 Dec 2024 11:01:37 +0000
From: David Laight <David.Laight@...LAB.COM>
To: 'David Howells' <dhowells@...hat.com>
CC: "netdev@...r.kernel.org" <netdev@...r.kernel.org>, Marc Dionne
	<marc.dionne@...istor.com>, Yunsheng Lin <linyunsheng@...wei.com>, "David S.
 Miller" <davem@...emloft.net>, Eric Dumazet <edumazet@...gle.com>, "Jakub
 Kicinski" <kuba@...nel.org>, Paolo Abeni <pabeni@...hat.com>,
	"linux-afs@...ts.infradead.org" <linux-afs@...ts.infradead.org>,
	"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: RE: [PATCH net-next 02/37] rxrpc: Use umin() and umax() rather than
 min_t()/max_t() where possible

From: David Howells
> Sent: 05 December 2024 10:50
> 
> David Laight <David.Laight@...LAB.COM> wrote:
> 
> > > Use umin() and umax() rather than min_t()/max_t() where the type specified
> > > is an unsigned type.
> >
> > You are also changing some max() to umax().
> 
> Good point.  If I have to respin my patches again, I'll update that.
> 
> > Presumably they have always passed the type check so max() is fine.
> > And max(foo, 1) would have required that 'foo' be 'signed int' and could
> > potentially be negative when max(-1, 1) will be 1 but umax(-1, 1) is
> > undefined.
> 
> There have been cases like this:
> 
> 	unsigned long timeout;
> 	...
> 	timeout = max(timeout, 1);
> 
> where the macro would complain because it thought "timeout" and "1" were
> different sizes, so "1UL" had to be used.  Using umax() deals with that issue.

The current version of max() won't complain if you use "1".
It uses statically_true((x) >= 0) to decide whether values are valid
for an unsigned compare.

So even:
	int r = fn();
	unsigned int u = fu();
	if (r < 0)
		return r;
	return max(r, u);

is fine since modern compilers do limited domain tracking.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ