[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <73beeb8a098468e777af27fe3f7950881cdb394b.1285024850.git.andy.shevchenko@gmail.com>
Date: Tue, 21 Sep 2010 02:27:08 +0300
From: Andy Shevchenko <andy.shevchenko@...il.com>
To: linux-kernel@...r.krenel.org
Cc: "David S. Miller" <davem@...emloft.net>, netdev@...r.kernel.org,
Andy Shevchenko <andy.shevchenko@...il.com>
Subject: [PATCH 3/3] net: core: use kernel's converter from hex to bin
Signed-off-by: Andy Shevchenko <andy.shevchenko@...il.com>
---
net/core/pktgen.c | 10 ++++------
net/core/utils.c | 13 +++++++------
2 files changed, 11 insertions(+), 12 deletions(-)
diff --git a/net/core/pktgen.c b/net/core/pktgen.c
index 386c228..168e3b6 100644
--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -729,16 +729,14 @@ static int hex32_arg(const char __user *user_buffer, unsigned long maxlen,
*num = 0;
for (; i < maxlen; i++) {
+ int value;
char c;
*num <<= 4;
if (get_user(c, &user_buffer[i]))
return -EFAULT;
- if ((c >= '0') && (c <= '9'))
- *num |= c - '0';
- else if ((c >= 'a') && (c <= 'f'))
- *num |= c - 'a' + 10;
- else if ((c >= 'A') && (c <= 'F'))
- *num |= c - 'A' + 10;
+ value = hex_to_bin(*num);
+ if (value >= 0)
+ *num |= value;
else
break;
}
diff --git a/net/core/utils.c b/net/core/utils.c
index f418544..ec6bb32 100644
--- a/net/core/utils.c
+++ b/net/core/utils.c
@@ -92,18 +92,19 @@ EXPORT_SYMBOL(in_aton);
static inline int xdigit2bin(char c, int delim)
{
+ int val;
+
if (c == delim || c == '\0')
return IN6PTON_DELIM;
if (c == ':')
return IN6PTON_COLON_MASK;
if (c == '.')
return IN6PTON_DOT;
- if (c >= '0' && c <= '9')
- return (IN6PTON_XDIGIT | IN6PTON_DIGIT| (c - '0'));
- if (c >= 'a' && c <= 'f')
- return (IN6PTON_XDIGIT | (c - 'a' + 10));
- if (c >= 'A' && c <= 'F')
- return (IN6PTON_XDIGIT | (c - 'A' + 10));
+
+ val = hex_to_bin(c);
+ if (val >= 0)
+ return val | IN6PTON_XDIGIT | (val < 10 ? IN6PTON_DIGIT : 0);
+
if (delim == -1)
return IN6PTON_DELIM;
return IN6PTON_UNKNOWN;
--
1.7.2.2
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Powered by blists - more mailing lists