Re: [PATCH] iov_iter: Use __bitwise with the extraction_flags

From: Al Viro
Date: Thu Jan 26 2023 - 17:27:23 EST


On Thu, Jan 26, 2023 at 10:33:50AM +0000, David Howells wrote:
> X-Mailer: MH-E 8.6+git; nmh 1.7.1; GNU Emacs 28.2
> --------
> David Hildenbrand <david@xxxxxxxxxx> wrote:
>
> > >> Just a note that the usage of new __bitwise types instead of "unsigned" is
> > >> encouraged for flags.
>
> Something like the attached?
>
> > $ git grep "typedef int" | grep __bitwise | wc -l
> > 27
> > $ git grep "typedef unsigned" | grep __bitwise | wc -l
> > 23
>
> git grep __bitwise | grep typedef | grep __u | wc -l
> 62
>
> *shrug*
>
> Interestingly, things like __be32 are __bitwise. I wonder if that actually
> makes sense or if it was just convenient so stop people doing arithmetic on
> them. I guess doing AND/OR/XOR on them isn't a problem provided both
> arguments are appropriately byte-swapped.

Forget the words "byte-swapped". There are several data types.
With different memory representations. Bitwise operations are
valid between the values of the same type and yield the result
of that same type.

The fact that mapping between those representations happens to
be an involution is an accident; keeping track of the number of
times you've done a byteswap to the value currently in this
variable is asking for trouble. It's really easy to fuck up.

"Am I trying to store the value of type X in variable of type Y
(presumably having forgotten that I need to use X_to_Y(...)
to convert)" is much easier to keep track of.