Re: [PATCH] uapi/asm/termbits: Use the U integer suffix for bit fields
From: Greg KH <gregkh@linuxfoundation.org>
Date: 2024-06-12 14:21:28
Also in:
linux-api
On Wed, Jun 12, 2024 at 04:00:18PM +0200, Alejandro Colomar wrote:
Hi Greg, On Wed, Jun 12, 2024 at 03:35:20PM GMT, Greg KH wrote:quoted
On Wed, Jun 12, 2024 at 03:16:58PM +0200, Alejandro Colomar wrote:quoted
Constants that are to be used in bitwise operations should be unsigned, or a user could easily trigger Undefined Behavior.Wait, do we really have such broken compilers out there?I meant this as a generic statement that signed integers on bitwise ops are bad, not as a specific statement that these values would trigger UB. I expect that these specific values and the operations done on them probably don't trigger UB, since the shifts are done by a controlled amount, and there are justa few operations done on them.
These, for the most part, are NOT used as shifts.
For example, a left shift where a set bit overflows the type (e.g., 1<<32), causes UB.
Sure, but that's not in play here.
The reason why it's better to avoid this at all even if we know these values work fine, is that programs using <asm/termbits.h> would need to disable those compiler warnings, which could silence warnings on other code which might be broken.
But again, you aren't using these as bit shifts, they are bit masks, or values, only.
TL;DR: The kernel isn't broken, but improving this would allow users to enable stricter warnings, which is a good thing.
Enable it where? thanks, greg k-h