Skip to contentSkip to conversation

drivers/net/wan: Replace custom macro with

PATCH NAK Tobias Klauser 2 participants 2 messages Sep 10, 2005

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 3/4 drivers/net/wan: Replace custom macro with

Replace the custom is_digit()/is_hex_digit() macros with isdigit()/isxdigit() from <linux/ctype.h> Additionaly remove unused macro is_alpha() from <linux/wanpipe.h>

---

 drivers/net/wan/cycx_x25.c |    5 +++--
 drivers/net/wan/sdla_fr.c  |    4 ++--
 drivers/net/wan/sdla_x25.c |    8 ++++----
 include/linux/cyclomx.h    |    2 --
 include/linux/wanpipe.h    |    9 ---------
 5 files changed, 9 insertions(+), 19 deletions(-)
drivers/net/wan/cycx_x25.c +3 -2
diff -urpN -X dontdiff linux-2.6.13/drivers/net/wan/cycx_x25.c linux-2.6.13~macro_removal/drivers/net/wan/cycx_x25.c
@@ -78,6 +78,7 @@
 
 #define CYCLOMX_X25_DEBUG 1
 
+#include <linux/ctype.h>	/* isdigit() */
 #include <linux/errno.h>	/* return codes */
 #include <linux/if_arp.h>       /* ARPHRD_HWX25 */
 #include <linux/kernel.h>	/* printk(), and other useful stuff */
