Skip to contentSkip to conversation

Clean up code to use native kernel functions when convert or check hex digits

PATCH In review Andy Shevchenko 4 participants 21 messages Feb 18, 2010 – Feb 22, 2010

Subsystems (11)
Network drivers SCSI USB PowerPC +7 more subsystems
lore
Share & tools
lore
#0 lore raw

cover Clean up code to use native kernel functions when convert or check hex digits

From: Andy Shevchenko <[email protected]>

Hello.

There are set of paches related to hex2bin, bin2hex, isxdigit custom implementations. All of them are changed by native kernel functions. In case of hex2bin there is generalized method [hex_to_bin] to do such thing which is put under lib/hexxdump.c (kernel.h).

TODO: apply hex_to_bin() to kgdb code.

Andy Shevchenko (12):
isdn: remove ishexdigit() in regard to isxdigit()
audit: use kernel's method to get byte in hex form
staging: remove unused methods
scsi: ibmmca: use kernel native convertor
lib: introduce common method to convert hex digits
drivers: net: optimize hex2bin()
usb: atm: speedtch: use new hex_to_bin() method
net: use new hex_to_bin() method
drivers: net: use kernel's method to get byte in hex form
drivers: net: use new hex_to_bin() method
drivers: isdn: use new hex_to_bin() method
drivers: wireless: use kernel's method to get byte in hex form

 drivers/isdn/gigaset/capi.c         |   30 +++---------------------------
 drivers/net/cxgb3/t3_hw.c           |   16 ++++------------
 drivers/net/ppp_synctty.c           |    4 +---
 drivers/net/ps3_gelic_wireless.c    |   12 ++++--------
 drivers/net/sb1250-mac.c            |   32 ++------------------------------
 drivers/net/wireless/at76c50x-usb.c |    5 +----
 drivers/scsi/ibmmca.c               |    3 +--
 drivers/staging/otus/apdbg.c        |   25 -------------------------
 drivers/usb/atm/speedtch.c          |    5 ++---
 include/linux/kernel.h              |    2 ++
 kernel/audit.c                      |    8 +++-----
 lib/hexdump.c                       |   19 +++++++++++++++++++
 12 files changed, 42 insertions(+), 119 deletions(-)
#1 lore raw

PATCH 1/12 isdn: remove ishexdigit() in regard to isxdigit()

From: Andy Shevchenko <[email protected]>

Samll cleanup in drivers/isdn/gigaset/capi.c where own implementation of isxdigit() has been changed to kernel native one.

---
 drivers/isdn/gigaset/capi.c |   16 +---------------
 1 files changed, 1 insertions(+), 15 deletions(-)
drivers/isdn/gigaset/capi.c +1 -15
index 3f5cd06..83c4e2f 100644
@@ -169,20 +169,6 @@ static inline void ignore_cstruct_param(struct cardstate *cs, _cstruct param,
 }
 
 /*
- * check for legal hex digit
- */
-static inline int ishexdigit(char c)
-{
-	if (c >= '0' && c <= '9')
-		return 1;
-	if (c >= 'A' && c <= 'F')
-		return 1;
-	if (c >= 'a' && c <= 'f')
-		return 1;
-	return 0;
-}
-
-/*
  * convert hex to binary
  */
 static inline u8 hex2bin(char c)
