LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] mn10300: remove redundant hex()
@ 2014-11-30 10:59 Arjun Sreedharan
  2015-01-26 17:19 ` Arjun Sreedharan
  0 siblings, 1 reply; 3+ messages in thread
From: Arjun Sreedharan @ 2014-11-30 10:59 UTC (permalink / raw)
  To: David Howells; +Cc: Koichi Yasutake, linux-am33-list, linux-kernel

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mn10300: remove redundant hex()
  2014-11-30 10:59 [PATCH] mn10300: remove redundant hex() Arjun Sreedharan
@ 2015-01-26 17:19 ` Arjun Sreedharan
  2015-01-27 10:49   ` Paul Bolle
  0 siblings, 1 reply; 3+ messages in thread
From: Arjun Sreedharan @ 2015-01-26 17:19 UTC (permalink / raw)
  To: David Howells; +Cc: Koichi Yasutake, linux-am33-list, linux-kernel

Ping !!

On 30 November 2014 at 16:29, Arjun Sreedharan <arjun024@gmail.com> wrote:
> 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
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mn10300: remove redundant hex()
  2015-01-26 17:19 ` Arjun Sreedharan
@ 2015-01-27 10:49   ` Paul Bolle
  0 siblings, 0 replies; 3+ messages in thread
From: Paul Bolle @ 2015-01-27 10:49 UTC (permalink / raw)
  To: Arjun Sreedharan
  Cc: David Howells, Koichi Yasutake, linux-am33-list, linux-kernel

Arjun,

On Mon, 2015-01-26 at 22:49 +0530, Arjun Sreedharan wrote:
> Ping !!

I wouldn't hold my breath waiting for any response, if I were you.

> On 30 November 2014 at 16:29, Arjun Sreedharan <arjun024@gmail.com> wrote:
> > 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(-)

You can't actually build a mn10300 kernel with GDBSTUB set since
v2.6.39, see https://lkml.org/lkml/2014/9/18/387 . Perhaps you still
managed to build arch/mn10300/kernel/gdb-stub.o manually, bypassing
kconfig. Or did you just edit out its dependency on DEPRECATED?


Paul Bolle


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-01-27 10:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-30 10:59 [PATCH] mn10300: remove redundant hex() Arjun Sreedharan
2015-01-26 17:19 ` Arjun Sreedharan
2015-01-27 10:49   ` Paul Bolle

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).