Re: [RFC-PATCH] lib: add byteorder helpers for the aligned case

From: Alan Stern
Date: Fri May 16 2008 - 20:36:38 EST

On Fri, 16 May 2008, Harvey Harrison wrote:

> Some users know the pointer they are writing to are aligned,
> rather than doing *(__le16 *)ptr = cpu_to_le16(val) add helpers
> wrapping this up that have the same convention as put_unaligned_le/be.
> Signed-off-by: Harvey Harrison <harvey.harrison@xxxxxxxxx>
> ---
> Alan, as requested, I'm looking around a bit to see if there are actual
> users for this. But it does make a nice complement to the unaligned
> versions.

This is great -- thanks! I've wanted this sort of thing for a long
time. There's a good chance that the SCSI core could make use of
it. Try looking at the prep functions in sd.c and sr.c.

> +static inline void put_le16(u16 val, void *ptr)
> +{
> + *(__le16 *)ptr = cpu_to_le16(val);
> +}

Is this able to do the byte rearrangement at compile time if val is a
compile-time constant? I imagine it would.

Alan Stern

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at
Please read the FAQ at