Re: [RFC][PATCH 1/5] lib: add unpack_hex_byte()

From: Andy Shevchenko
Date: Fri Sep 16 2011 - 09:11:20 EST


On Fri, Sep 16, 2011 at 3:50 PM, Mimi Zohar <zohar@xxxxxxxxxxxxxxxxxx> wrote:
> Since converting 2 ascii hex digits into a byte with error checks
> is commonly used, we can replace multiple hex_to_bin() calls with
> a single call to unpack_hex_byte().
>
> Changelog:
> - Error checking added based on Tetsuo Handa's patch.
> - Moved the hex2bin code here, making it into a static inline function.
> Â(Andy Shevchenko's request.)
>
> Signed-off-by: Mimi Zohar <zohar@xxxxxxxxxxxxxxxxxx>
> ---
> Âinclude/linux/kernel.h | Â 21 +++++++++++++++++++++
> Â1 files changed, 21 insertions(+), 0 deletions(-)
>
> diff --git a/include/linux/kernel.h b/include/linux/kernel.h
> index 46ac9a5..d8ea13b 100644
> --- a/include/linux/kernel.h
> +++ b/include/linux/kernel.h
> @@ -385,6 +385,27 @@ extern int hex_to_bin(char ch);
> Âextern void hex2bin(u8 *dst, const char *src, size_t count);
>
> Â/*
> + * unpack_hex_byte - convert 2 asii hex digits into a byte
> + * @byte: binary result
> + * @buf: ascii hexadecimal byte string
> + */
> +static inline bool unpack_hex_byte(u8 *byte, const char *buf)
> +{
> + Â Â Â int hi, lo;
> +
> + Â Â Â hi = hex_to_bin(buf[0]);
> + Â Â Â if (hi < 0)
> + Â Â Â Â Â Â Â return false;
> +
> + Â Â Â lo = hex_to_bin(buf[1]);
> + Â Â Â if (lo < 0)
> + Â Â Â Â Â Â Â return false;
> +
> + Â Â Â *byte = (hi << 4) | lo;
> + Â Â Â return true;
> +}
> +
> +/*
> Â* General tracing related utility functions - trace_printk(),
> Â* tracing_on/tracing_off and tracing_start()/tracing_stop
> Â*

Acked-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>

--
With Best Regards,
Andy Shevchenko
--
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/