Skip to contentSkip to conversation

lib/hexdump.c: return -EINVAL in case of error in hex2bin()

PATCH New [email protected] 1 participant 1 message Sep 8, 2017 Library code

lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

PATCH 82/126 lib/hexdump.c: return -EINVAL in case of error in hex2bin()

From: Andy Shevchenko <[email protected]>
Subject: lib/hexdump.c: return -EINVAL in case of error in hex2bin()

In some cases caller would like to use error code directly without shadowing.

-EINVAL feels a rightful code to return in case of error in hex2bin().

---

 lib/hexdump.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
lib/hexdump.c renamed from lib/hexdump.c~lib-hexdump-return-einval-in-case-of-error-in-hex2bin +3 -2
diff -puN lib/hexdump.c~lib-hexdump-return-einval-in-case-of-error-in-hex2bin lib/hexdump.c
@@ -9,6 +9,7 @@
 
 #include <linux/types.h>
 #include <linux/ctype.h>
+#include <linux/errno.h>
 #include <linux/kernel.h>
 #include <linux/export.h>
 #include <asm/unaligned.h>
@@ -42,7 +43,7 @@ EXPORT_SYMBOL(hex_to_bin);
  * @src: ascii hexadecimal string
  * @count: result length
  *
- * Return 0 on success, -1 in case of bad input.
+ * Return 0 on success, -EINVAL in case of bad input.
  */
 int hex2bin(u8 *dst, const char *src, size_t count)
 {
@@ -51,7 +52,7 @@ int hex2bin(u8 *dst, const char *src, si
 		int lo = hex_to_bin(*src++);
 
 		if ((hi < 0) || (lo < 0))
-			return -1;
+			return -EINVAL;
 
 		*dst++ = (hi << 4) | lo;
 	}

_