Skip to contentSkip to conversation

arch: mips: use newly introduced hex_to_bin()

PATCH Applied Andy Shevchenko 3 participants 4 messages Sep 11, 2010 – May 19, 2011 MIPS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arch: mips: use newly introduced hex_to_bin()

Remove custom implementation of hex_to_bin().

---
 arch/mips/rb532/devices.c |   24 +++++++++---------------
 1 files changed, 9 insertions(+), 15 deletions(-)
arch/mips/rb532/devices.c +9 -15
index 041fc1a..a969eb8 100644
@@ -251,28 +251,22 @@ static struct platform_device *rb532_devs[] = {
 
 static void __init parse_mac_addr(char *macstr)
 {
-	int i, j;
-	unsigned char result, value;
+	int i, h, l;
 
 	for (i = 0; i < 6; i++) {
-		result = 0;
-
 		if (i != 5 && *(macstr + 2) != ':')
 			return;
 
-		for (j = 0; j < 2; j++) {
-			if (isxdigit(*macstr)
-			    && (value =
-				isdigit(*macstr) ? *macstr -
-				'0' : toupper(*macstr) - 'A' + 10) < 16) {
-				result = result * 16 + value;
-				macstr++;
-			} else
-				return;
-		}
+		h = hex_to_bin(*macstr++);
+		if (h == -1)
+			return;
+
+		l = hex_to_bin(*macstr++);
+		if (l == -1)
+			return;
 
 		macstr++;
-		korina_dev0_data.mac[i] = result;
+		korina_dev0_data.mac[i] = (h << 4) + l;
 	}
 }
 
Signature · 1 line
1.7.2.2
#1 lore raw

Any comments here?

Quoted 55 lines · Andy Shevchenko

Remove custom implementation of hex_to_bin().

---
 arch/mips/rb532/devices.c |   24 +++++++++---------------

 1 files changed, 9 insertions(+), 15 deletions(-)
arch/mips/rb532/devices.c +9 -16
index 041fc1a..a969eb8 100644
@@ -251,28 +251,22 @@ static struct platform_device *rb532_devs[] = {
 
  static void __init parse_mac_addr(char *macstr)
  {
-       int i, j;
-       unsigned char result, value;
+       int i, h, l;
 
        for (i = 0; i < 6; i++) {
-               result = 0;
-
                if (i != 5 && *(macstr + 2) != ':')
                        return;
 
-               for (j = 0; j < 2; j++) {
-                       if (isxdigit(*macstr)
-                           && (value =
-                               isdigit(*macstr) ? *macstr -
-                               '0' : toupper(*macstr) - 'A' + 10) < 16) {
-                               result = result * 16 + value;
-                               macstr++;
-                       } else
-                               return;
-               }
+               h = hex_to_bin(*macstr++);
+               if (h == -1)
+                       return;
+
+               l = hex_to_bin(*macstr++);
+               if (l == -1)
+                       return;
 
                macstr++;
-               korina_dev0_data.mac[i] = result;
+               korina_dev0_data.mac[i] = (h << 4) + l;
        }
  }
 
--

1.7.2.2

Signature · 3 lines
With Best Regards,
Andy Shevchenko
���{.n�+�������+%�����ݶ��w��{.n�+����{��G�����{ay�ʇڙ�,j��f���h��������z_�(�階�ݢj"���m������G������?����&���~��iO��z��v�^�m����������?�I�
#2 lore raw
Quoted 1 line · Andy Shevchenko

Any comments here?

Quoted 57 lines

On Sat, Sep 11, 2010 at 4:33 PM, Andy Shevchenko

Quoted 53 lines · <[email protected]> wrote:

Remove custom implementation of hex_to_bin().

---
 arch/mips/rb532/devices.c |   24 +++++++++---------------
 1 files changed, 9 insertions(+), 15 deletions(-)
arch/mips/rb532/devices.c +9 -15
index 041fc1a..a969eb8 100644
@@ -251,28 +251,22 @@ static struct platform_device *rb532_devs[] = {
 
 static void __init parse_mac_addr(char *macstr)
 {
-       int i, j;
-       unsigned char result, value;
+       int i, h, l;
 
       for (i = 0; i < 6; i++) {
-               result = 0;
-
               if (i != 5 && *(macstr + 2) != ':')
                       return;
 
-               for (j = 0; j < 2; j++) {
-                       if (isxdigit(*macstr)
-                           && (value =
-                               isdigit(*macstr) ? *macstr -
-                               '0' : toupper(*macstr) - 'A' + 10) < 16)
 { -                               result = result * 16 + value;
-                               macstr++;
-                       } else
-                               return;
-               }
+               h = hex_to_bin(*macstr++);
+               if (h == -1)
+                       return;
+
+               l = hex_to_bin(*macstr++);
+               if (l == -1)
+                       return;
 
               macstr++;
-               korina_dev0_data.mac[i] = result;
+               korina_dev0_data.mac[i] = (h << 4) + l;
       }
 }
 
--

1.7.2.2