mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andy Shevchenko <andy.shevchenko@gmail.com>
To: linux-kernel@vger.kernel.org, Greg Kroah-Hartman <gregkh@suse.de>,
	devel@driverdev.osuosl.org
Cc: Andy Shevchenko <andy.shevchenko@gmail.com>
Subject: [PATCH 2/2] staging: ath6kl: use native methods from kernel library
Date: Tue,  7 Sep 2010 18:20:22 +0300	[thread overview]
Message-ID: <8b251244717765e795b92a1f7335f8af98e5706f.1283872748.git.andy.shevchenko@gmail.com> (raw)
In-Reply-To: <09b7da2e5462e0b855617ff5308ed6efb4fc9cab.1283872748.git.andy.shevchenko@gmail.com>
In-Reply-To: <09b7da2e5462e0b855617ff5308ed6efb4fc9cab.1283872748.git.andy.shevchenko@gmail.com>

There are already implemented methods such hex_to_bin() or isxdigit() in
the kernel. Let's use them.

Signed-off-by: Andy Shevchenko <andy.shevchenko@gmail.com>
---
 .../staging/ath6kl/miscdrv/ar3kps/ar3kpsparser.c   |   31 ++++++-------------
 drivers/staging/ath6kl/os/linux/eeprom.c           |   32 +++++++++----------
 2 files changed, 25 insertions(+), 38 deletions(-)

diff --git a/drivers/staging/ath6kl/miscdrv/ar3kps/ar3kpsparser.c b/drivers/staging/ath6kl/miscdrv/ar3kps/ar3kpsparser.c
index 5eed8ac..8dce054 100644
--- a/drivers/staging/ath6kl/miscdrv/ar3kps/ar3kpsparser.c
+++ b/drivers/staging/ath6kl/miscdrv/ar3kps/ar3kpsparser.c
@@ -27,6 +27,9 @@
 
 #include "ar3kpsparser.h"
 
+#include <linux/ctype.h>
+#include <linux/kernel.h>
+
 #define BD_ADDR_SIZE            6
 #define WRITE_PATCH             8
 #define ENABLE_PATCH            11
@@ -61,20 +64,6 @@
 #define MAX_BYTE_LENGTH                   244
 
 #define SKIP_BLANKS(str) while (*str == ' ') str++
