2010-02-18 18:57:31

by Andy Shevchenko

[permalink] [raw]
Subject: [PATCH 00/12] 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(-)


2010-02-18 18:57:19

by Andy Shevchenko

[permalink] [raw]
Subject: [PATCH 06/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.

Signed-off-by: Andy Shevchenko <[email protected]>
---
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..073d0a0 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++ = (u8)((h << 4) + l);
}
return 0;
};
--
1.5.6.5

2010-02-18 18:57:26

by Andy Shevchenko

[permalink] [raw]
Subject: [PATCH 12/12] drivers: wireless: use kernel's method to get byte in hex form

From: Andy Shevchenko <[email protected]>

Signed-off-by: Andy Shevchenko <[email protected]>
---
drivers/net/wireless/at76c50x-usb.c | 5 +----
1 files changed, 1 insertions(+), 4 deletions(-)

diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
index 2517364..d700d13 100644
--- a/drivers/net/wireless/at76c50x-usb.c
+++ b/drivers/net/wireless/at76c50x-usb.c
@@ -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';

--
1.5.6.5

2010-02-18 18:57:33

by Andy Shevchenko

[permalink] [raw]
Subject: [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.

Signed-off-by: Andy Shevchenko <[email protected]>
---
drivers/isdn/gigaset/capi.c | 14 ++------------
1 files changed, 2 insertions(+), 12 deletions(-)

diff --git a/drivers/isdn/gigaset/capi.c b/drivers/isdn/gigaset/capi.c
index 83c4e2f..72adcfb 100644
--- a/drivers/isdn/gigaset/capi.c
+++ b/drivers/isdn/gigaset/capi.c
@@ -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;
--
1.5.6.5

2010-02-18 18:57:48

by Andy Shevchenko

[permalink] [raw]
Subject: [PATCH 09/12] drivers: net: use kernel's method to get byte in hex form

From: Andy Shevchenko <[email protected]>

Signed-off-by: Andy Shevchenko <[email protected]>
---
drivers/net/ppp_synctty.c | 4 +---
1 files changed, 1 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ppp_synctty.c b/drivers/net/ppp_synctty.c
index 3a13cec..e4b3cf6 100644
--- a/drivers/net/ppp_synctty.c
+++ b/drivers/net/ppp_synctty.c
@@ -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;
}
}
--
1.5.6.5

2010-02-18 18:58:07

by Andy Shevchenko

[permalink] [raw]
Subject: [PATCH 07/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.

Signed-off-by: Andy Shevchenko <[email protected]>
---
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..dd1c562 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

2010-02-18 18:57:23

by Andy Shevchenko

[permalink] [raw]
Subject: [PATCH 04/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.

Signed-off-by: Andy Shevchenko <[email protected]>
---
drivers/scsi/ibmmca.c | 3 +--
1 files changed, 1 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/ibmmca.c b/drivers/scsi/ibmmca.c
index 9c1e6a5..52b03a6 100644
--- a/drivers/scsi/ibmmca.c
+++ b/drivers/scsi/ibmmca.c
@@ -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;
--
1.5.6.5

2010-02-18 18:58:33

by Andy Shevchenko

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

From: Andy Shevchenko <[email protected]>

Signed-off-by: Andy Shevchenko <[email protected]>
---
kernel/audit.c | 8 +++-----
1 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/kernel/audit.c b/kernel/audit.c
index 5feed23..160abad 100644
--- a/kernel/audit.c
+++ b/kernel/audit.c
@@ -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

2010-02-18 18:58:28

by Andy Shevchenko

[permalink] [raw]
Subject: [PATCH 03/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.

Signed-off-by: Andy Shevchenko <[email protected]>
---
drivers/staging/otus/apdbg.c | 25 -------------------------
1 files changed, 0 insertions(+), 25 deletions(-)

diff --git a/drivers/staging/otus/apdbg.c b/drivers/staging/otus/apdbg.c
index 0eb93f1..30d07ef 100644
--- a/drivers/staging/otus/apdbg.c
+++ b/drivers/staging/otus/apdbg.c
@@ -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;
-}
-
--
1.5.6.5

2010-02-18 18:58:57

by Andy Shevchenko

[permalink] [raw]
Subject: [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.

Signed-off-by: Andy Shevchenko <[email protected]>
---
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..80b3cd7 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

2010-02-18 18:59:24

by Andy Shevchenko

[permalink] [raw]
Subject: [PATCH 08/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.

Signed-off-by: Andy Shevchenko <[email protected]>
---
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

2010-02-18 18:58:59

by Andy Shevchenko

[permalink] [raw]
Subject: [PATCH 05/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.

Signed-off-by: Andy Shevchenko <[email protected]>
---
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

2010-02-18 19:00:56

by Andy Shevchenko

[permalink] [raw]
Subject: [PATCH 01/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.

Signed-off-by: Andy Shevchenko <[email protected]>
---
drivers/isdn/gigaset/capi.c | 16 +---------------
1 files changed, 1 insertions(+), 15 deletions(-)

diff --git a/drivers/isdn/gigaset/capi.c b/drivers/isdn/gigaset/capi.c
index 3f5cd06..83c4e2f 100644
--- a/drivers/isdn/gigaset/capi.c
+++ b/drivers/isdn/gigaset/capi.c
@@ -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;
--
1.5.6.5

2010-02-18 23:37:11

by Tilman Schmidt

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

Am 18.02.2010 19:55 schrieb Andy Shevchenko:
> 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.
>
> Signed-off-by: Andy Shevchenko <[email protected]>

Acked-by: Tilman Schmidt <[email protected]>

Thanks,
Tilman

> ---
> drivers/isdn/gigaset/capi.c | 16 +---------------
> 1 files changed, 1 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/isdn/gigaset/capi.c b/drivers/isdn/gigaset/capi.c
> index 3f5cd06..83c4e2f 100644
> --- a/drivers/isdn/gigaset/capi.c
> +++ b/drivers/isdn/gigaset/capi.c
> @@ -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;

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


Attachments:
signature.asc (259.00 B)
OpenPGP digital signature

2010-02-18 23:56:08

by Tilman Schmidt

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

Am 18.02.2010 19:55 schrieb Andy Shevchenko:
> 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.
>
> Signed-off-by: Andy Shevchenko <[email protected]>
> ---
> drivers/isdn/gigaset/capi.c | 14 ++------------
> 1 files changed, 2 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/isdn/gigaset/capi.c b/drivers/isdn/gigaset/capi.c
> index 83c4e2f..72adcfb 100644
> --- a/drivers/isdn/gigaset/capi.c
> +++ b/drivers/isdn/gigaset/capi.c
> @@ -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.

> @@ -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;

Otherwise, fine with me.

Thanks,
Tilman

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


Attachments:
signature.asc (259.00 B)
OpenPGP digital signature

2010-02-19 09:54:55

by Andy Shevchenko

[permalink] [raw]
Subject: [PATCHv2] 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/

Signed-off-by: Andy Shevchenko <[email protected]>
Cc: Tilman Schmidt <[email protected]>
---
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 83c4e2f..82ee085 100644
--- a/drivers/isdn/gigaset/capi.c
+++ b/drivers/isdn/gigaset/capi.c
@@ -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;
--
1.5.6.5

2010-02-19 11:41:57

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH 00/12] Clean up code to use native kernel functions when convert or check hex digits

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.

--
With Best Regards,
Andy Shevchenko

2010-02-19 14:57:49

by Greg KH

[permalink] [raw]
Subject: Re: [PATCH 03/12] staging: remove unused methods

On Thu, Feb 18, 2010 at 08:55:42PM +0200, Andy Shevchenko wrote:
> 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.
>
> Signed-off-by: Andy Shevchenko <[email protected]>

Acked-by: Greg Kroah-Hartman <[email protected]>

2010-02-19 23:45:12

by Tilman Schmidt

[permalink] [raw]
Subject: Re: [PATCH 00/12] Clean up code to use native kernel functions when convert or check hex digits

Am 19.02.2010 12:41 schrieb Andy Shevchenko:
> 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

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


Attachments:
signature.asc (259.00 B)
OpenPGP digital signature

2010-02-22 20:21:39

by Eric Paris

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

On Thu, Feb 18, 2010 at 1:55 PM, Andy Shevchenko
<[email protected]> wrote:
> From: Andy Shevchenko <[email protected]>
>
> Signed-off-by: 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


> ---
> ?kernel/audit.c | ? ?8 +++-----
> ?1 files changed, 3 insertions(+), 5 deletions(-)
>
> diff --git a/kernel/audit.c b/kernel/audit.c
> index 5feed23..160abad 100644
> --- a/kernel/audit.c
> +++ b/kernel/audit.c
> @@ -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/
>

2010-02-22 21:18:18

by Andy Shevchenko

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

On Mon, Feb 22, 2010 at 10:21 PM, Eric Paris <[email protected]> wrote:
> 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.

> 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.

--
With Best Regards,
Andy Shevchenko