@@ -418,7 +419,7 @@ static int cycx_wan_new_if(struct wan_de
 
 		/* Set channel timeouts (default if not specified) */
 		chan->idle_tmout = conf->idle_timeout ? conf->idle_timeout : 90;
-	} else if (is_digit(conf->addr[0])) {	/* PVC */
+	} else if (isdigit(conf->addr[0])) {	/* PVC */
 		s16 lcn = dec_to_uint(conf->addr, 0);
 
 		if (lcn >= card->u.x.lo_pvc && lcn <= card->u.x.hi_pvc)
@@ -1531,7 +1532,7 @@ static unsigned dec_to_uint(u8 *str, int
 	if (!len)
 		len = strlen(str);
 
-	for (; len && is_digit(*str); ++str, --len)
+	for (; len && isdigit(*str); ++str, --len)
 		val = (val * 10) + (*str - (unsigned) '0');
 
 	return val;
drivers/net/wan/sdla_fr.c +2 -2
diff -urpN -X dontdiff linux-2.6.13/drivers/net/wan/sdla_fr.c linux-2.6.13~macro_removal/drivers/net/wan/sdla_fr.c
@@ -822,7 +822,7 @@ static int new_if(struct wan_device* wan
 	chan->card = card;
 
 	/* verify media address */
-	if (is_digit(conf->addr[0])) {
+	if (isdigit(conf->addr[0])) {
 
 		dlci = dec_to_uint(conf->addr, 0);
 
@@ -3458,7 +3458,7 @@ static unsigned int dec_to_uint (unsigne
 	if (!len) 
 		len = strlen(str);
 
-	for (val = 0; len && is_digit(*str); ++str, --len)
+	for (val = 0; len && isdigit(*str); ++str, --len)
 		val = (val * 10) + (*str - (unsigned)'0');
 
 	return val;
drivers/net/wan/sdla_x25.c +4 -4
diff -urpN -X dontdiff linux-2.6.13/drivers/net/wan/sdla_x25.c linux-2.6.13~macro_removal/drivers/net/wan/sdla_x25.c
@@ -957,7 +957,7 @@ static int new_if(struct wan_device* wan
 		chan->hold_timeout = (conf->hold_timeout) ? 
 					conf->hold_timeout : 10;
 
-	}else if (is_digit(conf->addr[0])){	/* PVC */
+	}else if (isdigit(conf->addr[0])){	/* PVC */
 		int lcn = dec_to_uint(conf->addr, 0);
 
 		if ((lcn >= card->u.x.lo_pvc) && (lcn <= card->u.x.hi_pvc)){
@@ -3875,7 +3875,7 @@ static unsigned int dec_to_uint (unsigne
 	if (!len) 
 		len = strlen(str);
 
-	for (val = 0; len && is_digit(*str); ++str, --len)
+	for (val = 0; len && isdigit(*str); ++str, --len)
 		val = (val * 10) + (*str - (unsigned)'0');
 	
 	return val;
@@ -3896,9 +3896,9 @@ static unsigned int hex_to_uint (unsigne
 	for (val = 0; len; ++str, --len)
 	{
 		ch = *str;
-		if (is_digit(ch))
+		if (isdigit(ch))
 			val = (val << 4) + (ch - (unsigned)'0');
-		else if (is_hex_digit(ch))
+		else if (isxdigit(ch))
 			val = (val << 4) + ((ch & 0xDF) - (unsigned)'A' + 10);
 		else break;
 	}
include/linux/cyclomx.h +0 -2
diff -urpN -X dontdiff linux-2.6.13/include/linux/cyclomx.h linux-2.6.13~macro_removal/include/linux/cyclomx.h
@@ -37,8 +37,6 @@
 #include <linux/cycx_x25.h>
 #endif
 
-#define	is_digit(ch) (((ch)>=(unsigned)'0'&&(ch)<=(unsigned)'9')?1:0)
-
 /* Adapter Data Space.
  * This structure is needed because we handle multiple cards, otherwise
  * static data would do it.
include/linux/wanpipe.h +0 -9
diff -urpN -X dontdiff linux-2.6.13/include/linux/wanpipe.h linux-2.6.13~macro_removal/include/linux/wanpipe.h
@@ -265,15 +265,6 @@ typedef struct {
 #include <linux/tty_driver.h>
 #include <linux/tty_flip.h>
 
-
-#define	is_digit(ch) (((ch)>=(unsigned)'0'&&(ch)<=(unsigned)'9')?1:0)
-#define	is_alpha(ch) ((((ch)>=(unsigned)'a'&&(ch)<=(unsigned)'z')||\
-	 	  ((ch)>=(unsigned)'A'&&(ch)<=(unsigned)'Z'))?1:0)
-#define	is_hex_digit(ch) ((((ch)>=(unsigned)'0'&&(ch)<=(unsigned)'9')||\
-	 	  ((ch)>=(unsigned)'a'&&(ch)<=(unsigned)'f')||\
-	 	  ((ch)>=(unsigned)'A'&&(ch)<=(unsigned)'F'))?1:0)
-
-
 /****** Data Structures *****************************************************/
 
 /* Adapter Data Space.

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#1 lore raw

drivers/net/wan/cycx_x25.c static unsigned dec_to_uint(u8 *str, int

Quoted 7 lines · Tobias Klauser

Replace the custom is_digit()/is_hex_digit() macros with isdigit()/isxdigit() from <linux/ctype.h>

drivers/net/wan/cycx_x25.c +0 -0
@@ -1531,7 +1532,7 @@ static unsigned dec_to_uint(u8 *str, int
					^^^^^^^^^^^

drivers/net/wan/cycx_x25.c static unsigned dec_to_uint(u8 *str, int · line 1536

Quoted 3 lines
drivers/net/wan/cycx_x25.c +1 -1
-	for (; len && is_digit(*str); ++str, --len)
+	for (; len && isdigit(*str); ++str, --len)
 		val = (val * 10) + (*str - (unsigned) '0');

Removing duplicated code on slightly larger scale would be even better.

$ cat -n drivers/net/wan/cycx_x25.c | head -n 1538 | tail -n 14
  1525	/* Convert decimal string to unsigned integer.
  1526	 * If len != 0 then only 'len' characters of the string are converted. */
  1527	static unsigned dec_to_uint(u8 *str, int len)
  1528	{
  1529		unsigned val = 0;
  1530	
  1531		if (!len)
  1532			len = strlen(str);
  1533	
  1534		for (; len && is_digit(*str); ++str, --len)
  1535			val = (val * 10) + (*str - (unsigned) '0');
  1536	
  1537		return val;
  1538	}

drivers/net/wan/sdla_fr.c static unsigned int dec_to_uint (unsigne

Quoted 3 lines
drivers/net/wan/sdla_fr.c +0 -0
@@ -3458,7 +3458,7 @@ static unsigned int dec_to_uint (unsigne
					    ^^^^^^^^^^^

drivers/net/wan/sdla_x25.c static unsigned int dec_to_uint (unsigne

Quoted 3 lines
drivers/net/wan/sdla_x25.c +0 -0
@@ -3875,7 +3875,7 @@ static unsigned int dec_to_uint (unsigne
					    ^^^^^^^^^^^

drivers/net/wan/sdla_x25.c static unsigned int hex_to_uint (unsigne

Quoted 1 line
drivers/net/wan/sdla_x25.c +0 -0
@@ -3896,9 +3896,9 @@ static unsigned int hex_to_uint (unsigne
					    ^^^^^^^^^^^

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors