bcm43xx: sysfs code cleanup
Subsystems (3)
PATCH 8/10 bcm43xx: sysfs code cleanup
From: Michael Buesch <[email protected]>
This cleans up the bcm43xx sysfs code and makes it compliant with the unwritten sysfs rules (at least I hope so).
---
drivers/net/wireless/bcm43xx/bcm43xx.h | 17 ++ drivers/net/wireless/bcm43xx/bcm43xx_main.c | 1 drivers/net/wireless/bcm43xx/bcm43xx_sysfs.c | 115 +++++++++-------- drivers/net/wireless/bcm43xx/bcm43xx_sysfs.h | 16 -- 4 files changed, 82 insertions(+), 67 deletions(-)
drivers/net/wireless/bcm43xx/bcm43xx.h renamed from drivers/net/wireless/bcm43xx/bcm43xx.h~bcm43xx-sysfs-code-cleanup +14 -3
@@ -15,7 +15,6 @@#include "bcm43xx_debugfs.h" #include "bcm43xx_leds.h" -#include "bcm43xx_sysfs.h" #define PFX KBUILD_MODNAME ": "
@@ -638,8 +637,6 @@ struct bcm43xx_key { };struct bcm43xx_private { -struct bcm43xx_sysfs sysfs; -struct ieee80211_device *ieee;struct ieee80211softmac_device *softmac;
@@ -772,6 +769,20 @@ struct bcm43xx_private * bcm43xx_priv(streturn ieee80211softmac_priv (dev); } +struct device ; + +static inline +struct bcm43xx_private *dev_to_bcm (struct device *dev) +{ +struct net_device *net_dev; +struct bcm43xx_private *bcm; + + net_dev =dev_get_drvdata (dev); + bcm =bcm43xx_priv (net_dev); + +return bcm; +} +/* Helper function, which returns a boolean. * TRUE, if PIO is used; FALSE, if DMA is used.
drivers/net/wireless/bcm43xx/bcm43xx_main.c renamed from drivers/net/wireless/bcm43xx/bcm43xx_main.c~bcm43xx-sysfs-code-cleanup +1 -0
@@ -52,6 +52,7 @@#include "bcm43xx_wx.h" #include "bcm43xx_ethtool.h" #include "bcm43xx_xmit.h" +#include "bcm43xx_sysfs.h" MODULE_DESCRIPTION ("Broadcom BCM43xx wireless driver" );
drivers/net/wireless/bcm43xx/bcm43xx_sysfs.c renamed from drivers/net/wireless/bcm43xx/bcm43xx_sysfs.c~bcm43xx-sysfs-code-cleanup +67 -48
217 lines not on this page · raw message
drivers/net/wireless/bcm43xx/bcm43xx_sysfs.h renamed from drivers/net/wireless/bcm43xx/bcm43xx_sysfs.h~bcm43xx-sysfs-code-cleanup +0 -16
@@ -1,22 +1,6 @@#ifndef BCM43xx_SYSFS_H_#define BCM43xx_SYSFS_H_ -#include <linux/device.h> - - -struct bcm43xx_sysfs { -struct device_attribute attr_sprom; -struct device_attribute attr_interfmode; -struct device_attribute attr_preamble; -}; - -#define devattr_to_bcm (attr, attr_name) ({ \ - struct bcm43xx_sysfs *__s; struct bcm43xx_private *__p; \ - __s = container_of((attr), struct bcm43xx_sysfs, attr_name); \ - __p = container_of(__s, struct bcm43xx_private, sysfs); \ - __p; \ - }) -struct bcm43xx_private ;int bcm43xx_sysfs_register (struct bcm43xx_private *bcm);
_
[email protected] <[email protected]> :
Quoted 10 lines
From: Michael Buesch <[email protected]>
This cleans up the bcm43xx sysfs code and makes it compliant with the unwritten sysfs rules (at least I hope so).
Signed-off-by Michael Buesch <[email protected]>Cc Jeff Garzik <[email protected]>Cc Greg KH <[email protected]>Signed-off-by Andrew Morton <[email protected]>
[...]
Quoted 3 lines
diff -puN
drivers/net/wireless/bcm43xx/bcm43xx.h~bcm43xx-sysfs-code-cleanupdrivers/net/wireless/bcm43xx/bcm43xx.hdrivers/net/wireless/bcm43xx/bcm43xx.h renamed from drivers/net/wireless/bcm43xx/bcm43xx.h~bcm43xx-sysfs-code-cleanup +0
-0
[...]
Quoted 8 lines
drivers/net/wireless/bcm43xx/bcm43xx.h renamed from drivers/net/wireless/bcm43xx/bcm43xx.h~bcm43xx-sysfs-code-cleanup +4
-0@@ -772,6 +769,20 @@ struct bcm43xx_private * bcm43xx_priv(streturn ieee80211softmac_priv (dev); } +struct device ; + +static inline +struct bcm43xx_private *dev_to_bcm (struct device *dev)
drivers/net/wireless/bcm43xx/bcm43xx.h struct bcm43xx_private * bcm43xx_priv(st · line 785
Quoted 10 lines
drivers/net/wireless/bcm43xx/bcm43xx.h renamed from drivers/net/wireless/bcm43xx/bcm43xx.h~bcm43xx-sysfs-code-cleanup +10
-0+{ +struct net_device *net_dev; +struct bcm43xx_private *bcm; + + net_dev =dev_get_drvdata (dev); + bcm =bcm43xx_priv (net_dev); + +return bcm; +} +
It's used only in bcm43xx_sysfs.c. It could go there and avoid an extra forward declaration.
[...]
Quoted 28 lines
diff -puN
drivers/net/wireless/bcm43xx/bcm43xx_sysfs.c~bcm43xx-sysfs-code-cleanupdrivers/net/wireless/bcm43xx/bcm43xx_sysfs.cdrivers/net/wireless/bcm43xx/bcm43xx_sysfs.c renamed from drivers/net/wireless/bcm43xx/bcm43xx_sysfs.c~bcm43xx-sysfs-code-cleanup +21
-0@@ -71,14 +71,46 @@ static int get_boolean(const char *buf,return -EINVAL ; } +static int sprom2hex (const u16 *sprom,char *buf,size_t buf_len) +{ +int i, pos =0 ; + +for (i =0 ; i < BCM43xx_SPROM_SIZE; i++) { + pos +=snprintf (buf + pos, buf_len - pos -1 , +"%04X" ,swab16 (sprom[i]) &0xFFFF ); + } + pos +=snprintf (buf + pos, buf_len - pos -1 ,"\n" ); + +return pos +1 ; +} + +static int hex2sprom (u16 *sprom,const char *dump,size_t len) +{ +char tmp[5 ] = {0 }; +int cnt =0 ; +unsigned long parsed; + +if (len < BCM43xx_SPROM_SIZE *sizeof (u16) *2 ) +return -EINVAL ;
drivers/net/wireless/bcm43xx/bcm43xx_sysfs.c static int get_boolean(const char *buf, · line 104
Quoted 10 lines
drivers/net/wireless/bcm43xx/bcm43xx_sysfs.c renamed from drivers/net/wireless/bcm43xx/bcm43xx_sysfs.c~bcm43xx-sysfs-code-cleanup +10
-0+ +while (cnt < BCM43xx_SPROM_SIZE) { +memcpy (tmp, dump,4 ); + dump +=4 ; + parsed =simple_strtoul (tmp,NULL ,16 ); + sprom[cnt++] =swab16 ((u16 )parsed); + } + +return 0 ; +}
"4" suggests that the code walks dump -> dump + 4*BCM43xx_SPROM_SIZE
Quoted 2 lines
drivers/net/wireless/bcm43xx/bcm43xx_sysfs.c renamed from drivers/net/wireless/bcm43xx/bcm43xx_sysfs.c~bcm43xx-sysfs-code-cleanup +0
-0static ssize_t bcm43xx_attr_sprom_store (struct device *dev,const char *buf,size_t count)
[...]
drivers/net/wireless/bcm43xx/bcm43xx_sysfs.c static ssize_t bcm43xx_attr_sprom_show(s · line 150
Quoted 5 lines
drivers/net/wireless/bcm43xx/bcm43xx_sysfs.c renamed from drivers/net/wireless/bcm43xx/bcm43xx_sysfs.c~bcm43xx-sysfs-code-cleanup +1
-4-for (i =0 ; i < BCM43xx_SPROM_SIZE; i++) { - sprom[i] = buf[i *2 ] &0xFF ; - sprom[i] |= ((u16)(buf[i *2 +1 ] &0xFF )) <<8 ; - } + err =hex2sprom (sprom, buf, count);
... whereas here it only parses buf -> buf + 2*BCM43xx_SPROM_SIZE
Signature · 1 line
Ueimor
Quoted 29 lines · you
[email protected] <[email protected]> :
Quoted 10 lines
From: Michael Buesch <[email protected]>
This cleans up the bcm43xx sysfs code and makes it compliant with the unwritten sysfs rules (at least I hope so).
Signed-off-by Michael Buesch <[email protected]>Cc Jeff Garzik <[email protected]>Cc Greg KH <[email protected]>Signed-off-by Andrew Morton <[email protected]>[...]
Quoted 3 lines
diff -puN
drivers/net/wireless/bcm43xx/bcm43xx.h~bcm43xx-sysfs-code-cleanupdrivers/net/wireless/bcm43xx/bcm43xx.hdrivers/net/wireless/bcm43xx/bcm43xx.h renamed from drivers/net/wireless/bcm43xx/bcm43xx.h~bcm43xx-sysfs-code-cleanup +0
-0[...]
Quoted 13 lines
drivers/net/wireless/bcm43xx/bcm43xx.h renamed from drivers/net/wireless/bcm43xx/bcm43xx.h~bcm43xx-sysfs-code-cleanup +9
-0@@ -772,6 +769,20 @@ struct bcm43xx_private * bcm43xx_priv(streturn ieee80211softmac_priv (dev); } +struct device ; + +static inline +struct bcm43xx_private *dev_to_bcm (struct device *dev) +{ +struct net_device *net_dev; +struct bcm43xx_private *bcm; + + net_dev =dev_get_drvdata (dev);
Quoted 8 lines
drivers/net/wireless/bcm43xx/bcm43xx.h struct bcm43xx_private * bcm43xx_priv(st · line 785
Quoted 5 lines
drivers/net/wireless/bcm43xx/bcm43xx.h renamed from drivers/net/wireless/bcm43xx/bcm43xx.h~bcm43xx-sysfs-code-cleanup +5
-0+ bcm =bcm43xx_priv (net_dev); + +return bcm; +} +It's used only in
bcm43xx_sysfs.c. It could go there and avoid an extra forward declaration.
But it is a very generic helper, that does not have anything to do with sysfs. It converts a struct device to struct bcm43xx_private. bcm43xx_sysfs.h does only contain sysfs specific stuff for bcm.
Quoted 44 lines
[...]
Quoted 28 lines
diff -puN
drivers/net/wireless/bcm43xx/bcm43xx_sysfs.c~bcm43xx-sysfs-code-cleanupdrivers/net/wireless/bcm43xx/bcm43xx_sysfs.cdrivers/net/wireless/bcm43xx/bcm43xx_sysfs.c renamed from drivers/net/wireless/bcm43xx/bcm43xx_sysfs.c~bcm43xx-sysfs-code-cleanup +21
-0@@ -71,14 +71,46 @@ static int get_boolean(const char *buf,return -EINVAL ; } +static int sprom2hex (const u16 *sprom,char *buf,size_t buf_len) +{ +int i, pos =0 ; + +for (i =0 ; i < BCM43xx_SPROM_SIZE; i++) { + pos +=snprintf (buf + pos, buf_len - pos -1 , +"%04X" ,swab16 (sprom[i]) &0xFFFF ); + } + pos +=snprintf (buf + pos, buf_len - pos -1 ,"\n" ); + +return pos +1 ; +} + +static int hex2sprom (u16 *sprom,const char *dump,size_t len) +{ +char tmp[5 ] = {0 }; +int cnt =0 ; +unsigned long parsed; + +if (len < BCM43xx_SPROM_SIZE *sizeof (u16) *2 ) +return -EINVAL ;drivers/net/wireless/bcm43xx/bcm43xx_sysfs.c static int get_boolean(const char *buf, · line 104
Quoted 10 lines
drivers/net/wireless/bcm43xx/bcm43xx_sysfs.c renamed from drivers/net/wireless/bcm43xx/bcm43xx_sysfs.c~bcm43xx-sysfs-code-cleanup +10
-0+ +while (cnt < BCM43xx_SPROM_SIZE) { +memcpy (tmp, dump,4 ); + dump +=4 ; + parsed =simple_strtoul (tmp,NULL ,16 ); + sprom[cnt++] =swab16 ((u16 )parsed); + } + +return 0 ; +}"4" suggests that the code walks dump -> dump + 4*BCM43xx_SPROM_SIZE
drivers/net/wireless/bcm43xx/bcm43xx_sysfs.c static ssize_t bcm43xx_attr_sprom_show(s · line 136
Quoted 2 lines
drivers/net/wireless/bcm43xx/bcm43xx_sysfs.c renamed from drivers/net/wireless/bcm43xx/bcm43xx_sysfs.c~bcm43xx-sysfs-code-cleanup +0
-0static ssize_t bcm43xx_attr_sprom_store (struct device *dev,const char *buf,size_t count)
Quoted 8 lines
[...]
drivers/net/wireless/bcm43xx/bcm43xx_sysfs.c static ssize_t bcm43xx_attr_sprom_show(s · line 150
Quoted 5 lines
drivers/net/wireless/bcm43xx/bcm43xx_sysfs.c renamed from drivers/net/wireless/bcm43xx/bcm43xx_sysfs.c~bcm43xx-sysfs-code-cleanup +1
-4-for (i =0 ; i < BCM43xx_SPROM_SIZE; i++) { - sprom[i] = buf[i *2 ] &0xFF ; - sprom[i] |= ((u16)(buf[i *2 +1 ] &0xFF )) <<8 ; - } + err =hex2sprom (sprom, buf, count);... whereas here it only parses buf -> buf + 2*BCM43xx_SPROM_SIZE
the deleted code parses binary input. The
new code parses human readable hex input.
Signature · 1 line
Greetings Michael.
Michael Buesch <[email protected]> :
[...]
Quoted 2 lines
the deleted code parses binary input. The
new code parses human readable hex input.
No offence intended but it was not clear from the description of the patch.
<pavlov>
Does it imply an user space visible API change ?
</pavlov>
Signature · 1 line
Ueimor
Quoted 11 lines · you
Michael Buesch <[email protected]> :
[...]Quoted 2 lines
the deleted code parses binary input. The
new code parses human readable hex input.No offence intended but it was not clear from the description of the patch.
<pavlov>
Does it imply an user space visible API change ?
</pavlov>
Yes it does, but:
* We did not release a stable kernel with it in the meantime.
* There is no software using it at the moment. (Well, the bcm43xx-sprom tool is kind of using it, but it can handle both binary and hex input anyway)
Signature · 1 line
Greetings Michael.
Michael Buesch <[email protected]> :
[...]
Quoted 5 lines
Yes it does, but:
* We did not release a stable kernel with it in the meantime.
* There is no software using it at the moment. (Well, the bcm43xx-sprom tool is kind of using it, but it can handle both binary and hex input anyway)
Ok. Thanks for the explanation.
Signature · 1 line
Ueimor