* [PATCH 00/11] Introduce common hex_to_bin() helper @ 2010-02-22 18:08 Andy Shevchenko 2010-02-22 18:09 ` [PATCH 01/11] lib: introduce common method to convert hex digits Andy Shevchenko 0 siblings, 1 reply; 21+ messages in thread From: Andy Shevchenko @ 2010-02-22 18:08 UTC (permalink / raw) To: linux-kernel; +Cc: Andy Shevchenko From: Andy Shevchenko <ext-andriy.shevchenko@nokia.com> Hello. There is set of patches related to hex_to_bin() custom implementations. Many of them are changed to newly introduced common method. The idea published early by Harvey Harrison [1], but was given to me by Alexander Shishkin. [1] http://lkml.indiana.edu/hypermail/linux/kernel/0805.0/0323.html TODO: - apply hex_to_bin() to kgdb code - /arch Andy Shevchenko (11): lib: introduce common method to convert hex digits drivers: isdn: use new hex_to_bin() method drivers: net: optimize hex2bin() usb: atm: speedtch: use new hex_to_bin() method drivers: net: use new hex_to_bin() method drivers: net: use new hex_to_bin() method sysctl: don't use own implementation of hex_to_bin() staging: rt2860: use new hex_to_bin() method fs: ldm: don't use own implementation of hex_to_bin() drivers: wireless: use new hex_to_bin() method drivers: acpi: don't use own implementation of hex_to_bin() drivers/acpi/bus.c | 9 +------ drivers/isdn/gigaset/capi.c | 13 +---------- drivers/net/cxgb3/t3_hw.c | 16 +++---------- drivers/net/ps3_gelic_wireless.c | 12 +++------- drivers/net/sb1250-mac.c | 32 +--------------------------- drivers/net/wireless/airo.c | 15 +++---------- drivers/staging/rt2860/common/rtmp_init.c | 15 +----------- drivers/staging/rt2860/rtmp.h | 2 - drivers/usb/atm/speedtch.c | 5 +-- fs/partitions/ldm.c | 18 ++++++++-------- include/linux/kernel.h | 2 + kernel/sysctl_binary.c | 9 ++----- lib/hexdump.c | 19 +++++++++++++++++ 13 files changed, 54 insertions(+), 113 deletions(-) ^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH 01/11] lib: introduce common method to convert hex digits 2010-02-22 18:08 [PATCH 00/11] Introduce common hex_to_bin() helper Andy Shevchenko @ 2010-02-22 18:09 ` Andy Shevchenko 2010-02-22 18:09 ` [PATCH 02/11] drivers: isdn: use new hex_to_bin() method Andy Shevchenko 2010-03-09 1:03 ` [PATCH 01/11] lib: introduce common method to convert hex digits Andy Shevchenko 0 siblings, 2 replies; 21+ messages in thread From: Andy Shevchenko @ 2010-02-22 18:09 UTC (permalink / raw) To: linux-kernel; +Cc: Andy Shevchenko, Andrew Morton, Ingo Molnar From: Andy Shevchenko <ext-andriy.shevchenko@nokia.com> 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. Signed-off-by: Andy Shevchenko <ext-andriy.shevchenko@nokia.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Ingo Molnar <mingo@elte.hu> --- include/linux/kernel.h | 2 ++ lib/hexdump.c | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 0 deletions(-) diff --git a/include/linux/kernel.h b/include/linux/kernel.h index 328bca6..bbbf885 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -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 diff --git a/lib/hexdump.c b/lib/hexdump.c index 39af256..d79b166 100644 --- a/lib/hexdump.c +++ b/lib/hexdump.c @@ -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 -- 1.5.6.5 ^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 02/11] drivers: isdn: use new hex_to_bin() method 2010-02-22 18:09 ` [PATCH 01/11] lib: introduce common method to convert hex digits Andy Shevchenko @ 2010-02-22 18:09 ` Andy Shevchenko 2010-02-22 18:09 ` [PATCH 03/11] drivers: net: optimize hex2bin() Andy Shevchenko 2010-02-22 21:22 ` [PATCH 02/11] drivers: isdn: use new hex_to_bin() method Tilman Schmidt 2010-03-09 1:03 ` [PATCH 01/11] lib: introduce common method to convert hex digits Andy Shevchenko 1 sibling, 2 replies; 21+ messages in thread From: Andy Shevchenko @ 2010-02-22 18:09 UTC (permalink / raw) To: linux-kernel; +Cc: Andy Shevchenko, Tilman Schmidt From: Andy Shevchenko <ext-andriy.shevchenko@nokia.com> 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/ Signed-off-by: Andy Shevchenko <ext-andriy.shevchenko@nokia.com> Cc: Tilman Schmidt <tilman@imap.cc> --- drivers/isdn/gigaset/capi.c | 13 +------------ 1 files changed, 1 insertions(+), 12 deletions(-) diff --git a/drivers/isdn/gigaset/capi.c b/drivers/isdn/gigaset/capi.c index 3f5cd06..532ca33 100644 --- a/drivers/isdn/gigaset/capi.c +++ b/drivers/isdn/gigaset/capi.c @@ -183,17 +183,6 @@ static inline int ishexdigit(char c) } /* - * 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 @@ -204,7 +193,7 @@ static int encode_ie(char *in, u8 *out, int maxlen) while (*in) { if (!ishexdigit(in[0]) || !ishexdigit(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; -- 1.5.6.5 ^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 03/11] drivers: net: optimize hex2bin() 2010-02-22 18:09 ` [PATCH 02/11] drivers: isdn: use new hex_to_bin() method Andy Shevchenko @ 2010-02-22 18:09 ` Andy Shevchenko 2010-02-22 18:09 ` [PATCH 04/11] usb: atm: speedtch: use new hex_to_bin() method Andy Shevchenko 2010-03-01 23:06 ` [PATCH 03/11] drivers: net: optimize hex2bin() Geoff Levand 2010-02-22 21:22 ` [PATCH 02/11] drivers: isdn: use new hex_to_bin() method Tilman Schmidt 1 sibling, 2 replies; 21+ messages in thread From: Andy Shevchenko @ 2010-02-22 18:09 UTC (permalink / raw) To: linux-kernel; +Cc: Andy Shevchenko, Geoff Levand From: Andy Shevchenko <ext-andriy.shevchenko@nokia.com> Optimize hex2bin() function used in ps3_gelic_wireless.c. It requires to have hex_to_bin() implementation introduced by starter patch in series. Signed-off-by: Andy Shevchenko <ext-andriy.shevchenko@nokia.com> Cc: Geoff Levand <geoffrey.levand@am.sony.com> --- drivers/net/ps3_gelic_wireless.c | 12 ++++-------- 1 files changed, 4 insertions(+), 8 deletions(-) diff --git a/drivers/net/ps3_gelic_wireless.c b/drivers/net/ps3_gelic_wireless.c index 227b141..43e9688 100644 --- a/drivers/net/ps3_gelic_wireless.c +++ b/drivers/net/ps3_gelic_wireless.c @@ -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++ = (h << 4) + l; } return 0; }; -- 1.5.6.5 ^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 04/11] usb: atm: speedtch: use new hex_to_bin() method 2010-02-22 18:09 ` [PATCH 03/11] drivers: net: optimize hex2bin() Andy Shevchenko @ 2010-02-22 18:09 ` Andy Shevchenko 2010-02-22 18:09 ` [PATCH 05/11] drivers: net: " Andy Shevchenko 2010-03-01 23:06 ` [PATCH 03/11] drivers: net: optimize hex2bin() Geoff Levand 1 sibling, 1 reply; 21+ messages in thread From: Andy Shevchenko @ 2010-02-22 18:09 UTC (permalink / raw) To: linux-kernel; +Cc: Andy Shevchenko, Duncan Sands, Greg Kroah-Hartman From: Andy Shevchenko <ext-andriy.shevchenko@nokia.com> Instead of using own implementation which potentialy has bugs involve hex_to_bin() function. It requires to have hex_to_bin() implementation introduced by starter patch in series. Signed-off-by: Andy Shevchenko <ext-andriy.shevchenko@nokia.com> Cc: Duncan Sands <duncan.sands@free.fr> Cc: Greg Kroah-Hartman <gregkh@suse.de> --- drivers/usb/atm/speedtch.c | 5 ++--- 1 files changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/usb/atm/speedtch.c b/drivers/usb/atm/speedtch.c index 3e86240..f3a454d 100644 --- a/drivers/usb/atm/speedtch.c +++ b/drivers/usb/atm/speedtch.c @@ -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 */ -- 1.5.6.5 ^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 05/11] drivers: net: use new hex_to_bin() method 2010-02-22 18:09 ` [PATCH 04/11] usb: atm: speedtch: use new hex_to_bin() method Andy Shevchenko @ 2010-02-22 18:09 ` Andy Shevchenko 2010-02-22 18:09 ` [PATCH 06/11] " Andy Shevchenko 0 siblings, 1 reply; 21+ messages in thread From: Andy Shevchenko @ 2010-02-22 18:09 UTC (permalink / raw) To: linux-kernel; +Cc: Andy Shevchenko, Greg Kroah-Hartman From: Andy Shevchenko <ext-andriy.shevchenko@nokia.com> Instead of using own implementation involve hex_to_bin() function. It requires to have hex_to_bin() introduced by starter patch in series. Signed-off-by: Andy Shevchenko <ext-andriy.shevchenko@nokia.com> Cc: Greg Kroah-Hartman <gregkh@suse.de> --- drivers/net/sb1250-mac.c | 32 ++------------------------------ 1 files changed, 2 insertions(+), 30 deletions(-) diff --git a/drivers/net/sb1250-mac.c b/drivers/net/sb1250-mac.c index 564d4d7..87c57cb 100644 --- a/drivers/net/sb1250-mac.c +++ b/drivers/net/sb1250-mac.c @@ -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++; -- 1.5.6.5 ^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 06/11] drivers: net: use new hex_to_bin() method 2010-02-22 18:09 ` [PATCH 05/11] drivers: net: " Andy Shevchenko @ 2010-02-22 18:09 ` Andy Shevchenko 2010-02-22 18:09 ` [PATCH 07/11] sysctl: don't use own implementation of hex_to_bin() Andy Shevchenko 0 siblings, 1 reply; 21+ messages in thread From: Andy Shevchenko @ 2010-02-22 18:09 UTC (permalink / raw) To: linux-kernel; +Cc: Andy Shevchenko, Divy Le Ray From: Andy Shevchenko <ext-andriy.shevchenko@nokia.com> Get rid of own implementation of hex_to_bin(). It requires to have hex_to_bin() introduced by starter patch in series. Signed-off-by: Andy Shevchenko <ext-andriy.shevchenko@nokia.com> Cc: Divy Le Ray <divy@chelsio.com> --- drivers/net/cxgb3/t3_hw.c | 16 ++++------------ 1 files changed, 4 insertions(+), 12 deletions(-) diff --git a/drivers/net/cxgb3/t3_hw.c b/drivers/net/cxgb3/t3_hw.c index 032cfe0..b85f492 100644 --- a/drivers/net/cxgb3/t3_hw.c +++ b/drivers/net/cxgb3/t3_hw.c @@ -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; } -- 1.5.6.5 ^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 07/11] sysctl: don't use own implementation of hex_to_bin() 2010-02-22 18:09 ` [PATCH 06/11] " Andy Shevchenko @ 2010-02-22 18:09 ` Andy Shevchenko 2010-02-22 18:09 ` [PATCH 08/11] staging: rt2860: use new hex_to_bin() method Andy Shevchenko 0 siblings, 1 reply; 21+ messages in thread From: Andy Shevchenko @ 2010-02-22 18:09 UTC (permalink / raw) To: linux-kernel; +Cc: Andy Shevchenko, Eric W. Biederman, Andi Kleen From: Andy Shevchenko <ext-andriy.shevchenko@nokia.com> Get rid of own implementation of hex_to_bin(). It requires to have hex_to_bin() introduced by starter patch in the series. Signed-off-by: Andy Shevchenko <ext-andriy.shevchenko@nokia.com> Cc: Eric W. Biederman <ebiederm@xmission.com> Cc: Andi Kleen <ak@linux.intel.com> --- kernel/sysctl_binary.c | 9 +++------ 1 files changed, 3 insertions(+), 6 deletions(-) diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c index 8f5d16e..e09c852 100644 --- a/kernel/sysctl_binary.c +++ b/kernel/sysctl_binary.c @@ -13,6 +13,7 @@ #include <linux/file.h> #include <linux/ctype.h> #include <linux/netdevice.h> +#include <linux/kernel.h> #ifdef CONFIG_SYSCTL_SYSCALL @@ -1124,11 +1125,6 @@ out: return result; } -static unsigned hex_value(int ch) -{ - return isdigit(ch) ? ch - '0' : ((ch | 0x20) - 'a') + 10; -} - static ssize_t bin_uuid(struct file *file, void __user *oldval, size_t oldlen, void __user *newval, size_t newlen) { @@ -1156,7 +1152,8 @@ static ssize_t bin_uuid(struct file *file, if (!isxdigit(str[0]) || !isxdigit(str[1])) goto out; - uuid[i] = (hex_value(str[0]) << 4) | hex_value(str[1]); + uuid[i] = (hex_to_bin(str[0]) << 4) | + hex_to_bin(str[1]); str += 2; if (*str == '-') str++; -- 1.5.6.5 ^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 08/11] staging: rt2860: use new hex_to_bin() method 2010-02-22 18:09 ` [PATCH 07/11] sysctl: don't use own implementation of hex_to_bin() Andy Shevchenko @ 2010-02-22 18:09 ` Andy Shevchenko 2010-02-22 18:09 ` [PATCH 09/11] fs: ldm: don't use own implementation of hex_to_bin() Andy Shevchenko 0 siblings, 1 reply; 21+ messages in thread From: Andy Shevchenko @ 2010-02-22 18:09 UTC (permalink / raw) To: linux-kernel; +Cc: Andy Shevchenko, Greg Kroah-Hartman From: Andy Shevchenko <ext-andriy.shevchenko@nokia.com> Instead of using own implementation involve hex_to_bin() function. It requires to have hex_to_bin() introduced by starter patch in series. Signed-off-by: Andy Shevchenko <ext-andriy.shevchenko@nokia.com> Cc: Greg Kroah-Hartman <gregkh@suse.de> --- drivers/staging/rt2860/common/rtmp_init.c | 15 ++------------- drivers/staging/rt2860/rtmp.h | 2 -- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/drivers/staging/rt2860/common/rtmp_init.c b/drivers/staging/rt2860/common/rtmp_init.c index 21a95ff..a090385 100644 --- a/drivers/staging/rt2860/common/rtmp_init.c +++ b/drivers/staging/rt2860/common/rtmp_init.c @@ -2810,17 +2810,6 @@ void UserCfgInit(struct rt_rtmp_adapter *pAd) } /* IRQL = PASSIVE_LEVEL */ -u8 BtoH(char ch) -{ - if (ch >= '0' && ch <= '9') - return (ch - '0'); /* Handle numerals */ - if (ch >= 'A' && ch <= 'F') - return (ch - 'A' + 0xA); /* Handle capitol hex digits */ - if (ch >= 'a' && ch <= 'f') - return (ch - 'a' + 0xA); /* Handle small hex digits */ - return (255); -} - /* */ /* FUNCTION: AtoH(char *, u8 *, int) */ /* */ @@ -2847,8 +2836,8 @@ void AtoH(char *src, u8 *dest, int destlen) destTemp = (u8 *)dest; while (destlen--) { - *destTemp = BtoH(*srcptr++) << 4; /* Put 1st ascii byte in upper nibble. */ - *destTemp += BtoH(*srcptr++); /* Add 2nd ascii byte to above. */ + *destTemp = hex_to_bin(*srcptr++) << 4; /* Put 1st ascii byte in upper nibble. */ + *destTemp += hex_to_bin(*srcptr++); /* Add 2nd ascii byte to above. */ destTemp++; } } diff --git a/drivers/staging/rt2860/rtmp.h b/drivers/staging/rt2860/rtmp.h index c50abf4..c91dfc2 100644 --- a/drivers/staging/rt2860/rtmp.h +++ b/drivers/staging/rt2860/rtmp.h @@ -2366,8 +2366,6 @@ void RTMPMoveMemory(void *pDest, void *pSrc, unsigned long Length); void AtoH(char *src, u8 *dest, int destlen); -u8 BtoH(char ch); - void RTMPPatchMacBbpBug(struct rt_rtmp_adapter *pAd); void RTMPInitTimer(struct rt_rtmp_adapter *pAd, -- 1.5.6.5 ^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 09/11] fs: ldm: don't use own implementation of hex_to_bin() 2010-02-22 18:09 ` [PATCH 08/11] staging: rt2860: use new hex_to_bin() method Andy Shevchenko @ 2010-02-22 18:09 ` Andy Shevchenko 2010-02-22 18:09 ` [PATCH 10/11] drivers: wireless: use new hex_to_bin() method Andy Shevchenko 0 siblings, 1 reply; 21+ messages in thread From: Andy Shevchenko @ 2010-02-22 18:09 UTC (permalink / raw) To: linux-kernel; +Cc: Andy Shevchenko, Richard Russon (FlatCap) From: Andy Shevchenko <ext-andriy.shevchenko@nokia.com> Get rid of own implementation of hex_to_bin(). It requires to have hex_to_bin() introduced by starter patch in the series. Signed-off-by: Andy Shevchenko <ext-andriy.shevchenko@nokia.com> Cc: "Richard Russon (FlatCap)" <ldm@flatcap.org> --- fs/partitions/ldm.c | 18 +++++++++--------- 1 files changed, 9 insertions(+), 9 deletions(-) diff --git a/fs/partitions/ldm.c b/fs/partitions/ldm.c index 8652fb9..cb445fb 100644 --- a/fs/partitions/ldm.c +++ b/fs/partitions/ldm.c @@ -26,6 +26,7 @@ #include <linux/slab.h> #include <linux/pagemap.h> #include <linux/stringify.h> +#include <linux/kernel.h> #include "ldm.h" #include "check.h" #include "msdos.h" @@ -77,17 +78,16 @@ static int ldm_parse_hexbyte (const u8 *src) int h; /* high part */ - if ((x = src[0] - '0') <= '9'-'0') h = x; - else if ((x = src[0] - 'a') <= 'f'-'a') h = x+10; - else if ((x = src[0] - 'A') <= 'F'-'A') h = x+10; - else return -1; - h <<= 4; + x = h = hex_to_bin(src[0]); + if (h < 0) + return -1; /* low part */ - if ((x = src[1] - '0') <= '9'-'0') return h | x; - if ((x = src[1] - 'a') <= 'f'-'a') return h | (x+10); - if ((x = src[1] - 'A') <= 'F'-'A') return h | (x+10); - return -1; + h = hex_to_bin(src[1]); + if (h < 0) + return -1; + + return (x << 4) + h; } /** -- 1.5.6.5 ^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 10/11] drivers: wireless: use new hex_to_bin() method 2010-02-22 18:09 ` [PATCH 09/11] fs: ldm: don't use own implementation of hex_to_bin() Andy Shevchenko @ 2010-02-22 18:09 ` Andy Shevchenko 2010-02-22 18:09 ` [PATCH 11/11] drivers: acpi: don't use own implementation of hex_to_bin() Andy Shevchenko 0 siblings, 1 reply; 21+ messages in thread From: Andy Shevchenko @ 2010-02-22 18:09 UTC (permalink / raw) To: linux-kernel; +Cc: Andy Shevchenko, John W. Linville From: Andy Shevchenko <ext-andriy.shevchenko@nokia.com> Instead of using own implementation involve hex_to_bin() function. It requires to have hex_to_bin() introduced by starter patch in series. Signed-off-by: Andy Shevchenko <ext-andriy.shevchenko@nokia.com> Cc: John W. Linville <linville@tuxdriver.com> --- drivers/net/wireless/airo.c | 15 ++++----------- 1 files changed, 4 insertions(+), 11 deletions(-) diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c index 4331d67..4c4e11c 100644 --- a/drivers/net/wireless/airo.c +++ b/drivers/net/wireless/airo.c @@ -5150,13 +5150,6 @@ static void proc_SSID_on_close(struct inode *inode, struct file *file) enable_MAC(ai, 1); } -static inline u8 hexVal(char c) { - if (c>='0' && c<='9') return c -= '0'; - if (c>='a' && c<='f') return c -= 'a'-10; - if (c>='A' && c<='F') return c -= 'A'-10; - return 0; -} - static void proc_APList_on_close( struct inode *inode, struct file *file ) { struct proc_data *data = (struct proc_data *)file->private_data; struct proc_dir_entry *dp = PDE(inode); @@ -5176,11 +5169,11 @@ static void proc_APList_on_close( struct inode *inode, struct file *file ) { switch(j%3) { case 0: APList_rid.ap[i][j/3]= - hexVal(data->wbuffer[j+i*6*3])<<4; + hex_to_bin(data->wbuffer[j+i*6*3])<<4; break; case 1: APList_rid.ap[i][j/3]|= - hexVal(data->wbuffer[j+i*6*3]); + hex_to_bin(data->wbuffer[j+i*6*3]); break; } } @@ -5331,10 +5324,10 @@ static void proc_wepkey_on_close( struct inode *inode, struct file *file ) { for( i = 0; i < 16*3 && data->wbuffer[i+j]; i++ ) { switch(i%3) { case 0: - key[i/3] = hexVal(data->wbuffer[i+j])<<4; + key[i/3] = hex_to_bin(data->wbuffer[i+j])<<4; break; case 1: - key[i/3] |= hexVal(data->wbuffer[i+j]); + key[i/3] |= hex_to_bin(data->wbuffer[i+j]); break; } } -- 1.5.6.5 ^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 11/11] drivers: acpi: don't use own implementation of hex_to_bin() 2010-02-22 18:09 ` [PATCH 10/11] drivers: wireless: use new hex_to_bin() method Andy Shevchenko @ 2010-02-22 18:09 ` Andy Shevchenko 0 siblings, 0 replies; 21+ messages in thread From: Andy Shevchenko @ 2010-02-22 18:09 UTC (permalink / raw) To: linux-kernel; +Cc: Andy Shevchenko, Len Brown From: Andy Shevchenko <ext-andriy.shevchenko@nokia.com> Get rid of own implementation of hex_to_bin(). It requires to have hex_to_bin() introduced by starter patch in the series. Signed-off-by: Andy Shevchenko <ext-andriy.shevchenko@nokia.com> Cc: Len Brown <lenb@kernel.org> --- drivers/acpi/bus.c | 9 ++------- 1 files changed, 2 insertions(+), 7 deletions(-) diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c index a52126e..c42a692 100644 --- a/drivers/acpi/bus.c +++ b/drivers/acpi/bus.c @@ -362,11 +362,6 @@ static void acpi_print_osc_error(acpi_handle handle, printk("\n"); } -static u8 hex_val(unsigned char c) -{ - return isdigit(c) ? c - '0' : toupper(c) - 'A' + 10; -} - static acpi_status acpi_str_to_uuid(char *str, u8 *uuid) { int i; @@ -383,8 +378,8 @@ static acpi_status acpi_str_to_uuid(char *str, u8 *uuid) return AE_BAD_PARAMETER; } for (i = 0; i < 16; i++) { - uuid[i] = hex_val(str[opc_map_to_uuid[i]]) << 4; - uuid[i] |= hex_val(str[opc_map_to_uuid[i] + 1]); + uuid[i] = hex_to_bin(str[opc_map_to_uuid[i]]) << 4; + uuid[i] |= hex_to_bin(str[opc_map_to_uuid[i] + 1]); } return AE_OK; } -- 1.5.6.5 ^ permalink raw reply related [flat|nested] 21+ messages in thread
* Re: [PATCH 03/11] drivers: net: optimize hex2bin() 2010-02-22 18:09 ` [PATCH 03/11] drivers: net: optimize hex2bin() Andy Shevchenko 2010-02-22 18:09 ` [PATCH 04/11] usb: atm: speedtch: use new hex_to_bin() method Andy Shevchenko @ 2010-03-01 23:06 ` Geoff Levand 2010-03-02 7:59 ` [PATCHv2] " Andy Shevchenko 1 sibling, 1 reply; 21+ messages in thread From: Geoff Levand @ 2010-03-01 23:06 UTC (permalink / raw) To: Andy Shevchenko; +Cc: linux-kernel@vger.kernel.org, Andy Shevchenko Hi Andy, Sorry for the delay, I was working away from my test equipment and wanted to test this change before commenting. On 02/22/2010 10:09 AM, Andy Shevchenko wrote: > From: Andy Shevchenko <ext-andriy.shevchenko@nokia.com> > > Optimize hex2bin() function used in ps3_gelic_wireless.c. It requires to have > hex_to_bin() implementation introduced by starter patch in series. > > Signed-off-by: Andy Shevchenko <ext-andriy.shevchenko@nokia.com> > Cc: Geoff Levand <geoffrey.levand@am.sony.com> > --- > drivers/net/ps3_gelic_wireless.c | 12 ++++-------- > 1 files changed, 4 insertions(+), 8 deletions(-) > > --- a/drivers/net/ps3_gelic_wireless.c > +++ b/drivers/net/ps3_gelic_wireless.c > @@ -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)) { We should have a blank line between the two variable declarations and the if statement here. Please make an updated patch, otherwise this patch looks OK, and seems to work correctly on PS3. -Geoff ^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCHv2] drivers: net: optimize hex2bin() 2010-03-01 23:06 ` [PATCH 03/11] drivers: net: optimize hex2bin() Geoff Levand @ 2010-03-02 7:59 ` Andy Shevchenko 2010-03-02 16:04 ` Geoff Levand 0 siblings, 1 reply; 21+ messages in thread From: Andy Shevchenko @ 2010-03-02 7:59 UTC (permalink / raw) To: linux-kernel; +Cc: Andy Shevchenko, Geoff Levand From: Andy Shevchenko <ext-andriy.shevchenko@nokia.com> Optimize hex2bin() function used in ps3_gelic_wireless.c. It requires to have hex_to_bin() implementation introduced by starter patch [1] in series. [1] http://patchwork.kernel.org/patch/81224/ Signed-off-by: Andy Shevchenko <ext-andriy.shevchenko@nokia.com> Cc: Geoff Levand <geoffrey.levand@am.sony.com> --- drivers/net/ps3_gelic_wireless.c | 13 +++++-------- 1 files changed, 5 insertions(+), 8 deletions(-) diff --git a/drivers/net/ps3_gelic_wireless.c b/drivers/net/ps3_gelic_wireless.c index 227b141..7c3d7f1 100644 --- a/drivers/net/ps3_gelic_wireless.c +++ b/drivers/net/ps3_gelic_wireless.c @@ -1394,23 +1394,20 @@ 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++ = (h << 4) + l; } return 0; }; -- 1.5.6.5 ^ permalink raw reply related [flat|nested] 21+ messages in thread
* Re: [PATCHv2] drivers: net: optimize hex2bin() 2010-03-02 7:59 ` [PATCHv2] " Andy Shevchenko @ 2010-03-02 16:04 ` Geoff Levand 2010-03-03 22:02 ` Geoff Levand 0 siblings, 1 reply; 21+ messages in thread From: Geoff Levand @ 2010-03-02 16:04 UTC (permalink / raw) To: Andy Shevchenko; +Cc: linux-kernel@vger.kernel.org, Andy Shevchenko On 03/01/2010 11:59 PM, Andy Shevchenko wrote: > Optimize hex2bin() function used in ps3_gelic_wireless.c. It requires to have > hex_to_bin() implementation introduced by starter patch [1] in series. > > [1] http://patchwork.kernel.org/patch/81224/ > > Signed-off-by: Andy Shevchenko <ext-andriy.shevchenko@nokia.com> > Cc: Geoff Levand <geoffrey.levand@am.sony.com> > --- > drivers/net/ps3_gelic_wireless.c | 13 +++++-------- > 1 files changed, 5 insertions(+), 8 deletions(-) Looks good, thanks. Acked-by: Geoff Levand <geoffrey.levand@am.sony.com> ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCHv2] drivers: net: optimize hex2bin() 2010-03-02 16:04 ` Geoff Levand @ 2010-03-03 22:02 ` Geoff Levand 0 siblings, 0 replies; 21+ messages in thread From: Geoff Levand @ 2010-03-03 22:02 UTC (permalink / raw) To: Levand, Geoffrey Cc: Andy Shevchenko, linux-kernel@vger.kernel.org, Andy Shevchenko Hi, On 03/02/2010 08:04 AM, Levand, Geoffrey wrote: > On 03/01/2010 11:59 PM, Andy Shevchenko wrote: >> Optimize hex2bin() function used in ps3_gelic_wireless.c. It requires to have >> hex_to_bin() implementation introduced by starter patch [1] in series. >> >> [1] http://patchwork.kernel.org/patch/81224/ >> >> Signed-off-by: Andy Shevchenko <ext-andriy.shevchenko@nokia.com> >> Cc: Geoff Levand <geoffrey.levand@am.sony.com> >> --- >> drivers/net/ps3_gelic_wireless.c | 13 +++++-------- >> 1 files changed, 5 insertions(+), 8 deletions(-) > > Looks good, thanks. > > Acked-by: Geoff Levand <geoffrey.levand@am.sony.com> Sorry, this is now a NAK. Some PS3 driver clean-ups were merged, and Andy's change is no longer needed. Here is the commit: c1596b75c29eb5b32c65ef1e186c8b08c289bf05 - ps3_gelic_wireless: Remove PS3 gelic legacy wpa support Sorry for asking for an updated patch when this other change was queued. -Geoff ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH 02/11] drivers: isdn: use new hex_to_bin() method 2010-02-22 18:09 ` [PATCH 02/11] drivers: isdn: use new hex_to_bin() method Andy Shevchenko 2010-02-22 18:09 ` [PATCH 03/11] drivers: net: optimize hex2bin() Andy Shevchenko @ 2010-02-22 21:22 ` Tilman Schmidt 1 sibling, 0 replies; 21+ messages in thread From: Tilman Schmidt @ 2010-02-22 21:22 UTC (permalink / raw) To: Andy Shevchenko; +Cc: linux-kernel, Andy Shevchenko [-- Attachment #1: Type: text/plain, Size: 1739 bytes --] Am 22.02.2010 19:09 schrieb Andy Shevchenko: > From: Andy Shevchenko <ext-andriy.shevchenko@nokia.com> > > 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/ > > Signed-off-by: Andy Shevchenko <ext-andriy.shevchenko@nokia.com> > Cc: Tilman Schmidt <tilman@imap.cc> Acked-by: Tilman Schmidt <tilman@imap.cc> > --- > drivers/isdn/gigaset/capi.c | 13 +------------ > 1 files changed, 1 insertions(+), 12 deletions(-) > > diff --git a/drivers/isdn/gigaset/capi.c b/drivers/isdn/gigaset/capi.c > index 3f5cd06..532ca33 100644 > --- a/drivers/isdn/gigaset/capi.c > +++ b/drivers/isdn/gigaset/capi.c > @@ -183,17 +183,6 @@ static inline int ishexdigit(char c) > } > > /* > - * 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 > @@ -204,7 +193,7 @@ static int encode_ie(char *in, u8 *out, int maxlen) > while (*in) { > if (!ishexdigit(in[0]) || !ishexdigit(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; -- Tilman Schmidt E-Mail: tilman@imap.cc Bonn, Germany Diese Nachricht besteht zu 100% aus wiederverwerteten Bits. Ungeöffnet mindestens haltbar bis: (siehe Rückseite) [-- Attachment #2: OpenPGP digital signature --] [-- Type: application/pgp-signature, Size: 259 bytes --] ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH 01/11] lib: introduce common method to convert hex digits 2010-02-22 18:09 ` [PATCH 01/11] lib: introduce common method to convert hex digits Andy Shevchenko 2010-02-22 18:09 ` [PATCH 02/11] drivers: isdn: use new hex_to_bin() method Andy Shevchenko @ 2010-03-09 1:03 ` Andy Shevchenko 2010-03-09 19:57 ` Andrew Morton 1 sibling, 1 reply; 21+ messages in thread From: Andy Shevchenko @ 2010-03-09 1:03 UTC (permalink / raw) To: linux-kernel Cc: Andy Shevchenko, Andrew Morton, Ingo Molnar, Greg Kroah-Hartman On Mon, Feb 22, 2010 at 8:09 PM, Andy Shevchenko <andy.shevchenko@gmail.com> wrote: > 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. I found another more than 10 places (roughly there are > 20 of them already) with such 'copy-paste' logic. Still waiting decision to include first patch of this series... Any comments, suggestions? -- With Best Regards, Andy Shevchenko ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH 01/11] lib: introduce common method to convert hex digits 2010-03-09 1:03 ` [PATCH 01/11] lib: introduce common method to convert hex digits Andy Shevchenko @ 2010-03-09 19:57 ` Andrew Morton 2010-04-22 8:39 ` Andy Shevchenko 0 siblings, 1 reply; 21+ messages in thread From: Andrew Morton @ 2010-03-09 19:57 UTC (permalink / raw) To: Andy Shevchenko Cc: linux-kernel, Andy Shevchenko, Ingo Molnar, Greg Kroah-Hartman On Tue, 9 Mar 2010 03:03:05 +0200 Andy Shevchenko <andy.shevchenko@gmail.com> wrote: > On Mon, Feb 22, 2010 at 8:09 PM, Andy Shevchenko > <andy.shevchenko@gmail.com> wrote: > > 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. > > I found another more than 10 places (roughly there are > 20 of them > already) with such 'copy-paste' logic. Still waiting decision to > include first patch of this series... Any comments, suggestions? This patch series turned up two days before the 2.6.33 release, which is fairly exactly the time when non-bugfixes won't get looked at! I stored it all away for consideration after we've finished the 2.6.34-rc1 merge scramble. ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH 01/11] lib: introduce common method to convert hex digits 2010-03-09 19:57 ` Andrew Morton @ 2010-04-22 8:39 ` Andy Shevchenko 2010-04-29 22:11 ` Andrew Morton 0 siblings, 1 reply; 21+ messages in thread From: Andy Shevchenko @ 2010-04-22 8:39 UTC (permalink / raw) To: Andrew Morton Cc: linux-kernel, Andy Shevchenko, Ingo Molnar, Greg Kroah-Hartman On Tue, Mar 9, 2010 at 10:57 PM, Andrew Morton <akpm@linux-foundation.org> wrote: > This patch series turned up two days before the 2.6.33 release, which > is fairly exactly the time when non-bugfixes won't get looked at! I > stored it all away for consideration after we've finished the > 2.6.34-rc1 merge scramble. Any news here? Should I resubmit series? -- With Best Regards, Andy Shevchenko ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH 01/11] lib: introduce common method to convert hex digits 2010-04-22 8:39 ` Andy Shevchenko @ 2010-04-29 22:11 ` Andrew Morton 0 siblings, 0 replies; 21+ messages in thread From: Andrew Morton @ 2010-04-29 22:11 UTC (permalink / raw) To: Andy Shevchenko Cc: linux-kernel, Andy Shevchenko, Ingo Molnar, Greg Kroah-Hartman On Thu, 22 Apr 2010 11:39:51 +0300 Andy Shevchenko <andy.shevchenko@gmail.com> wrote: > On Tue, Mar 9, 2010 at 10:57 PM, Andrew Morton > <akpm@linux-foundation.org> wrote: > > This patch series turned up two days before the 2.6.33 release, which > > is fairly exactly the time when non-bugfixes won't get looked at! __I > > stored it all away for consideration after we've finished the > > 2.6.34-rc1 merge scramble. > > Any news here? Ancient history ;) > Should I resubmit series? Yes please. ^ permalink raw reply [flat|nested] 21+ messages in thread
end of thread, other threads:[~2010-04-30 17:08 UTC | newest] Thread overview: 21+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2010-02-22 18:08 [PATCH 00/11] Introduce common hex_to_bin() helper Andy Shevchenko 2010-02-22 18:09 ` [PATCH 01/11] lib: introduce common method to convert hex digits Andy Shevchenko 2010-02-22 18:09 ` [PATCH 02/11] drivers: isdn: use new hex_to_bin() method Andy Shevchenko 2010-02-22 18:09 ` [PATCH 03/11] drivers: net: optimize hex2bin() Andy Shevchenko 2010-02-22 18:09 ` [PATCH 04/11] usb: atm: speedtch: use new hex_to_bin() method Andy Shevchenko 2010-02-22 18:09 ` [PATCH 05/11] drivers: net: " Andy Shevchenko 2010-02-22 18:09 ` [PATCH 06/11] " Andy Shevchenko 2010-02-22 18:09 ` [PATCH 07/11] sysctl: don't use own implementation of hex_to_bin() Andy Shevchenko 2010-02-22 18:09 ` [PATCH 08/11] staging: rt2860: use new hex_to_bin() method Andy Shevchenko 2010-02-22 18:09 ` [PATCH 09/11] fs: ldm: don't use own implementation of hex_to_bin() Andy Shevchenko 2010-02-22 18:09 ` [PATCH 10/11] drivers: wireless: use new hex_to_bin() method Andy Shevchenko 2010-02-22 18:09 ` [PATCH 11/11] drivers: acpi: don't use own implementation of hex_to_bin() Andy Shevchenko 2010-03-01 23:06 ` [PATCH 03/11] drivers: net: optimize hex2bin() Geoff Levand 2010-03-02 7:59 ` [PATCHv2] " Andy Shevchenko 2010-03-02 16:04 ` Geoff Levand 2010-03-03 22:02 ` Geoff Levand 2010-02-22 21:22 ` [PATCH 02/11] drivers: isdn: use new hex_to_bin() method Tilman Schmidt 2010-03-09 1:03 ` [PATCH 01/11] lib: introduce common method to convert hex digits Andy Shevchenko 2010-03-09 19:57 ` Andrew Morton 2010-04-22 8:39 ` Andy Shevchenko 2010-04-29 22:11 ` Andrew Morton
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).