From: Andy Shevchenko <andy.shevchenko@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: "David S. Miller" <davem@davemloft.net>,
netdev@vger.kernel.org,
Andy Shevchenko <andy.shevchenko@gmail.com>
Subject: [PATCHv1.5 3/3] net: core: use kernel's converter from hex to bin
Date: Tue, 21 Sep 2010 09:40:26 +0300 [thread overview]
Message-ID: <3998a210e172f58814e2b559f67d42c9ba78ba6a.1285051188.git.andy.shevchenko@gmail.com> (raw)
In-Reply-To: <2d00b66224535ae82be1a1e638b86b81fb890f58.1285051188.git.andy.shevchenko@gmail.com>
In-Reply-To: <2d00b66224535ae82be1a1e638b86b81fb890f58.1285051188.git.andy.shevchenko@gmail.com>
Signed-off-by: Andy Shevchenko <andy.shevchenko@gmail.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..2c0df0f 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(c);
+ 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
next prev parent reply other threads:[~2010-09-21 6:40 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-09-21 6:40 [PATCHv1.5 1/3] drivers: atm: use native kernel's hex_to_bin() func Andy Shevchenko
2010-09-21 6:40 ` [PATCHv1.5 2/3] sunrpc/cache: don't use custom hex_to_bin() converter Andy Shevchenko
[not found] ` <9ff9c1f334999e0128fe6426aaad4e9d465f310f.1285051188.git.andy.shevchenko-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2010-09-22 1:08 ` David Miller
2010-09-22 19:03 ` J. Bruce Fields
2010-09-21 6:40 ` Andy Shevchenko [this message]
2010-09-22 1:08 ` [PATCHv1.5 3/3] net: core: use kernel's converter from hex to bin David Miller
2010-09-22 1:07 ` [PATCHv1.5 1/3] drivers: atm: use native kernel's hex_to_bin() func David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3998a210e172f58814e2b559f67d42c9ba78ba6a.1285051188.git.andy.shevchenko@gmail.com \
--to=andy.shevchenko@gmail.com \
--cc=davem@davemloft.net \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).