Re: [PATCH 3/5] bitwise: allow compares for bitwise types

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Jun 27, 2022 at 12:05 PM Luc Van Oostenryck
<luc.vanoostenryck@xxxxxxxxx> wrote:
>
> Currently, bitwise types are restricted to bitwise operations
> (&, |, ^ and ~) as well as equality comparisons.
>
> This patch makes the others comparisons valid for bitwise types
> too.
>
> Warning: This change make sense in the context of [1] but
>          doesn't make sense for the 'main' bitwise types:
>          __be32 and friends.

Yeah, this is wrong.

It will literally break one of the use-cases, which is endianness comparisons.

You cannot compare values in the wrong endianness for greater-than or
less-than, because you will get the wrong answer - the ordering is
different in different byte-orders.

But comparing for equality (and inequality) is fine, and we actually
do that in the kernel (ie you can take a big-endian value, and compare
it with another big-endian value for being equal, without converting
it to the local CPU endianness).

Now, comparing the *constants* 0 and all-ones is fine. They are
smaller than (and larger than) all other values, regardless of any
byte/bit order issues.

So I think that really needs to check that one (or both) sides are the
magic constants.

             Linus



[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux