wireless: a global static to local static improvement
There are two improvements in this simple patch: 1. wiphy_counter is a static var only used in one function, so can use local static instead of global static; 2. wiphy_counter wrap handling killed one comparision; Signed-off-by: Denis ChengRq <crquan@gmail.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
This commit is contained in:
committed by
John W. Linville
parent
acaf908d40
commit
638af07386
@@ -34,7 +34,6 @@ MODULE_DESCRIPTION("wireless configuration support");
|
|||||||
* often because we need to do it for each command */
|
* often because we need to do it for each command */
|
||||||
LIST_HEAD(cfg80211_drv_list);
|
LIST_HEAD(cfg80211_drv_list);
|
||||||
DEFINE_MUTEX(cfg80211_drv_mutex);
|
DEFINE_MUTEX(cfg80211_drv_mutex);
|
||||||
static int wiphy_counter;
|
|
||||||
|
|
||||||
/* for debugfs */
|
/* for debugfs */
|
||||||
static struct dentry *ieee80211_debugfs_dir;
|
static struct dentry *ieee80211_debugfs_dir;
|
||||||
@@ -206,6 +205,8 @@ out_unlock:
|
|||||||
|
|
||||||
struct wiphy *wiphy_new(struct cfg80211_ops *ops, int sizeof_priv)
|
struct wiphy *wiphy_new(struct cfg80211_ops *ops, int sizeof_priv)
|
||||||
{
|
{
|
||||||
|
static int wiphy_counter;
|
||||||
|
|
||||||
struct cfg80211_registered_device *drv;
|
struct cfg80211_registered_device *drv;
|
||||||
int alloc_size;
|
int alloc_size;
|
||||||
|
|
||||||
@@ -222,21 +223,18 @@ struct wiphy *wiphy_new(struct cfg80211_ops *ops, int sizeof_priv)
|
|||||||
|
|
||||||
mutex_lock(&cfg80211_drv_mutex);
|
mutex_lock(&cfg80211_drv_mutex);
|
||||||
|
|
||||||
drv->idx = wiphy_counter;
|
drv->idx = wiphy_counter++;
|
||||||
|
|
||||||
/* now increase counter for the next device unless
|
|
||||||
* it has wrapped previously */
|
|
||||||
if (wiphy_counter >= 0)
|
|
||||||
wiphy_counter++;
|
|
||||||
|
|
||||||
mutex_unlock(&cfg80211_drv_mutex);
|
|
||||||
|
|
||||||
if (unlikely(drv->idx < 0)) {
|
if (unlikely(drv->idx < 0)) {
|
||||||
|
wiphy_counter--;
|
||||||
|
mutex_unlock(&cfg80211_drv_mutex);
|
||||||
/* ugh, wrapped! */
|
/* ugh, wrapped! */
|
||||||
kfree(drv);
|
kfree(drv);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mutex_unlock(&cfg80211_drv_mutex);
|
||||||
|
|
||||||
/* give it a proper name */
|
/* give it a proper name */
|
||||||
snprintf(drv->wiphy.dev.bus_id, BUS_ID_SIZE,
|
snprintf(drv->wiphy.dev.bus_id, BUS_ID_SIZE,
|
||||||
PHY_NAME "%d", drv->idx);
|
PHY_NAME "%d", drv->idx);
|
||||||
|
Reference in New Issue
Block a user