@@ -202,7 +188,7 @@ static int encode_ie(char *in, u8 *out, int maxlen)
 {
 	int l = 0;
 	while (*in) {
-		if (!ishexdigit(in[0]) || !ishexdigit(in[1]) || l >= maxlen)
+		if (!isxdigit(in[0]) || !isxdigit(in[1]) || l >= maxlen)
 			return -1;
 		out[++l] = (hex2bin(in[0]) << 4) + hex2bin(in[1]);
 		in += 2;
Signature · 1 line
1.5.6.5
#2 lore raw

PATCH 2/12 audit: use kernel's method to get byte in hex form

From: Andy Shevchenko <[email protected]>

---
 kernel/audit.c |    8 +++-----
 1 files changed, 3 insertions(+), 5 deletions(-)
kernel/audit.c +3 -5
index 5feed23..160abad 100644
@@ -58,6 +58,7 @@
 #include <linux/inotify.h>
 #include <linux/freezer.h>
 #include <linux/tty.h>
+#include <linux/kernel.h>
 
 #include "audit.h"
 
@@ -1308,7 +1309,6 @@ void audit_log_n_hex(struct audit_buffer *ab, const unsigned char *buf,
 	int i, avail, new_len;
 	unsigned char *ptr;
 	struct sk_buff *skb;
-	static const unsigned char *hex = "0123456789ABCDEF";
 
 	if (!ab)
 		return;
@@ -1326,10 +1326,8 @@ void audit_log_n_hex(struct audit_buffer *ab, const unsigned char *buf,
 	}
 
 	ptr = skb_tail_pointer(skb);
-	for (i=0; i<len; i++) {
-		*ptr++ = hex[(buf[i] & 0xF0)>>4]; /* Upper nibble */
-		*ptr++ = hex[buf[i] & 0x0F];	  /* Lower nibble */
-	}
+	for (i=0; i<len; i++)
+		ptr = pack_hex_byte(ptr, buf[i]);
 	*ptr = 0;
 	skb_put(skb, len << 1); /* new string is twice the old string */
 }
Signature · 1 line
1.5.6.5
#3 lore raw

PATCH 3/12 staging: remove unused methods

From: Andy Shevchenko <[email protected]>

There are two methods to convert hex value to binary format. This certain methods aren't used anywhere in kernel.

---
 drivers/staging/otus/apdbg.c |   25 -------------------------
 1 files changed, 0 insertions(+), 25 deletions(-)
drivers/staging/otus/apdbg.c +0 -25
index 0eb93f1..30d07ef 100644
@@ -90,9 +90,6 @@ struct zdap_ioctl {
 
 #endif
 
-char hex(char);
-unsigned char asctohex(char *str);
-
 char *prgname;
 
 int set_ioctl(int sock, struct ifreq *req)
@@ -380,25 +377,3 @@ fail:
 	exit(0);
 }
 
-unsigned char asctohex(char *str)
-{
-	unsigned char value;
-
-	value = hex(*str) & 0x0f;
-	value = value << 4;
-	str++;
-	value |= hex(*str) & 0x0f;
-
-	return value;
-}
-
-char hex(char v)
-{
-	if (isdigit(v))
-		return v - '0';
-	else if (isxdigit(v))
-		return tolower(v) - 'a' + 10;
-	else
-		return 0;
-}
-
Signature · 1 line
1.5.6.5
#4 lore raw

PATCH 4/12 scsi: ibmmca: use kernel native convertor

From: Andy Shevchenko <[email protected]>

to get hex digit from a binary format we may use kernel's hex_asc_*() methods.

---
 drivers/scsi/ibmmca.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
drivers/scsi/ibmmca.c +1 -2
index 9c1e6a5..52b03a6 100644
@@ -1002,12 +1002,11 @@ static char *ti_p(int dev)
 /* interpreter for logical device numbers (ldn) */
 static char *ti_l(int val)
 {
-	const char hex[16] = "0123456789abcdef";
 	static char answer[2];
 
 	answer[1] = (char) (0x0);
 	if (val <= MAX_LOG_DEV)
-		answer[0] = hex[val];
+		answer[0] = hex_asc_lo(val);
 	else
 		answer[0] = '-';
 	return (char *) &answer;
Signature · 1 line
1.5.6.5
#5 lore raw

PATCH 5/12 lib: introduce common method to convert hex digits

From: Andy Shevchenko <[email protected]>

hex_to_bin() is a little method which converts hex digit to its actual value. There are plenty of places where such functionality is needed.

---
 include/linux/kernel.h |    2 ++
 lib/hexdump.c          |   19 +++++++++++++++++++
 2 files changed, 21 insertions(+), 0 deletions(-)
include/linux/kernel.h +2 -0
index 328bca6..bbbf885 100644
@@ -361,6 +361,8 @@ static inline char *pack_hex_byte(char *buf, u8 byte)
 	return buf;
 }
 
+extern int hex_to_bin(char ch);
+
 #ifndef pr_fmt
 #define pr_fmt(fmt) fmt
 #endif
lib/hexdump.c +19 -0
index 39af256..d79b166 100644
@@ -16,6 +16,25 @@ const char hex_asc[] = "0123456789abcdef";
 EXPORT_SYMBOL(hex_asc);
 
 /**
+ * hex_to_bin - convert a hex digit to its real value
+ * @ch: ascii character represents hex digit
+ *
+ * hex_to_bin() converts one hex digit to its actual value or -1 in case of bad
+ * input.
+ */
+int hex_to_bin(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;
+}
+EXPORT_SYMBOL(hex_to_bin);
+
+/**
  * hex_dump_to_buffer - convert a blob of data to "hex ASCII" in memory
  * @buf: data blob to dump
  * @len: number of bytes in the @buf
Signature · 1 line
1.5.6.5
#6 lore raw

PATCH 6/12 drivers: net: optimize hex2bin()

From: Andy Shevchenko <[email protected]>

Optimize hex2bin() function used in ps3_gelic_wireless.c. It requires to have hex_to_bin() implementation introduced by one of previous path in series.

---
 drivers/net/ps3_gelic_wireless.c |   12 ++++--------
 1 files changed, 4 insertions(+), 8 deletions(-)
drivers/net/ps3_gelic_wireless.c +4 -8
index 227b141..073d0a0 100644
@@ -1394,23 +1394,19 @@ static int gelic_wl_get_mode(struct net_device *netdev,
 static int hex2bin(u8 *str, u8 *bin, unsigned int len)
 {
 	unsigned int i;
-	static unsigned char *hex = "0123456789ABCDEF";
-	unsigned char *p, *q;
-	u8 tmp;
 
 	if (len != WPA_PSK_LEN * 2)
 		return -EINVAL;
 
 	for (i = 0; i < WPA_PSK_LEN * 2; i += 2) {
-		p = strchr(hex, toupper(str[i]));
-		q = strchr(hex, toupper(str[i + 1]));
-		if (!p || !q) {
+		int h = hex_to_bin(str[i]);
+		int l = hex_to_bin(str[i+1]);
+		if ((h == -1) || (l == -1)) {
 			pr_info("%s: unconvertible PSK digit=%d\n",
 				__func__, i);
 			return -EINVAL;
 		}
-		tmp = ((p - hex) << 4) + (q - hex);
-		*bin++ = tmp;
+		*bin++ = (u8)((h << 4) + l);
 	}
 	return 0;
 };
Signature · 1 line
1.5.6.5
#7 lore raw

PATCH 7/12 usb: atm: speedtch: use new hex_to_bin() method

From: Andy Shevchenko <[email protected]>

Instead of using own implementation which potentialy has bugs involve hex_to_bin() function. It requires to have hex_to_bin() implementation introduced by one of previous path in series.

---
 drivers/usb/atm/speedtch.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)
drivers/usb/atm/speedtch.c +2 -3
index 3e86240..dd1c562 100644
@@ -128,8 +128,6 @@ MODULE_PARM_DESC(ModemOption, "default: 0x10,0x00,0x00,0x00,0x20");
 #define ENDPOINT_ISOC_DATA	0x07
 #define ENDPOINT_FIRMWARE	0x05
 
-#define hex2int(c) ( (c >= '0') && (c <= '9') ? (c - '0') : ((c & 0xf) + 9) )
-
 struct speedtch_params {
 	unsigned int altsetting;
 	unsigned int BMaxDSL;
@@ -670,7 +668,8 @@ static int speedtch_atm_start(struct usbatm_data *usbatm, struct atm_dev *atm_de
 	memset(atm_dev->esi, 0, sizeof(atm_dev->esi));
 	if (usb_string(usb_dev, usb_dev->descriptor.iSerialNumber, mac_str, sizeof(mac_str)) == 12) {
 		for (i = 0; i < 6; i++)
-			atm_dev->esi[i] = (hex2int(mac_str[i * 2]) * 16) + (hex2int(mac_str[i * 2 + 1]));
+			atm_dev->esi[i] = (hex_to_bin(mac_str[i*2]) << 4) +
+				hex_to_bin(mac_str[i*2+1]);
 	}
 
 	/* Start modem synchronisation */
Signature · 1 line
1.5.6.5
#8 lore raw

PATCH 8/12 net: use new hex_to_bin() method

From: Andy Shevchenko <[email protected]>

Instead of using own implementation involve hex_to_bin() function. It requires to have hex_to_bin() introduced by one of previous path in series.

---
 drivers/net/sb1250-mac.c |   32 ++------------------------------
 1 files changed, 2 insertions(+), 30 deletions(-)
drivers/net/sb1250-mac.c +2 -30
index 564d4d7..87c57cb 100644
@@ -2184,34 +2184,6 @@ static void sbmac_setmulti(struct sbmac_softc *sc)
 
 #if defined(SBMAC_ETH0_HWADDR) || defined(SBMAC_ETH1_HWADDR) || defined(SBMAC_ETH2_HWADDR) || defined(SBMAC_ETH3_HWADDR)
 /**********************************************************************
- *  SBMAC_PARSE_XDIGIT(str)
- *
- *  Parse a hex digit, returning its value
- *
- *  Input parameters:
- *  	   str - character
- *
- *  Return value:
- *  	   hex value, or -1 if invalid
- ********************************************************************* */
-
-static int sbmac_parse_xdigit(char str)
-{
-	int digit;
-
-	if ((str >= '0') && (str <= '9'))
-		digit = str - '0';
-	else if ((str >= 'a') && (str <= 'f'))
-		digit = str - 'a' + 10;
-	else if ((str >= 'A') && (str <= 'F'))
-		digit = str - 'A' + 10;
-	else
-		return -1;
-
-	return digit;
-}
-
-/**********************************************************************
  *  SBMAC_PARSE_HWADDR(str,hwaddr)
  *
  *  Convert a string in the form xx:xx:xx:xx:xx:xx into a 6-byte
@@ -2231,7 +2203,7 @@ static int sbmac_parse_hwaddr(char *str, unsigned char *hwaddr)
 	int idx = 6;
 
 	while (*str && (idx > 0)) {
-		digit1 = sbmac_parse_xdigit(*str);
+		digit1 = hex_to_bin(*str);
 		if (digit1 < 0)
 			return -1;
 		str++;
@@ -2243,7 +2215,7 @@ static int sbmac_parse_hwaddr(char *str, unsigned char *hwaddr)
 			digit1 = 0;
 		}
 		else {
-			digit2 = sbmac_parse_xdigit(*str);
+			digit2 = hex_to_bin(*str);
 			if (digit2 < 0)
 				return -1;
 			str++;
Signature · 1 line
1.5.6.5
#9 lore raw

PATCH 9/12 drivers: net: use kernel's method to get byte in hex form

From: Andy Shevchenko <[email protected]>

---
 drivers/net/ppp_synctty.c |    4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)
drivers/net/ppp_synctty.c +1 -3
index 3a13cec..e4b3cf6 100644
@@ -108,12 +108,10 @@ static void
 ppp_print_hex (register __u8 * out, const __u8 * in, int count)
 {
 	register __u8 next_ch;
-	static const char hex[] = "0123456789ABCDEF";
 
 	while (count-- > 0) {
 		next_ch = *in++;
-		*out++ = hex[(next_ch >> 4) & 0x0F];
-		*out++ = hex[next_ch & 0x0F];
+		out = pack_hex_byte(out, next_ch);
 		++out;
 	}
 }
Signature · 1 line
1.5.6.5
#10 lore raw

PATCH 10/12 drivers: net: use new hex_to_bin() method

From: Andy Shevchenko <[email protected]>

Get rid of own implementation of hex_to_bin(). It requires to have hex_to_bin() introduced by one of previous path in series.

---
 drivers/net/cxgb3/t3_hw.c |   16 ++++------------
 1 files changed, 4 insertions(+), 12 deletions(-)
drivers/net/cxgb3/t3_hw.c +4 -12
index 032cfe0..80b3cd7 100644
@@ -679,14 +679,6 @@ int t3_seeprom_wp(struct adapter *adapter, int enable)
 	return t3_seeprom_write(adapter, EEPROM_STAT_ADDR, enable ? 0xc : 0);
 }
 
-/*
- * Convert a character holding a hex digit to a number.
- */
-static unsigned int hex2int(unsigned char c)
-{
-	return isdigit(c) ? c - '0' : toupper(c) - 'A' + 10;
-}
-
 /**
  *	get_vpd_params - read VPD parameters from VPD EEPROM
  *	@adapter: adapter to read
@@ -727,15 +719,15 @@ static int get_vpd_params(struct adapter *adapter, struct vpd_params *p)
 		p->port_type[0] = uses_xaui(adapter) ? 1 : 2;
 		p->port_type[1] = uses_xaui(adapter) ? 6 : 2;
 	} else {
-		p->port_type[0] = hex2int(vpd.port0_data[0]);
-		p->port_type[1] = hex2int(vpd.port1_data[0]);
+		p->port_type[0] = hex_to_bin(vpd.port0_data[0]);
+		p->port_type[1] = hex_to_bin(vpd.port1_data[0]);
 		p->xauicfg[0] = simple_strtoul(vpd.xaui0cfg_data, NULL, 16);
 		p->xauicfg[1] = simple_strtoul(vpd.xaui1cfg_data, NULL, 16);
 	}
 
 	for (i = 0; i < 6; i++)
-		p->eth_base[i] = hex2int(vpd.na_data[2 * i]) * 16 +
-				 hex2int(vpd.na_data[2 * i + 1]);
+		p->eth_base[i] = hex_to_bin(vpd.na_data[2*i]) * 16 +
+				 hex_to_bin(vpd.na_data[2*i + 1]);
 	return 0;
 }
 
Signature · 1 line
1.5.6.5
#11 lore raw

PATCH 11/12 drivers: isdn: use new hex_to_bin() method

From: Andy Shevchenko <[email protected]>

Get rid of own implementation of hex_to_bin(). It requires to have hex_to_bin() introduced by one of previous path in series.

---
 drivers/isdn/gigaset/capi.c |   14 ++------------
 1 files changed, 2 insertions(+), 12 deletions(-)
drivers/isdn/gigaset/capi.c +2 -12
index 83c4e2f..72adcfb 100644
@@ -13,6 +13,7 @@
 
 #include "gigaset.h"
 #include <linux/ctype.h>
+#include <linux/kernel.h>
 #include <linux/isdn/capilli.h>
 #include <linux/isdn/capicmd.h>
 #include <linux/isdn/capiutil.h>
@@ -169,17 +170,6 @@ static inline void ignore_cstruct_param(struct cardstate *cs, _cstruct param,
 }
 
 /*
- * convert hex to binary
- */
-static inline u8 hex2bin(char c)
-{
-	int result = c & 0x0f;
-	if (c & 0x40)
-		result += 9;
-	return result;
-}
-
-/*
  * convert an IE from Gigaset hex string to ETSI binary representation
  * including length byte
  * return value: result length, -1 on error
@@ -190,7 +180,7 @@ static int encode_ie(char *in, u8 *out, int maxlen)
 	while (*in) {
 		if (!isxdigit(in[0]) || !isxdigit(in[1]) || l >= maxlen)
 			return -1;
-		out[++l] = (hex2bin(in[0]) << 4) + hex2bin(in[1]);
+		out[++l] = (hex_to_bin(in[0]) << 4) + hex_to_bin(in[1]);
 		in += 2;
 	}
 	out[0] = l;
Signature · 1 line
1.5.6.5
#12 lore raw

PATCH 12/12 drivers: wireless: use kernel's method to get byte in hex form

From: Andy Shevchenko <[email protected]>

---
 drivers/net/wireless/at76c50x-usb.c |    5 +----
 1 files changed, 1 insertions(+), 4 deletions(-)
drivers/net/wireless/at76c50x-usb.c +1 -4
index 2517364..d700d13 100644
@@ -502,7 +502,6 @@ exit:
 
 #define HEX2STR_BUFFERS 4
 #define HEX2STR_MAX_LEN 64
-#define BIN2HEX(x) ((x) < 10 ? '0' + (x) : (x) + 'A' - 10)
 
 /* Convert binary data into hex string */
 static char *hex2str(void *buf, int len)
@@ -522,10 +521,8 @@ static char *hex2str(void *buf, int len)
 	}
 
 	while (len--) {
-		*obuf++ = BIN2HEX(*ibuf >> 4);
-		*obuf++ = BIN2HEX(*ibuf & 0xf);
+		obuf = pack_hex_byte(obuf, *ibuf++);
 		*obuf++ = '-';
-		ibuf++;
 	}
 	*(--obuf) = '\0';
 
Signature · 1 line
1.5.6.5
#13 lore raw

Re: [PATCH 11/12] drivers: isdn: use new hex_to_bin() method

In reply to Andy Shevchenko

Am 18.02.2010 19:55 schrieb Andy Shevchenko:

Quoted 15 lines

From: Andy Shevchenko <[email protected]>

Get rid of own implementation of hex_to_bin(). It requires to have hex_to_bin() introduced by one of previous path in series.

---
 drivers/isdn/gigaset/capi.c |   14 ++------------
 1 files changed, 2 insertions(+), 12 deletions(-)
drivers/isdn/gigaset/capi.c +0 -0
index 83c4e2f..72adcfb 100644

drivers/isdn/gigaset/capi.c line 19

Quoted 7 lines
drivers/isdn/gigaset/capi.c +1 -0
@@ -13,6 +13,7 @@
 
 #include "gigaset.h"
 #include <linux/ctype.h>
+#include <linux/kernel.h>
 #include <linux/isdn/capilli.h>
 #include <linux/isdn/capicmd.h>
 #include <linux/isdn/capiutil.h>

You don't need to include kernel.h here, it's already included from gigaset.h.

Quoted 19 lines
drivers/isdn/gigaset/capi.c +0 -11
@@ -169,17 +170,6 @@ static inline void ignore_cstruct_param(struct cardstate *cs, _cstruct param,
 }
 
 /*
- * convert hex to binary
- */
-static inline u8 hex2bin(char c)
-{
-	int result = c & 0x0f;
-	if (c & 0x40)
-		result += 9;
-	return result;
-}
-
-/*
  * convert an IE from Gigaset hex string to ETSI binary representation
  * including length byte
  * return value: result length, -1 on error

drivers/isdn/gigaset/capi.c static int encode_ie(char *in, u8 *out, int maxlen) · line 186

Quoted 8 lines
drivers/isdn/gigaset/capi.c +1 -1
@@ -190,7 +180,7 @@ static int encode_ie(char *in, u8 *out, int maxlen)
 	while (*in) {
 		if (!isxdigit(in[0]) || !isxdigit(in[1]) || l >= maxlen)
 			return -1;
-		out[++l] = (hex2bin(in[0]) << 4) + hex2bin(in[1]);
+		out[++l] = (hex_to_bin(in[0]) << 4) + hex_to_bin(in[1]);
 		in += 2;
 	}
 	out[0] = l;

Otherwise, fine with me.

Thanks,
Tilman

Signature · 4 lines
Tilman Schmidt                    E-Mail: [email protected]
Bonn, Germany
Diese Nachricht besteht zu 100% aus wiederverwerteten Bits.
Ungeöffnet mindestens haltbar bis: (siehe Rückseite)
#14 lore raw

PATCH v2 1/1 drivers: isdn: use new hex_to_bin() method

From: Andy Shevchenko <[email protected]>

Get rid of own implementation of hex_to_bin().

Please note it requires to have hex_to_bin() introduced by one of previous patch [1] which is not applied yet.

[1] http://patchwork.kernel.org/patch/80404/

---
 drivers/isdn/gigaset/capi.c |   13 +------------
 1 files changed, 1 insertions(+), 12 deletions(-)
drivers/isdn/gigaset/capi.c +1 -12
index 83c4e2f..82ee085 100644
@@ -169,17 +169,6 @@ static inline void ignore_cstruct_param(struct cardstate *cs, _cstruct param,
 }
 
 /*
- * convert hex to binary
- */
-static inline u8 hex2bin(char c)
-{
-	int result = c & 0x0f;
-	if (c & 0x40)
-		result += 9;
-	return result;
-}
-
-/*
  * convert an IE from Gigaset hex string to ETSI binary representation
  * including length byte
  * return value: result length, -1 on error
@@ -190,7 +179,7 @@ static int encode_ie(char *in, u8 *out, int maxlen)
 	while (*in) {
 		if (!isxdigit(in[0]) || !isxdigit(in[1]) || l >= maxlen)
 			return -1;
-		out[++l] = (hex2bin(in[0]) << 4) + hex2bin(in[1]);
+		out[++l] = (hex_to_bin(in[0]) << 4) + hex_to_bin(in[1]);
 		in += 2;
 	}
 	out[0] = l;
Signature · 1 line
1.5.6.5
#16 lore raw

Re: [PATCH 02/12] audit: use kernel's method to get byte in hex form

In reply to Andy Shevchenko
Quoted 3 lines · Andy Shevchenko

From: Andy Shevchenko <[email protected]>

It changes the case from ABCDEF to abcdef but there are a number of userspace tools which might not be able to handle it, have you tested any or all of these? The two that come to mind are ausearch and setroubleshoot, which I believe both may try to recreate pathnames when they contain a space....

-Eric

Quoted 46 lines

---
 kernel/audit.c |    8 +++-----

 1 files changed, 3 insertions(+), 5 deletions(-)
kernel/audit.c +3 -5
index 5feed23..160abad 100644
@@ -58,6 +58,7 @@
  #include <linux/inotify.h>
  #include <linux/freezer.h>
  #include <linux/tty.h>
+#include <linux/kernel.h>
 
  #include "audit.h"
 
@@ -1308,7 +1309,6 @@ void audit_log_n_hex(struct audit_buffer *ab, const unsigned char *buf,
        int i, avail, new_len;
        unsigned char *ptr;
        struct sk_buff *skb;
-       static const unsigned char *hex = "0123456789ABCDEF";
 
        if (!ab)
                return;
@@ -1326,10 +1326,8 @@ void audit_log_n_hex(struct audit_buffer *ab, const unsigned char *buf,
        }
 
        ptr = skb_tail_pointer(skb);
-       for (i=0; i<len; i++) {
-               *ptr++ = hex[(buf[i] & 0xF0)>>4]; /* Upper nibble */
-               *ptr++ = hex[buf[i] & 0x0F];      /* Lower nibble */
-       }
+       for (i=0; i<len; i++)
+               ptr = pack_hex_byte(ptr, buf[i]);
        *ptr = 0;

       skb_put(skb, len << 1); /* new string is twice the old string */ }
