Re: [RFC][PATCH 2/5] lib: add error checking to hex2bin

From: Andrew Morton
Date: Mon Sep 19 2011 - 17:20:58 EST


On Fri, 16 Sep 2011 08:50:27 -0400
Mimi Zohar <zohar@xxxxxxxxxxxxxxxxxx> wrote:

> --- a/lib/hexdump.c
> +++ b/lib/hexdump.c
> @@ -38,14 +38,17 @@ EXPORT_SYMBOL(hex_to_bin);
> * @dst: binary result
> * @src: ascii hexadecimal string
> * @count: result length
> + *
> + * Returns true on success, false in case of bad input.
> */
> -void hex2bin(u8 *dst, const char *src, size_t count)
> +bool hex2bin(u8 *dst, const char *src, size_t count)
> {
> while (count--) {
> - *dst = hex_to_bin(*src++) << 4;
> - *dst += hex_to_bin(*src++);
> - dst++;
> + if (!unpack_hex_byte(dst++, src))
> + return false;
> + src += 2;
> }
> + return true;
> }
> EXPORT_SYMBOL(hex2bin);

Again, this is very unconventional for kernel code, and it's for no good
reason. Please, stick with 0/-1 unless there's a good reason to diverge
from that.
--
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/