* [PATCH 1/3] drivers: isdn: use kernel macros to convert hex digit
@ 2010-07-15 12:37 Andy Shevchenko
2010-07-15 12:37 ` [PATCH 2/3] drivers: isdn: remove custom strtoul() Andy Shevchenko
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Andy Shevchenko @ 2010-07-15 12:37 UTC (permalink / raw)
To: linux-kernel; +Cc: Andy Shevchenko, Karsten Keil, Tilman Schmidt, netdev
Signed-off-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Karsten Keil <isdn@linux-pingi.de>
Cc: Tilman Schmidt <tilman@imap.cc>
Cc: netdev@vger.kernel.org
---
drivers/isdn/capi/capidrv.c | 7 ++-----
drivers/isdn/hisax/q931.c | 13 ++-----------
2 files changed, 4 insertions(+), 16 deletions(-)
diff --git a/drivers/isdn/capi/capidrv.c b/drivers/isdn/capi/capidrv.c
index bf55ed5..2978bda 100644
--- a/drivers/isdn/capi/capidrv.c
+++ b/drivers/isdn/capi/capidrv.c
@@ -1450,12 +1450,9 @@ static void handle_dtrace_data(capidrv_contr *card,
}
for (p = data, end = data+len; p < end; p++) {
- u8 w;
PUTBYTE_TO_STATUS(card, ' ');
- w = (*p >> 4) & 0xf;
- PUTBYTE_TO_STATUS(card, (w < 10) ? '0'+w : 'A'-10+w);
- w = *p & 0xf;
- PUTBYTE_TO_STATUS(card, (w < 10) ? '0'+w : 'A'-10+w);
+ PUTBYTE_TO_STATUS(card, hex_asc_hi(*p));
+ PUTBYTE_TO_STATUS(card, hex_asc_lo(*p));
}
PUTBYTE_TO_STATUS(card, '\n');
diff --git a/drivers/isdn/hisax/q931.c b/drivers/isdn/hisax/q931.c
index 8b853d5..c0771f9 100644
--- a/drivers/isdn/hisax/q931.c
+++ b/drivers/isdn/hisax/q931.c
@@ -1152,20 +1152,11 @@ QuickHex(char *txt, u_char * p, int cnt)
{
register int i;
register char *t = txt;
- register u_char w;
for (i = 0; i < cnt; i++) {
*t++ = ' ';
- w = (p[i] >> 4) & 0x0f;
- if (w < 10)
- *t++ = '0' + w;
- else
- *t++ = 'A' - 10 + w;
- w = p[i] & 0x0f;
- if (w < 10)
- *t++ = '0' + w;
- else
- *t++ = 'A' - 10 + w;
+ *t++ = hex_asc_hi(p[i]);
+ *t++ = hex_asc_lo(p[i]);
}
*t++ = 0;
return (t - txt);
--
1.7.1.1
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH 2/3] drivers: isdn: remove custom strtoul()
2010-07-15 12:37 [PATCH 1/3] drivers: isdn: use kernel macros to convert hex digit Andy Shevchenko
@ 2010-07-15 12:37 ` Andy Shevchenko
2010-07-16 2:08 ` David Miller
2010-07-15 12:37 ` [PATCH 3/3] drivers: isdn: get rid of " Andy Shevchenko
2010-07-16 2:08 ` [PATCH 1/3] drivers: isdn: use kernel macros to convert hex digit David Miller
2 siblings, 1 reply; 6+ messages in thread
From: Andy Shevchenko @ 2010-07-15 12:37 UTC (permalink / raw)
To: linux-kernel; +Cc: Andy Shevchenko, Karsten Keil, netdev
In this case we safe to use strict_strtoul().
Signed-off-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Karsten Keil <isdn@linux-pingi.de>
Cc: netdev@vger.kernel.org
---
drivers/isdn/hysdn/hysdn_proclog.c | 36 +++++++-----------------------------
1 files changed, 7 insertions(+), 29 deletions(-)
diff --git a/drivers/isdn/hysdn/hysdn_proclog.c b/drivers/isdn/hysdn/hysdn_proclog.c
index 7003698..2ee93d0 100644
--- a/drivers/isdn/hysdn/hysdn_proclog.c
+++ b/drivers/isdn/hysdn/hysdn_proclog.c
@@ -16,6 +16,7 @@
#include <linux/sched.h>
#include <linux/slab.h>
#include <linux/mutex.h>
+#include <linux/kernel.h>
#include "hysdn_defs.h"
@@ -155,9 +156,8 @@ static ssize_t
hysdn_log_write(struct file *file, const char __user *buf, size_t count, loff_t * off)
{
unsigned long u = 0;
- int found = 0;
- unsigned char *cp, valbuf[128];
- long base = 10;
+ int rc;
+ unsigned char valbuf[128];
hysdn_card *card = file->private_data;
if (count > (sizeof(valbuf) - 1))
@@ -166,32 +166,10 @@ hysdn_log_write(struct file *file, const char __user *buf, size_t count, loff_t
return (-EFAULT); /* copy failed */
valbuf[count] = 0; /* terminating 0 */
- cp = valbuf;
- if ((count > 2) && (valbuf[0] == '0') && (valbuf[1] == 'x')) {
- cp += 2; /* pointer after hex modifier */
- base = 16;
- }
- /* scan the input for debug flags */
- while (*cp) {
- if ((*cp >= '0') && (*cp <= '9')) {
- found = 1;
- u *= base; /* adjust to next digit */
- u += *cp++ - '0';
- continue;
- }
- if (base != 16)
- break; /* end of number */
-
- if ((*cp >= 'a') && (*cp <= 'f')) {
- found = 1;
- u *= base; /* adjust to next digit */
- u += *cp++ - 'a' + 10;
- continue;
- }
- break; /* terminated */
- }
- if (found) {
+ rc = strict_strtoul(valbuf, 0, &u);
+
+ if (rc == 0) {
card->debug_flags = u; /* remember debug flags */
hysdn_addlog(card, "debug set to 0x%lx", card->debug_flags);
}
--
1.7.1.1
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH 3/3] drivers: isdn: get rid of custom strtoul()
2010-07-15 12:37 [PATCH 1/3] drivers: isdn: use kernel macros to convert hex digit Andy Shevchenko
2010-07-15 12:37 ` [PATCH 2/3] drivers: isdn: remove custom strtoul() Andy Shevchenko
@ 2010-07-15 12:37 ` Andy Shevchenko
2010-07-16 2:08 ` David Miller
2010-07-16 2:08 ` [PATCH 1/3] drivers: isdn: use kernel macros to convert hex digit David Miller
2 siblings, 1 reply; 6+ messages in thread
From: Andy Shevchenko @ 2010-07-15 12:37 UTC (permalink / raw)
To: linux-kernel
Cc: Andy Shevchenko, Hansjoerg Lipp, Tilman Schmidt, Karsten Keil,
gigaset307x-common, netdev
There were two methods isdn_gethex() and isdn_getnum() which are custom
implementations of strtoul(). Get rid of them in regard to
strict_strtoul() kernel's function.
Signed-off-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Hansjoerg Lipp <hjlipp@web.de>
Cc: Tilman Schmidt <tilman@imap.cc>
Cc: Karsten Keil <isdn@linux-pingi.de>
Cc: gigaset307x-common@lists.sourceforge.net
Cc: netdev@vger.kernel.org
---
drivers/isdn/gigaset/ev-layer.c | 80 ++++++++++-----------------------------
1 files changed, 20 insertions(+), 60 deletions(-)
diff --git a/drivers/isdn/gigaset/ev-layer.c b/drivers/isdn/gigaset/ev-layer.c
index a230ba7..a141876 100644
--- a/drivers/isdn/gigaset/ev-layer.c
+++ b/drivers/isdn/gigaset/ev-layer.c
@@ -385,64 +385,18 @@ static const struct zsau_resp_t {
{NULL, ZSAU_UNKNOWN}
};
-/*
- * Get integer from char-pointer
- */
-static int isdn_getnum(char *p)
-{
- int v = -1;
-
- gig_dbg(DEBUG_EVENT, "string: %s", p);
-
- while (*p >= '0' && *p <= '9')
- v = ((v < 0) ? 0 : (v * 10)) + (int) ((*p++) - '0');
- if (*p)
- v = -1; /* invalid Character */
- return v;
-}
-
-/*
- * Get integer from char-pointer
- */
-static int isdn_gethex(char *p)
-{
- int v = 0;
- int c;
-
- gig_dbg(DEBUG_EVENT, "string: %s", p);
-
- if (!*p)
- return -1;
-
- do {
- if (v > (INT_MAX - 15) / 16)
- return -1;
- c = *p;
- if (c >= '0' && c <= '9')
- c -= '0';
- else if (c >= 'a' && c <= 'f')
- c -= 'a' - 10;
- else if (c >= 'A' && c <= 'F')
- c -= 'A' - 10;
- else
- return -1;
- v = v * 16 + c;
- } while (*++p);
-
- return v;
-}
-
/* retrieve CID from parsed response
* returns 0 if no CID, -1 if invalid CID, or CID value 1..65535
*/
static int cid_of_response(char *s)
{
- int cid;
+ unsigned long cid;
+ int rc;
if (s[-1] != ';')
return 0; /* no CID separator */
- cid = isdn_getnum(s);
- if (cid < 0)
+ rc = strict_strtoul(s, 10, &cid);
+ if (rc)
return 0; /* CID not numeric */
if (cid < 1 || cid > 65535)
return -1; /* CID out of range */
@@ -612,21 +566,27 @@ void gigaset_handle_modem_response(struct cardstate *cs)
case RT_ZCAU:
event->parameter = -1;
if (curarg + 1 < params) {
- i = isdn_gethex(argv[curarg]);
- j = isdn_gethex(argv[curarg + 1]);
- if (i >= 0 && i < 256 && j >= 0 && j < 256)
- event->parameter = (unsigned) i << 8
- | j;
- curarg += 2;
+ unsigned long type, value;
+
+ i = strict_strtoul(argv[curarg++], 16, &type);
+ j = strict_strtoul(argv[curarg++], 16, &value);
+
+ if (i == 0 && type < 256 &&
+ j == 0 && value < 256)
+ event->parameter = (type << 8) | value;
} else
curarg = params - 1;
break;
case RT_NUMBER:
+ event->parameter = -1;
if (curarg < params) {
- event->parameter = isdn_getnum(argv[curarg]);
- ++curarg;
- } else
- event->parameter = -1;
+ unsigned long res;
+ int rc;
+
+ rc = strict_strtoul(argv[curarg++], 10, &res);
+ if (rc == 0)
+ event->parameter = res;
+ }
gig_dbg(DEBUG_EVENT, "parameter==%d", event->parameter);
break;
}
--
1.7.1.1
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH 1/3] drivers: isdn: use kernel macros to convert hex digit
2010-07-15 12:37 [PATCH 1/3] drivers: isdn: use kernel macros to convert hex digit Andy Shevchenko
2010-07-15 12:37 ` [PATCH 2/3] drivers: isdn: remove custom strtoul() Andy Shevchenko
2010-07-15 12:37 ` [PATCH 3/3] drivers: isdn: get rid of " Andy Shevchenko
@ 2010-07-16 2:08 ` David Miller
2 siblings, 0 replies; 6+ messages in thread
From: David Miller @ 2010-07-16 2:08 UTC (permalink / raw)
To: andy.shevchenko; +Cc: linux-kernel, isdn, tilman, netdev
From: Andy Shevchenko <andy.shevchenko@gmail.com>
Date: Thu, 15 Jul 2010 15:37:18 +0300
> Signed-off-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Applied.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2010-07-16 2:08 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-15 12:37 [PATCH 1/3] drivers: isdn: use kernel macros to convert hex digit Andy Shevchenko
2010-07-15 12:37 ` [PATCH 2/3] drivers: isdn: remove custom strtoul() Andy Shevchenko
2010-07-16 2:08 ` David Miller
2010-07-15 12:37 ` [PATCH 3/3] drivers: isdn: get rid of " Andy Shevchenko
2010-07-16 2:08 ` David Miller
2010-07-16 2:08 ` [PATCH 1/3] drivers: isdn: use kernel macros to convert hex digit David Miller
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).