--
1.5.6.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

#17 lore raw

Re: [PATCH 02/12] audit: use kernel's method to get byte in hex form

Quoted 2 lines · Eric Paris

It changes the case from ABCDEF to abcdef but there are a number of userspace tools which might not be able to handle it,

Yeah, that's true.

Quoted 1 line

have you tested any or all of these?

Not yet. Anyway, thanks for point. I know how to modify patch to return behaviour back (there is macro toupper() which we have to use).

I'll resend fixed patch if no objections.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
Acked-by on v1 1/12
#18 lore raw

Re: [PATCH 01/12] isdn: remove ishexdigit() in regard to isxdigit()

In reply to Andy Shevchenko

Am 18.02.2010 19:55 schrieb Andy Shevchenko:

Quoted 6 lines

From: Andy Shevchenko <[email protected]>

Samll cleanup in drivers/isdn/gigaset/capi.c where own implementation of isxdigit() has been changed to kernel native one.

Thanks,
Tilman

Quoted 38 lines
---
 drivers/isdn/gigaset/capi.c |   16 +---------------
 1 files changed, 1 insertions(+), 15 deletions(-)
drivers/isdn/gigaset/capi.c +1 -15
index 3f5cd06..83c4e2f 100644
@@ -169,20 +169,6 @@ static inline void ignore_cstruct_param(struct cardstate *cs, _cstruct param,
 }
 
 /*
- * check for legal hex digit
- */
-static inline int ishexdigit(char c)
-{
-	if (c >= '0' && c <= '9')
-		return 1;
-	if (c >= 'A' && c <= 'F')
-		return 1;
-	if (c >= 'a' && c <= 'f')
-		return 1;
-	return 0;
-}
-
-/*
  * convert hex to binary
  */
 static inline u8 hex2bin(char c)
