diff mbox

cfg80211: wext: don't use static struct

Message ID 20180116221100.10079-1-johannes@sipsolutions.net (mailing list archive)
State Accepted
Delegated to: Johannes Berg
Headers show

Commit Message

Johannes Berg Jan. 16, 2018, 10:11 p.m. UTC
From: Johannes Berg <johannes.berg@intel.com>

There's no point in persistently allocating memory for these,
they're small enough to live on the stack.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
---
 net/wireless/wext-compat.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

Comments

Ping-Ke Shih Jan. 17, 2018, 1:26 p.m. UTC | #1
On Tue, 2018-01-16 at 23:11 +0100, Johannes Berg wrote:
> From: Johannes Berg <johannes.berg@intel.com>

> 

> There's no point in persistently allocating memory for these,

> they're small enough to live on the stack.

> 

> Signed-off-by: Johannes Berg <johannes.berg@intel.com>

> ---

>  net/wireless/wext-compat.c | 9 ++-------

>  1 file changed, 2 insertions(+), 7 deletions(-)

> 

> diff --git a/net/wireless/wext-compat.c b/net/wireless/wext-compat.c

> index 05186a47878f..c2b3d5ac0554 100644

> --- a/net/wireless/wext-compat.c

> +++ b/net/wireless/wext-compat.c

> @@ -1291,9 +1291,8 @@ static struct iw_statistics

> *cfg80211_wireless_stats(struct net_device *dev)

>  {

>  	struct wireless_dev *wdev = dev->ieee80211_ptr;

>  	struct cfg80211_registered_device *rdev =

> wiphy_to_rdev(wdev->wiphy);

> -	/* we are under RTNL - globally locked - so can use static

> structs */

> -	static struct iw_statistics wstats;

> -	static struct station_info sinfo;

> +	struct iw_statistics wstats = {};

> +	struct station_info sinfo = {};

>  	u8 bssid[ETH_ALEN];

>  

>  	if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION)

> @@ -1311,13 +1310,9 @@ static struct iw_statistics

> *cfg80211_wireless_stats(struct net_device *dev)

>  	memcpy(bssid, wdev->current_bss->pub.bssid, ETH_ALEN);

>  	wdev_unlock(wdev);

>  

> -	memset(&sinfo, 0, sizeof(sinfo));

> -

>  	if (rdev_get_station(rdev, dev, bssid, &sinfo))

>  		return NULL;

>  

> -	memset(&wstats, 0, sizeof(wstats));

> -

>  	switch (rdev->wiphy.signal_type) {

>  	case CFG80211_SIGNAL_TYPE_MBM:

>  		if (sinfo.filled & BIT(NL80211_STA_INFO_SIGNAL)) {


Without these two patches, the bit rate of 'iwconfig' and 
'iw dev wlan0 link' are different. After applying the patches,
the bit rates are the same and match sniffer.

Thanks!

Tested-by: Ping-Ke Shih <pkshih@realtek.com>
diff mbox

Patch

diff --git a/net/wireless/wext-compat.c b/net/wireless/wext-compat.c
index 05186a47878f..c2b3d5ac0554 100644
--- a/net/wireless/wext-compat.c
+++ b/net/wireless/wext-compat.c
@@ -1291,9 +1291,8 @@  static struct iw_statistics *cfg80211_wireless_stats(struct net_device *dev)
 {
 	struct wireless_dev *wdev = dev->ieee80211_ptr;
 	struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
-	/* we are under RTNL - globally locked - so can use static structs */
-	static struct iw_statistics wstats;
-	static struct station_info sinfo;
+	struct iw_statistics wstats = {};
+	struct station_info sinfo = {};
 	u8 bssid[ETH_ALEN];
 
 	if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION)
@@ -1311,13 +1310,9 @@  static struct iw_statistics *cfg80211_wireless_stats(struct net_device *dev)
 	memcpy(bssid, wdev->current_bss->pub.bssid, ETH_ALEN);
 	wdev_unlock(wdev);
 
-	memset(&sinfo, 0, sizeof(sinfo));
-
 	if (rdev_get_station(rdev, dev, bssid, &sinfo))
 		return NULL;
 
-	memset(&wstats, 0, sizeof(wstats));
-
 	switch (rdev->wiphy.signal_type) {
 	case CFG80211_SIGNAL_TYPE_MBM:
 		if (sinfo.filled & BIT(NL80211_STA_INFO_SIGNAL)) {