-#define MIN(x, y) (((x) <= (y))? (x):(y))
-#define MAX(x, y) (((x) >= (y))? (x):(y))
-
-#define UNUSED(x) (x=x)
-
-#define IS_BETWEEN(x, lower, upper) (((lower) <= (x)) && ((x) <= (upper)))
-#define IS_DIGIT(c) (IS_BETWEEN((c), '0', '9'))
-#define IS_HEX(c)   (IS_BETWEEN((c), '0', '9') || IS_BETWEEN((c), 'a', 'f') || IS_BETWEEN((c), 'A', 'F'))
-#define TO_LOWER(c) (IS_BETWEEN((c), 'A', 'Z') ? ((c) - 'A' + 'a') : (c))
-#define IS_BLANK(c) ((c) == ' ')
-#define CONV_DEC_DIGIT_TO_VALUE(c) ((c) - '0')
-#define CONV_HEX_DIGIT_TO_VALUE(c) (IS_DIGIT(c) ? ((c) - '0') : (IS_BETWEEN((c), 'A', 'Z') ? ((c) - 'A' + 10) : ((c) - 'a' + 10))) 
-#define CONV_VALUE_TO_HEX(v) ((A_UINT8)( ((v & 0x0F) <= 9) ? ((v & 0x0F) + '0') : ((v & 0x0F) - 10 + 'A') ) )
-
 
 enum MinBootFileFormatE
 {
@@ -483,12 +472,12 @@ A_STATUS AthParseFilesUnified(A_UCHAR *srcbuffer,A_UINT32 srclen, int FileFormat
                     if((stPS_DataFormat.eDataType == eHex) && stPS_DataFormat.bIsArray == true) {
                        while(uReadCount > 0) {
                            PsTagEntry[TagCount].TagData[stReadStatus.uByteCount] =
-                                                     (A_UINT8)(CONV_HEX_DIGIT_TO_VALUE(pCharLine[stReadStatus.uCharCount]) << 4)
-                                                     | (A_UINT8)(CONV_HEX_DIGIT_TO_VALUE(pCharLine[stReadStatus.uCharCount + 1]));
+                                                     (A_UINT8)(hex_to_bin(pCharLine[stReadStatus.uCharCount]) << 4)
+                                                     | (A_UINT8)(hex_to_bin(pCharLine[stReadStatus.uCharCount + 1]));
 
                            PsTagEntry[TagCount].TagData[stReadStatus.uByteCount+1] =
-                                                     (A_UINT8)(CONV_HEX_DIGIT_TO_VALUE(pCharLine[stReadStatus.uCharCount + 3]) << 4)
-                                                     | (A_UINT8)(CONV_HEX_DIGIT_TO_VALUE(pCharLine[stReadStatus.uCharCount + 4]));
+                                                     (A_UINT8)(hex_to_bin(pCharLine[stReadStatus.uCharCount + 3]) << 4)
+                                                     | (A_UINT8)(hex_to_bin(pCharLine[stReadStatus.uCharCount + 4]));
 
                            stReadStatus.uCharCount += 6; // read two bytes, plus a space;
                            stReadStatus.uByteCount += 2;
@@ -574,14 +563,14 @@ A_STATUS GetNextTwoChar(A_UCHAR *srcbuffer,A_UINT32 len, A_UINT32 *pos, char * b
     unsigned char ch;
 
     ch = AthReadChar(srcbuffer,len,pos);
-    if(ch != '\0' && IS_HEX(ch)) {
+    if(ch != '\0' && isxdigit(ch)) {
         buffer[0] =  ch;
     } else 
     {
         return A_ERROR;
     }
     ch = AthReadChar(srcbuffer,len,pos);
-    if(ch != '\0' && IS_HEX(ch)) {
+    if(ch != '\0' && isxdigit(ch)) {
         buffer[1] =  ch;
     } else 
     {
@@ -606,7 +595,7 @@ A_STATUS AthDoParsePatch(A_UCHAR *patchbuffer, A_UINT32 patchlen)
     Patch_Count = 0;
 
     while(NULL != AthGetLine(Line,MAX_BYTE_LENGTH,patchbuffer,patchlen,&filepos)) {
-        if(strlen(Line) <= 1 || !IS_HEX(Line[0])) {
+        if(strlen(Line) <= 1 || !isxdigit(Line[0])) {
             continue;
         } else {
             break;
diff --git a/drivers/staging/ath6kl/os/linux/eeprom.c b/drivers/staging/ath6kl/os/linux/eeprom.c
index 8dd130a..be77fb8 100644
--- a/drivers/staging/ath6kl/os/linux/eeprom.c
+++ b/drivers/staging/ath6kl/os/linux/eeprom.c
@@ -71,24 +71,22 @@ wmic_ether_aton(const char *orig, A_UINT8 *eth)
   i = 0;
   for(bufp = orig; *bufp != '\0'; ++bufp) {
     unsigned int val;
-    unsigned char c = *bufp++;
-    if (c >= '0' && c <= '9') val = c - '0';
-    else if (c >= 'a' && c <= 'f') val = c - 'a' + 10;
-    else if (c >= 'A' && c <= 'F') val = c - 'A' + 10;
-    else {
-        printk("%s: MAC value is invalid\n", __FUNCTION__);
-        break;
-    }
+	int h, l;
 
-    val <<= 4;
-    c = *bufp++;
-    if (c >= '0' && c <= '9') val |= c - '0';
-    else if (c >= 'a' && c <= 'f') val |= c - 'a' + 10;
-    else if (c >= 'A' && c <= 'F') val |= c - 'A' + 10;
-    else {
-        printk("%s: MAC value is invalid\n", __FUNCTION__);
-        break;
-    }
+	h = hex_to_bin(*bufp++);
+
+	if (h < 0) {
+		printk("%s: MAC value is invalid\n", __FUNCTION__);
+		break;
+	}
+
+	l = hex_to_bin(*bufp++);
+	if (l < 0) {
+		printk("%s: MAC value is invalid\n", __FUNCTION__);
+		break;
+	}
+
+	val = (h << 4) | l;
 
     eth[i] = (unsigned char) (val & 0377);
     if(++i == ATH_MAC_LEN) {
-- 
1.7.2.2


  reply	other threads:[~2010-09-07 15:20 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-07 15:20 [PATCH 1/2] staging: rtl8712: throw away custom hex_to_bin() Andy Shevchenko
2010-09-07 15:20 ` Andy Shevchenko [this message]
2010-09-07 21:18   ` [PATCH 2/2] staging: ath6kl: use native methods from kernel library Vipin Mehta
2010-09-07 22:26     ` Andy Shevchenko
2010-09-08  0:03     ` Greg KH
2010-09-08  2:29       ` Vipin Mehta
2010-09-08  7:08         ` Greg KH

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=8b251244717765e795b92a1f7335f8af98e5706f.1283872748.git.andy.shevchenko@gmail.com \
    --to=andy.shevchenko@gmail.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@suse.de \
    --cc=linux-kernel@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

all inboxes | Powered by JetHome®