Re: [RFC PATCH] lib: add ascii hex helper functions

From: Andrew Morton
Date: Mon May 05 2008 - 17:58:23 EST


On Sat, 03 May 2008 12:27:27 -0700
Harvey Harrison <harvey.harrison@xxxxxxxxx> wrote:

> Everyone rolls their own version around the tree, centralize
> in lib/hexdump.c. Move the only existing users of hex_asc over
> to the hi/lo helpers.
>
> Add helpers for reading binary values from a stream of hex chars.
> Most existing users want to know how many chars were read as well.
> This implementation chooses to return the number of chars read
> and takes a pointer to the value being read.
>
> As an alternative, a char **buf could be passed and the value could
> be returned and the pointer updated by reference.
>
> Fixed size helpers for u8, u16, u32 and u64 have been added with
> another helper that takes an argument specifying the max number of
> chars to read (capped to the size that will fit in an unsigned long)
>
> Signed-off-by: Harvey Harrison <harvey.harrison@xxxxxxxxx>
> ---
> Andrew, I've thought a little more about this, It's possible we could
> get away without the u8/u16 helpers, but it does make the api nicely
> complete, and they are pretty small. Most users really want to read
> a long or an int, but many can be move to the u32/u64 versions to
> tighten up implicit assumptions being made about the length being
> read.

hex_to_val() is distressingly similar to simple_strtoul(..., ..., 16).

> I'll wait for coment before fixing the previous series of patches to
> use these.

I'm all worn out on this one.
--
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/