staging: clean up code a bit, use kernel native methods
PATCH 1/1 staging: clean up code a bit, use kernel native methods
--- drivers/staging/otus/apdbg.c | 22 ----------------- drivers/staging/panel/panel.c | 19 +++++--------- drivers/staging/rtl8192su/r8192S_Efuse.c | 27 ++------------------- drivers/staging/wlags49_h2/wl_util.c | 37 +----------------------------- drivers/staging/wlags49_h2/wl_util.h | 2 - drivers/staging/wlan-ng/prism2sta.c | 6 +--- 6 files changed, 13 insertions(+), 100 deletions(-)
drivers/staging/otus/apdbg.c +0 -22
@@ -90,28 +90,6 @@ struct zdap_ioctl {#endif -static char hex (char v) -{ -if (isdigit (v)) -return v -'0' ; -else if (isxdigit (v)) -return tolower (v) -'a' +10 ; -else -return 0 ; -} - -static unsigned char asctohex (char *str) -{ -unsigned char value; - - value =hex (*str) &0x0f ; - value = value <<4 ; - str++; - value |=hex (*str) &0x0f ; - -return value; -} -char *prgname;int set_ioctl (int sock,struct ifreq *req)
drivers/staging/panel/panel.c +7 -12
@@ -48,6 +48,7 @@#include <linux/fcntl.h> #include <linux/init.h> #include <linux/delay.h> +#include <linux/kernel.h> #include <linux/ctype.h> #include <linux/parport.h> #include <linux/version.h>
@@ -1179,22 +1180,16 @@ static inline int handle_lcd_special_code(void)break ;while (*esc) { +char *endp; +if (*esc =='x' ) { esc++; - lcd_addr_x =0 ; -while (isdigit (*esc)) { - lcd_addr_x = lcd_addr_x *10 + - (*esc -'0' ); - esc++; - } + lcd_addr_x =simple_strtoul (esc, &endp,10 ); + esc = endp; }else if (*esc =='y' ) { esc++; - lcd_addr_y =0 ; -while (isdigit (*esc)) { - lcd_addr_y = lcd_addr_y *10 + - (*esc -'0' ); - esc++; - } + lcd_addr_y =simple_strtoul (esc, &endp,10 ); + esc = endp; }else break ; }
drivers/staging/rtl8192su/r8192S_Efuse.c +3 -24
@@ -30,6 +30,7 @@#include "r8192S_Efuse.h" #include <linux/types.h> +#include <linux/ctype.h> //typedef int INT32; //
@@ -1828,26 +1829,6 @@ EFUSE_ProgramMap(struct net_device* dev, char* pFileName,u8 TableType)#endif -// -// Description: -// Return TRUE if chTmp is represent for hex digit and -// FALSE otherwise. -// -// -bool IsHexDigit (char chTmp) -{ -if ( (chTmp >='0' && chTmp <='9' ) || - (chTmp >='a' && chTmp <='f' ) || - (chTmp >='A' && chTmp <='F' ) ) - { -return TRUE; - } -else - { -return FALSE; - } -} -/*----------------------------------------------------------------------------- * Function: efuse_ParsingMap *
@@ -1893,10 +1874,8 @@ efuse_ParsingMap(char* szStr,u32* pu4bVal,u32* pu4bMove)// Check if szScan is now pointer to a character for hex digit, // if not, it means this is not a valid hex number. -if (!IsHexDigit (*szScan)) - { +if (!isxdigit (*szScan))return FALSE; - }// Parse each digit. do
@@ -1905,7 +1884,7 @@ efuse_ParsingMap(char* szStr,u32* pu4bVal,u32* pu4bMove) szScan++; (*pu4bMove)++; - }while (IsHexDigit (*szScan)); + }while (isxdigit (*szScan));return TRUE;
drivers/staging/wlags49_h2/wl_util.c +1 -36
@@ -259,41 +259,6 @@ int is_valid_key_string( char *s )/******************************************************************************* -* hexdigit2int() -******************************************************************************* -* -* DESCRIPTION: -* -* Converts a hexadecimal digit character to an integer -* -* PARAMETERS: -* -* c - the hexadecimal digit character -* -* RETURNS: -* -* the converted integer -* -******************************************************************************/ -int hexdigit2int (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 ; -}// hexdigit2int -/*============================================================================*/ - - - - -/******************************************************************************* * key_string2key() ******************************************************************************* *
@@ -328,7 +293,7 @@ void key_string2key( char *ks, KEY_STRCT *key ) p = (char *)key->key;for ( i =2 ; i < l; i+=2 ) { - *p++ = (hexdigit2int ( ks[i] ) <<4 ) +hexdigit2int (ks[i+1 ] ); + *p++ = (hex_to_bin (ks[i]) <<4 ) +hex_to_bin (ks[i+1 ]); n++; }
drivers/staging/wlags49_h2/wl_util.h +0 -2
@@ -71,8 +71,6 @@ int is_valid_key_string( char *s );void key_string2key (char *ks,KEY_STRCT *key ); -int hexdigit2int (char c ); -void wl_hcf_error (struct net_device *dev,int hcfStatus );void wl_endian_translate_event (ltv_t *pLtv );
drivers/staging/wlan-ng/prism2sta.c +2 -4
@@ -83,8 +83,6 @@#include "hfa384x.h" #include "prism2mgmt.h" -#define wlan_hexchar (x) (((x) < 0x0a) ? ('0' + (x)) : ('a' + ((x) - 0x0a))) -/* Create a string of printable chars from something that might not be */ /* It's recommended that the str be 4*len + 1 bytes long */ #define wlan_mkprintstr (buf, buflen, str, strlen) \
@@ -99,8 +97,8 @@ }else { \ (str)[j] ='\\' ; \ (str)[j+1 ] ='x' ; \ - (str)[j+2 ] =wlan_hexchar (((buf)[i] &0xf0 ) >>4 ); \ - (str)[j+3 ] =wlan_hexchar (((buf)[i] &0x0f )); \ + (str)[j+2 ] =hex_asc_hi ((buf)[i]); \ + (str)[j+3 ] =hex_asc_lo ((buf)[i]); \ j +=4 ; \ } \ } \
Signature · 1 line
1.7.1.1
Quoted 10 lines · Andy Shevchenko
Signed-off-by Andy Shevchenko <[email protected]>Cc Greg Kroah-Hartman <[email protected]>--- drivers/staging/otus/apdbg.c | 22 ----------------- drivers/staging/panel/panel.c | 19 +++++--------- drivers/staging/rtl8192su/r8192S_Efuse.c | 27 ++------------------- drivers/staging/wlags49_h2/wl_util.c | 37 +----------------------------- drivers/staging/wlags49_h2/wl_util.h | 2 - drivers/staging/wlan-ng/prism2sta.c | 6 +---
Can you break this up into 5 different patches, one per driver, and use a better description of exactly what you did in each driver?
thanks,
greg k-h
cover staging: clean up code a bit, use kernel native methods
Andy Shevchenko (5):
staging: remove unused methods
staging: panel: change own pieces of code by strtoul()
staging: rtl8192su: don't use own isxdigit() method
staging: wlags49_h2: remove custom hex_to_bin() method
staging: wlan-ng: remove own bin2hex converter
drivers/staging/otus/apdbg.c | 22 ----------------- drivers/staging/panel/panel.c | 19 +++++--------- drivers/staging/rtl8192su/r8192S_Efuse.c | 27 ++------------------- drivers/staging/wlags49_h2/wl_util.c | 37 +----------------------------- drivers/staging/wlags49_h2/wl_util.h | 2 - drivers/staging/wlan-ng/prism2sta.c | 6 +--- 6 files changed, 13 insertions(+), 100 deletions(-)
PATCH 1/5 staging: remove unused methods
In reply to Greg KHThis is rebased version of the patch [1] which was mysteriously not pushed anywhere but acked.
Here are two methods to convert hex value to binary format. These certain methods aren't used anywhere in kernel.
[1] http://lkml.org/lkml/2010/2/18/267
--- drivers/staging/otus/apdbg.c | 22 ---------------------- 1 files changed, 0 insertions(+), 22 deletions(-)
drivers/staging/otus/apdbg.c +0 -22
@@ -90,28 +90,6 @@ struct zdap_ioctl {#endif -static char hex (char v) -{ -if (isdigit (v)) -return v -'0' ; -else if (isxdigit (v)) -return tolower (v) -'a' +10 ; -else -return 0 ; -} - -static unsigned char asctohex (char *str) -{ -unsigned char value; - - value =hex (*str) &0x0f ; - value = value <<4 ; - str++; - value |=hex (*str) &0x0f ; - -return value; -} -char *prgname;int set_ioctl (int sock,struct ifreq *req)
Signature · 1 line
1.7.1.1
PATCH 2/5 staging: panel: change own pieces of code by strtoul()
In reply to Greg KHWe have nice method simple_strtoul() to convert string to numbers which could be used here.
--- drivers/staging/panel/panel.c | 19 +++++++------------ 1 files changed, 7 insertions(+), 12 deletions(-)
drivers/staging/panel/panel.c +7 -12
@@ -48,6 +48,7 @@#include <linux/fcntl.h> #include <linux/init.h> #include <linux/delay.h> +#include <linux/kernel.h> #include <linux/ctype.h> #include <linux/parport.h> #include <linux/version.h>
@@ -1179,22 +1180,16 @@ static inline int handle_lcd_special_code(void)break ;while (*esc) { +char *endp; +if (*esc =='x' ) { esc++; - lcd_addr_x =0 ; -while (isdigit (*esc)) { - lcd_addr_x = lcd_addr_x *10 + - (*esc -'0' ); - esc++; - } + lcd_addr_x =simple_strtoul (esc, &endp,10 ); + esc = endp; }else if (*esc =='y' ) { esc++; - lcd_addr_y =0 ; -while (isdigit (*esc)) { - lcd_addr_y = lcd_addr_y *10 + - (*esc -'0' ); - esc++; - } + lcd_addr_y =simple_strtoul (esc, &endp,10 ); + esc = endp; }else break ; }
Signature · 1 line
1.7.1.1
PATCH 3/5 staging: rtl8192su: don't use own isxdigit() method
In reply to Greg KH--- drivers/staging/rtl8192su/r8192S_Efuse.c | 27 +++------------------------ 1 files changed, 3 insertions(+), 24 deletions(-)
drivers/staging/rtl8192su/r8192S_Efuse.c +3 -24
@@ -30,6 +30,7 @@#include "r8192S_Efuse.h" #include <linux/types.h> +#include <linux/ctype.h> //typedef int INT32; //
@@ -1828,26 +1829,6 @@ EFUSE_ProgramMap(struct net_device* dev, char* pFileName,u8 TableType)#endif -// -// Description: -// Return TRUE if chTmp is represent for hex digit and -// FALSE otherwise. -// -// -bool IsHexDigit (char chTmp) -{ -if ( (chTmp >='0' && chTmp <='9' ) || - (chTmp >='a' && chTmp <='f' ) || - (chTmp >='A' && chTmp <='F' ) ) - { -return TRUE; - } -else - { -return FALSE; - } -} -/*----------------------------------------------------------------------------- * Function: efuse_ParsingMap *
@@ -1893,10 +1874,8 @@ efuse_ParsingMap(char* szStr,u32* pu4bVal,u32* pu4bMove)// Check if szScan is now pointer to a character for hex digit, // if not, it means this is not a valid hex number. -if (!IsHexDigit (*szScan)) - { +if (!isxdigit (*szScan))return FALSE; - }// Parse each digit. do
@@ -1905,7 +1884,7 @@ efuse_ParsingMap(char* szStr,u32* pu4bVal,u32* pu4bMove) szScan++; (*pu4bMove)++; - }while (IsHexDigit (*szScan)); + }while (isxdigit (*szScan));return TRUE;
Signature · 1 line
1.7.1.1
PATCH 4/5 staging: wlags49_h2: remove custom hex_to_bin() method
In reply to Greg KH--- drivers/staging/wlags49_h2/wl_util.c | 37 +--------------------------------- drivers/staging/wlags49_h2/wl_util.h | 2 - 2 files changed, 1 insertions(+), 38 deletions(-)
drivers/staging/wlags49_h2/wl_util.c +1 -36
@@ -259,41 +259,6 @@ int is_valid_key_string( char *s )/******************************************************************************* -* hexdigit2int() -******************************************************************************* -* -* DESCRIPTION: -* -* Converts a hexadecimal digit character to an integer -* -* PARAMETERS: -* -* c - the hexadecimal digit character -* -* RETURNS: -* -* the converted integer -* -******************************************************************************/ -int hexdigit2int (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 ; -}// hexdigit2int -/*============================================================================*/ - - - - -/******************************************************************************* * key_string2key() ******************************************************************************* *
@@ -328,7 +293,7 @@ void key_string2key( char *ks, KEY_STRCT *key ) p = (char *)key->key;for ( i =2 ; i < l; i+=2 ) { - *p++ = (hexdigit2int ( ks[i] ) <<4 ) +hexdigit2int (ks[i+1 ] ); + *p++ = (hex_to_bin (ks[i]) <<4 ) +hex_to_bin (ks[i+1 ]); n++; }
drivers/staging/wlags49_h2/wl_util.h +0 -2
@@ -71,8 +71,6 @@ int is_valid_key_string( char *s );void key_string2key (char *ks,KEY_STRCT *key ); -int hexdigit2int (char c ); -void wl_hcf_error (struct net_device *dev,int hcfStatus );void wl_endian_translate_event (ltv_t *pLtv );
Signature · 1 line
1.7.1.1
PATCH 5/5 staging: wlan-ng: remove own bin2hex converter
In reply to Greg KHIn kernel we have hex_asc_hi and hex_asc_lo macroses to do the job.
--- drivers/staging/wlan-ng/prism2sta.c | 6 ++---- 1 files changed, 2 insertions(+), 4 deletions(-)
drivers/staging/wlan-ng/prism2sta.c +2 -4
@@ -83,8 +83,6 @@#include "hfa384x.h" #include "prism2mgmt.h" -#define wlan_hexchar (x) (((x) < 0x0a) ? ('0' + (x)) : ('a' + ((x) - 0x0a))) -/* Create a string of printable chars from something that might not be */ /* It's recommended that the str be 4*len + 1 bytes long */ #define wlan_mkprintstr (buf, buflen, str, strlen) \
@@ -99,8 +97,8 @@ }else { \ (str)[j] ='\\' ; \ (str)[j+1 ] ='x' ; \ - (str)[j+2 ] =wlan_hexchar (((buf)[i] &0xf0 ) >>4 ); \ - (str)[j+3 ] =wlan_hexchar (((buf)[i] &0x0f )); \ + (str)[j+2 ] =hex_asc_hi ((buf)[i]); \ + (str)[j+3 ] =hex_asc_lo ((buf)[i]); \ j +=4 ; \ } \ } \
Signature · 1 line
1.7.1.1