Re: [PATCH] NTB: ntb_perf: fix cast to restricted __le32

From: Arnd Bergmann
Date: Fri Jan 19 2018 - 15:42:30 EST


On Fri, Jan 19, 2018 at 6:30 PM, Serge Semin <fancer.lancer@xxxxxxxxx> wrote:
> Sparse is whining about the u32 and __le32 mixed usage in the
> driver.
>
> drivers/ntb/test/ntb_perf.c:288:21: warning: cast to restricted __le32
> drivers/ntb/test/ntb_perf.c:295:37: warning: incorrect type in argument 4 (different base types)
> drivers/ntb/test/ntb_perf.c:295:37: expected unsigned int [unsigned] [usertype] val
> drivers/ntb/test/ntb_perf.c:295:37: got restricted __le32 [usertype] <noident>
> ...
>
> The NTB API can't be changed so ntb_spad_*() methods
> would return either pure __le32 or __be32, since the scratchpad
> data can have arbitrary endianness in general. In this case we
> need to forcibly cast all the u32 to be __le32 and vise-versa
> where it's supposed to be in accordance with the driver logic.
>

There's got to be a better way to do this than sprinkling lots of __force
typecasts throughout the code.

It looks like all those casts are about
ntb_peer_spad_read()/ntb_peer_msg_write() calls, so why not change
those function prototypes to work on __le32 types?

There should also be some form of documentation regarding why you
need to swap the data twice, since all the ntb drivers later end up
doing another cpu_to_le32() on the little-endian data.

Arnd