Commit 82fd5b5d authored by Andy Shevchenko's avatar Andy Shevchenko Committed by David S. Miller

net: core: use kernel's converter from hex to bin

Signed-off-by: default avatarAndy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 66bb16de
...@@ -729,16 +729,14 @@ static int hex32_arg(const char __user *user_buffer, unsigned long maxlen, ...@@ -729,16 +729,14 @@ static int hex32_arg(const char __user *user_buffer, unsigned long maxlen,
*num = 0; *num = 0;
for (; i < maxlen; i++) { for (; i < maxlen; i++) {
int value;
char c; char c;
*num <<= 4; *num <<= 4;
if (get_user(c, &user_buffer[i])) if (get_user(c, &user_buffer[i]))
return -EFAULT; return -EFAULT;
if ((c >= '0') && (c <= '9')) value = hex_to_bin(c);
*num |= c - '0'; if (value >= 0)
else if ((c >= 'a') && (c <= 'f')) *num |= value;
*num |= c - 'a' + 10;
else if ((c >= 'A') && (c <= 'F'))
*num |= c - 'A' + 10;
else else
break; break;
} }
......
...@@ -92,18 +92,19 @@ EXPORT_SYMBOL(in_aton); ...@@ -92,18 +92,19 @@ EXPORT_SYMBOL(in_aton);
static inline int xdigit2bin(char c, int delim) static inline int xdigit2bin(char c, int delim)
{ {
int val;
if (c == delim || c == '\0') if (c == delim || c == '\0')
return IN6PTON_DELIM; return IN6PTON_DELIM;
if (c == ':') if (c == ':')
return IN6PTON_COLON_MASK; return IN6PTON_COLON_MASK;
if (c == '.') if (c == '.')
return IN6PTON_DOT; return IN6PTON_DOT;
if (c >= '0' && c <= '9')
return (IN6PTON_XDIGIT | IN6PTON_DIGIT| (c - '0')); val = hex_to_bin(c);
if (c >= 'a' && c <= 'f') if (val >= 0)
return (IN6PTON_XDIGIT | (c - 'a' + 10)); return val | IN6PTON_XDIGIT | (val < 10 ? IN6PTON_DIGIT : 0);
if (c >= 'A' && c <= 'F')
return (IN6PTON_XDIGIT | (c - 'A' + 10));
if (delim == -1) if (delim == -1)
return IN6PTON_DELIM; return IN6PTON_DELIM;
return IN6PTON_UNKNOWN; return IN6PTON_UNKNOWN;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment