Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Denis ChengRq and committed by
John W. Linville
638af073 acaf908d

+7 -9
+7 -9
net/wireless/core.c
··· 34 34 * often because we need to do it for each command */ 35 35 LIST_HEAD(cfg80211_drv_list); 36 36 DEFINE_MUTEX(cfg80211_drv_mutex); 37 - static int wiphy_counter; 38 37 39 38 /* for debugfs */ 40 39 static struct dentry *ieee80211_debugfs_dir; ··· 205 206 206 207 struct wiphy *wiphy_new(struct cfg80211_ops *ops, int sizeof_priv) 207 208 { 209 + static int wiphy_counter; 210 + 208 211 struct cfg80211_registered_device *drv; 209 212 int alloc_size; 210 213 ··· 223 222 224 223 mutex_lock(&cfg80211_drv_mutex); 225 224 226 - drv->idx = wiphy_counter; 227 - 228 - /* now increase counter for the next device unless 229 - * it has wrapped previously */ 230 - if (wiphy_counter >= 0) 231 - wiphy_counter++; 232 - 233 - mutex_unlock(&cfg80211_drv_mutex); 225 + drv->idx = wiphy_counter++; 234 226 235 227 if (unlikely(drv->idx < 0)) { 228 + wiphy_counter--; 229 + mutex_unlock(&cfg80211_drv_mutex); 236 230 /* ugh, wrapped! */ 237 231 kfree(drv); 238 232 return NULL; 239 233 } 234 + 235 + mutex_unlock(&cfg80211_drv_mutex); 240 236 241 237 /* give it a proper name */ 242 238 snprintf(drv->wiphy.dev.bus_id, BUS_ID_SIZE,