Re: [PATCH 1/2] byteorder: add load/store_{endian} API

From: Harvey Harrison
Date: Mon Mar 02 2009 - 19:26:05 EST


On Mon, 2009-03-02 at 16:15 -0800, Linus Torvalds wrote:
>
> On Mon, 2 Mar 2009, Harvey Harrison wrote:
> >
> > store_le16 is a new API and is added to be symmetric with the unaligned
> > functions.
>
> This seems to be expressly designed to be unsafe, in that it casts the
> thing to the right type, making it impossible for sparse to warn about
> bad byteorder use.
>

Unfortunately yes, hopefully you have a solution for the problem I ran
into with this part:

This was added to be symmetric with the unaligned store API, and replace
code doing

*(__le16 *)ptr = cpu_to_le16(val);

So existing code is casting already in most of the places this could be
used. And although this could be made a static inline and get the sparse
checking, we lose one of the big advantages of the open-coding - constants
are byteswapped at compile time. Although gcc (4.4) grew support for __builtin_constant_p
in static inlines, older gcc's don't, so we would lose that with essentially
all current compilers.

So the option was to make it a static inline and get the sparse checking, or
add the cast in the macro and lose sparse checking but preserve the compile-time
swapping...maybe I chose poorly.

Thoughts?

Harvey

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/