From: Arjun Sreedharan <arjun024@gmail.com>
To: David Howells <dhowells@redhat.com>
Cc: Koichi Yasutake <yasutake.koichi@jp.panasonic.com>,
linux-am33-list@redhat.com, linux-kernel@vger.kernel.org
Subject: [PATCH] mn10300: remove redundant hex()
Date: Sun, 30 Nov 2014 16:29:21 +0530 [thread overview]
Message-ID: <1417345161-18548-1-git-send-email-arjun024@gmail.com> (raw)
replace rendundant hex() with kernel's hex_to_bin()
Signed-off-by: Arjun Sreedharan <arjun024@gmail.com>
---
arch/mn10300/kernel/gdb-stub.c | 61 ++++++++++++++++--------------------------
1 file changed, 23 insertions(+), 38 deletions(-)
diff --git a/arch/mn10300/kernel/gdb-stub.c b/arch/mn10300/kernel/gdb-stub.c
index a128c57..06adf39 100644
--- a/arch/mn10300/kernel/gdb-stub.c
+++ b/arch/mn10300/kernel/gdb-stub.c
@@ -176,27 +176,12 @@ static struct gdbstub_bkpt gdbstub_bkpts[256];
static void getpacket(char *buffer);
static int putpacket(char *buffer);
static int computeSignal(enum exception_code excep);
-static int hex(unsigned char ch);
static int hexToInt(char **ptr, int *intValue);
static unsigned char *mem2hex(const void *mem, char *buf, int count,
int may_fault);
static const char *hex2mem(const char *buf, void *_mem, int count,
int may_fault);
-/*
- * Convert ch from a hex digit to an int
- */
-static int hex(unsigned char ch)
-{
- if (ch >= 'a' && ch <= 'f')
- return ch - 'a' + 10;
- if (ch >= '0' && ch <= '9')
- return ch - '0';
- if (ch >= 'A' && ch <= 'F')
- return ch - 'A' + 10;
- return -1;
-}
-
#ifdef CONFIG_GDBSTUB_DEBUGGING
void debug_to_serial(const char *p, int n)
@@ -283,12 +268,12 @@ static void getpacket(char *buffer)
ret = gdbstub_io_rx_char(&ch, 0);
if (ret < 0)
error = ret;
- xmitcsum = hex(ch) << 4;
+ xmitcsum = hex_to_bin(ch) << 4;
ret = gdbstub_io_rx_char(&ch, 0);
if (ret < 0)
error = ret;
- xmitcsum |= hex(ch);
+ xmitcsum |= hex_to_bin(ch);
if (error) {
if (error == -EIO)
@@ -391,7 +376,7 @@ static int hexToInt(char **ptr, int *intValue)
*intValue = 0;
while (**ptr) {
- hexValue = hex(**ptr);
+ hexValue = hex_to_bin(**ptr);
if (hexValue < 0)
break;
@@ -857,8 +842,8 @@ const char *hex2mem(const char *buf, void *_mem, int count, int may_fault)
} ch;
if ((u32) mem & 1 && count >= 1) {
- ch.b[0] = hex(*buf++) << 4;
- ch.b[0] |= hex(*buf++);
+ ch.b[0] = hex_to_bin(*buf++) << 4;
+ ch.b[0] |= hex_to_bin(*buf++);
if (gdbstub_write_byte(ch.val, mem) != 0)
return 0;
mem++;
@@ -866,10 +851,10 @@ const char *hex2mem(const char *buf, void *_mem, int count, int may_fault)
}
if ((u32) mem & 3 && count >= 2) {
- ch.b[0] = hex(*buf++) << 4;
- ch.b[0] |= hex(*buf++);
- ch.b[1] = hex(*buf++) << 4;
- ch.b[1] |= hex(*buf++);
+ ch.b[0] = hex_to_bin(*buf++) << 4;
+ ch.b[0] |= hex_to_bin(*buf++);
+ ch.b[1] = hex_to_bin(*buf++) << 4;
+ ch.b[1] |= hex_to_bin(*buf++);
if (gdbstub_write_word(ch.val, mem) != 0)
return 0;
mem += 2;
@@ -877,14 +862,14 @@ const char *hex2mem(const char *buf, void *_mem, int count, int may_fault)
}
while (count >= 4) {
- ch.b[0] = hex(*buf++) << 4;
- ch.b[0] |= hex(*buf++);
- ch.b[1] = hex(*buf++) << 4;
- ch.b[1] |= hex(*buf++);
- ch.b[2] = hex(*buf++) << 4;
- ch.b[2] |= hex(*buf++);
- ch.b[3] = hex(*buf++) << 4;
- ch.b[3] |= hex(*buf++);
+ ch.b[0] = hex_to_bin(*buf++) << 4;
+ ch.b[0] |= hex_to_bin(*buf++);
+ ch.b[1] = hex_to_bin(*buf++) << 4;
+ ch.b[1] |= hex_to_bin(*buf++);
+ ch.b[2] = hex_to_bin(*buf++) << 4;
+ ch.b[2] |= hex_to_bin(*buf++);
+ ch.b[3] = hex_to_bin(*buf++) << 4;
+ ch.b[3] |= hex_to_bin(*buf++);
if (gdbstub_write_dword(ch.val, mem) != 0)
return 0;
mem += 4;
@@ -892,10 +877,10 @@ const char *hex2mem(const char *buf, void *_mem, int count, int may_fault)
}
if (count >= 2) {
- ch.b[0] = hex(*buf++) << 4;
- ch.b[0] |= hex(*buf++);
- ch.b[1] = hex(*buf++) << 4;
- ch.b[1] |= hex(*buf++);
+ ch.b[0] = hex_to_bin(*buf++) << 4;
+ ch.b[0] |= hex_to_bin(*buf++);
+ ch.b[1] = hex_to_bin(*buf++) << 4;
+ ch.b[1] |= hex_to_bin(*buf++);
if (gdbstub_write_word(ch.val, mem) != 0)
return 0;
mem += 2;
@@ -903,8 +888,8 @@ const char *hex2mem(const char *buf, void *_mem, int count, int may_fault)
}
if (count >= 1) {
- ch.b[0] = hex(*buf++) << 4;
- ch.b[0] |= hex(*buf++);
+ ch.b[0] = hex_to_bin(*buf++) << 4;
+ ch.b[0] |= hex_to_bin(*buf++);
if (gdbstub_write_byte(ch.val, mem) != 0)
return 0;
}
--
1.7.11.7
next reply other threads:[~2014-11-30 10:59 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-30 10:59 Arjun Sreedharan [this message]
2015-01-26 17:19 ` [PATCH] mn10300: remove redundant hex() Arjun Sreedharan
2015-01-27 10:49 ` Paul Bolle
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=1417345161-18548-1-git-send-email-arjun024@gmail.com \
--to=arjun024@gmail.com \
--cc=dhowells@redhat.com \
--cc=linux-am33-list@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=yasutake.koichi@jp.panasonic.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.