diff options
-rw-r--r-- | include/linux/kernel.h | 2 | ||||
-rw-r--r-- | lib/hexdump.c | 15 |
2 files changed, 12 insertions, 5 deletions
diff --git a/include/linux/kernel.h b/include/linux/kernel.h index 46ac9a50528d..8eefcf7e95eb 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h | |||
@@ -382,7 +382,7 @@ static inline char *pack_hex_byte(char *buf, u8 byte) | |||
382 | } | 382 | } |
383 | 383 | ||
384 | extern int hex_to_bin(char ch); | 384 | extern int hex_to_bin(char ch); |
385 | extern void hex2bin(u8 *dst, const char *src, size_t count); | 385 | extern int __must_check hex2bin(u8 *dst, const char *src, size_t count); |
386 | 386 | ||
387 | /* | 387 | /* |
388 | * General tracing related utility functions - trace_printk(), | 388 | * General tracing related utility functions - trace_printk(), |
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); | |||
38 | * @dst: binary result | 38 | * @dst: binary result |
39 | * @src: ascii hexadecimal string | 39 | * @src: ascii hexadecimal string |
40 | * @count: result length | 40 | * @count: result length |
41 | * | ||
42 | * Return 0 on success, -1 in case of bad input. | ||
41 | */ | 43 | */ |
42 | void hex2bin(u8 *dst, const char *src, size_t count) | 44 | int hex2bin(u8 *dst, const char *src, size_t count) |
43 | { | 45 | { |
44 | while (count--) { | 46 | while (count--) { |
45 | *dst = hex_to_bin(*src++) << 4; | 47 | int hi = hex_to_bin(*src++); |
46 | *dst += hex_to_bin(*src++); | 48 | int lo = hex_to_bin(*src++); |
47 | dst++; | 49 | |
50 | if ((hi < 0) || (lo < 0)) | ||
51 | return -1; | ||
52 | |||
53 | *dst++ = (hi << 4) | lo; | ||
48 | } | 54 | } |
55 | return 0; | ||
49 | } | 56 | } |
50 | EXPORT_SYMBOL(hex2bin); | 57 | EXPORT_SYMBOL(hex2bin); |
51 | 58 | ||