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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 target-devel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux SCSI]     [Kernel Newbies]     [Linux SCSI Target Infrastructure]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Linux IIO]     [Device Mapper]

  Powered by Linux