@@ -202,7 +188,7 @@ static int encode_ie(char *in, u8 *out, int maxlen)
 {
 	int l = 0;
 	while (*in) {
-		if (!ishexdigit(in[0]) || !ishexdigit(in[1]) || l >= maxlen)
+		if (!isxdigit(in[0]) || !isxdigit(in[1]) || l >= maxlen)
 			return -1;
 		out[++l] = (hex2bin(in[0]) << 4) + hex2bin(in[1]);
 		in += 2;
Signature · 4 lines
Tilman Schmidt                    E-Mail: [email protected]
Bonn, Germany
Diese Nachricht besteht zu 100% aus wiederverwerteten Bits.
Ungeöffnet mindestens haltbar bis: (siehe Rückseite)
#19 lore raw
In reply to Andy Shevchenko

On Thu, Feb 18, 2010 at 8:55 PM, Andy Shevchenko
<[email protected]> wrote:

I have got a commentary from Uros Bizjak about previous work [1].

Additionally I'd like to sort out patches for two series - one is about clean up code and substitute custom functions by existing ones, the other is about introducing hex_to_bin() helper.

So, I'm going to prepare mentioned series. Please decline that one, but patch #1 which already has been Acked. I will include Cc field as well.
Meanwhile I found more places with the same functionality.

[1] http://lkml.indiana.edu/hypermail/linux/kernel/0805.0/0324.html

P.S. Actually the idea to fix this mess was come to me by Alexander Shishkin.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#20 lore raw

Am 19.02.2010 12:41 schrieb Andy Shevchenko:

Quoted 7 lines

Additionally I'd like to sort out patches for two series - one is about clean up code and substitute custom functions by existing ones, the other is about introducing hex_to_bin() helper.

So, I'm going to prepare mentioned series. Please decline that one, but patch #1 which already has been Acked. I will include Cc field as well.

I can forward your patch #1 to the ISDN maintainer together with my own patches for 2.6.34, or you can resubmit it with my ACK. Just tell me which way you prefer.

Thanks,
Tilman

Signature · 4 lines
Tilman Schmidt                    E-Mail: [email protected]
Bonn, Germany
Diese Nachricht besteht zu 100% aus wiederverwerteten Bits.
Ungeöffnet mindestens haltbar bis: (siehe Rückseite)