Re: [PATCH] net_sched: force endianness annotation

From: Edward Cree
Date: Mon Apr 29 2019 - 07:11:28 EST


On 29/04/2019 11:44, Nicholas Mc Guire wrote:
> be16_to_cpu((__force __be16)val) should be a NOP on big-endian as well
Yes. But it's semiotically wrong to call be16_to_cpu() on a cpu-endian
Âvalue; if the existing behaviour is desired, it ought to be implemented
Âdifferently.
> The problem with using swab16 is that it is impating the binary significantly
> so I'm not sure if the change is really side-effect free
It's not; it changes the behaviour. That's why I brought up the question
Âof the intended behaviour â it's unclear whether the current (no-op on BE)
Âbehaviour is correct or whether it's a bug in the original code.
Better to leave the sparse error in place â drawing future developers'
Âattention to something being possibly wrong here â than to mask it with a
Âsynthetic 'fix' which we don't even know if it's correct or not.

> but I just am unsure if
> - val = be16_to_cpu(val);
> + val = swab16(val);
> is actually equivalent.
If you're not sure about such things, maybe you shouldn't be touching
Âendianness-related code. swab is *not* a no-op, either on BE or LE.

-Ed