From: Harvey Harrison <harvey.harrison@gmail.com>
To: Geert Uytterhoeven <Geert.Uytterhoeven@sonycom.com>
Cc: Pavel Machek <pavel@ucw.cz>,
Andrew Morton <akpm@linux-foundation.org>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: byteorder helpers and void * (was: Re: [PATCH 01/21] lib: add byteorder helpers for the aligned case)
Date: Tue, 24 Jun 2008 19:35:37 -0700 [thread overview]
Message-ID: <1214361338.21092.71.camel@brick> (raw)
In-Reply-To: <Pine.LNX.4.64.0806241445430.17853@vixen.sonytel.be>
On Tue, 2008-06-24 at 14:54 +0200, Geert Uytterhoeven wrote:
> >
> > Document the fact that void * passed in needs to be 16-bit aligned?
>
> Why not let it just take a __le16 *? Because in many use-cases the pointer just
> points to an array of bytes?
>
> For the unaligned case, e.g. get_unaligned_le16(), I can understand a bit the
> rationale about using void * (a typical use-case is accessing a little endian
> 16-bit value in the middle of an arrays of bytes).
>
> However, a disadvantage is that you remove the ability of the compiler to check
> for using the wrong accessor in a (packed for the unaligned case) struct, e.g.
>
> struct {
> u8 pad;
> __le16 val; /* 16-bit value */
> } __attribute ((packed)) s;
>
> x = get_unaligned_le32(&s.val); /* oops, 32-bit access */
>
I'm starting to come around to the typechecking argument. This would
also be a chance to fix the argument ordering in put_analigned_XXXX
that was noticed by others. As there are already some existing users
in-tree, we could transition gradually by:
1) Introduce typed versions of get/put_unaligned_XXXX, that implies the
byteswap better:
u16 load_unaligned_le16(__le16 *)
void store_unaligned_le16(__le16 *, u16)
Then the aligned helpers could be:
le16_to_cpup -> aligned equivalent of load_unaligned_le16
store_le16(__le16 *, u16)
Implemented as (to allow constant folding)
#define store_le16(ptr, val) (*(__le16 *)(ptr) = cpu_to_le16((u16)(val)))
> I noticed there's also a __get_unaligned_le(), which uses compile-time
> detection of the pointer time, to make sure the correct accessor is used.
> Do you intend this to be used by generic code? It's function name starts
> with double underscore, indicating otherwise.
It is not meant for generic use, it is just there as a helper for each
arch to wire up it's get_unaligned() macro depending on its endianness,
so each arch doesn't wire up its own version that may or may not have
the size checking.
Anything I missed?
Harvey
next prev parent reply other threads:[~2008-06-25 2:35 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-05-20 18:05 [PATCH 01/21] lib: add byteorder helpers for the aligned case Harvey Harrison
2008-05-23 13:13 ` Pavel Machek
2008-06-24 12:54 ` byteorder helpers and void * (was: Re: [PATCH 01/21] lib: add byteorder helpers for the aligned case) Geert Uytterhoeven
2008-06-25 2:35 ` Harvey Harrison [this message]
2008-06-25 11:20 ` Geert Uytterhoeven
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1214361338.21092.71.camel@brick \
--to=harvey.harrison@gmail.com \
--cc=Geert.Uytterhoeven@sonycom.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pavel@ucw.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox