]> git.baikalelectronics.ru Git - kernel.git/commitdiff
net: core: use kernel's converter from hex to bin
authorAndy Shevchenko <andy.shevchenko@gmail.com>
Mon, 20 Sep 2010 20:40:26 +0000 (20:40 +0000)
committerDavid S. Miller <davem@davemloft.net>
Wed, 22 Sep 2010 01:04:45 +0000 (18:04 -0700)
Signed-off-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/core/pktgen.c
net/core/utils.c

index 386c2283f14ec580824e8cac355b7da568259abc..2c0df0f95b3d488c8e6f8818857f19c02726e200 100644 (file)
@@ -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(c);
+               if (value >= 0)
+                       *num |= value;
                else
                        break;
        }
index f41854470539855adee387a4c488f4be66a017a2..ec6bb322f3722f8e4070e7eb66ddbc5d2a88548b 100644 (file)
@@ -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;