Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1700069 > unrolled thread

[PATCH v1] lib/hexdump: Return -EINVAL in case of error in hex2bin()

Started byAndy Shevchenko <andriy.shevchenko@linux.intel.com>
First post2017-07-31 16:00 +0200
Last post2017-07-31 16:00 +0200
Articles 1 — 1 participant

Back to article view | Back to linux.kernel


Contents

  [PATCH v1] lib/hexdump: Return -EINVAL in case of error in hex2bin() Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2017-07-31 16:00 +0200

#1700069 — [PATCH v1] lib/hexdump: Return -EINVAL in case of error in hex2bin()

FromAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Date2017-07-31 16:00 +0200
Subject[PATCH v1] lib/hexdump: Return -EINVAL in case of error in hex2bin()
Message-ID<u9joJ-6Xr-9@gated-at.bofh.it>
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().

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 lib/hexdump.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lib/hexdump.c b/lib/hexdump.c
index 992457b1284c..81b70ed37209 100644
--- a/lib/hexdump.c
+++ b/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, size_t count)
 		int lo = hex_to_bin(*src++);
 
 		if ((hi < 0) || (lo < 0))
-			return -1;
+			return -EINVAL;
 
 		*dst++ = (hi << 4) | lo;
 	}
-- 
2.13.2

[toc] | [standalone]


Back to top | Article view | linux.kernel


csiph-web