diff options
| author | James Morris <jmorris@namei.org> | 2011-09-27 09:20:46 +1000 |
|---|---|---|
| committer | James Morris <jmorris@namei.org> | 2011-09-27 09:20:46 +1000 |
| commit | c6cb56fc94f4efaec2d4ad74bed2be7883179ccd (patch) | |
| tree | cc4ebf2231093ab57c2e868fbdf176791de600db /lib | |
| parent | a427fd14d3edf6396c4b9638dbc8e2972afaa05b (diff) | |
| parent | 8c35ad20270de91d0f3bfe521daa3b7983ee8db7 (diff) | |
Merge branch 'next-hex2bin' of git://github.com/mzohar/linux-evm into next
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/hexdump.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/hexdump.c b/lib/hexdump.c index f5fe6ba7a3ab..51d5ae210244 100644 --- a/lib/hexdump.c +++ b/lib/hexdump.c @@ -38,14 +38,21 @@ EXPORT_SYMBOL(hex_to_bin); * @dst: binary result * @src: ascii hexadecimal string * @count: result length + * + * Return 0 on success, -1 in case of bad input. */ -void hex2bin(u8 *dst, const char *src, size_t count) +int hex2bin(u8 *dst, const char *src, size_t count) { while (count--) { - *dst = hex_to_bin(*src++) << 4; - *dst += hex_to_bin(*src++); - dst++; + int hi = hex_to_bin(*src++); + int lo = hex_to_bin(*src++); + + if ((hi < 0) || (lo < 0)) + return -1; + + *dst++ = (hi << 4) | lo; } + return 0; } EXPORT_SYMBOL(hex2bin); |
