cfg80211: add wiphy_idx_valid to check for wiphy_idx sanity
authorLuis R. Rodriguez <lrodriguez@atheros.com>
Sat, 21 Feb 2009 05:04:20 +0000 (00:04 -0500)
committerJohn W. Linville <linville@tuxdriver.com>
Fri, 27 Feb 2009 19:52:54 +0000 (14:52 -0500)
This will later be used by others, for now make use of it in
cfg80211_drv_by_wiphy_idx() to return early if an invalid
wiphy_idx has been provided.

Signed-off-by: Luis R. Rodriguez <lrodriguez@atheros.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
net/wireless/core.c
net/wireless/core.h

index 2b3e786ec53f75321a5a669979aa12c23d12a6ea..35d457b2751e2724d42e4451e11cf5e435ad6df5 100644 (file)
@@ -42,6 +42,9 @@ cfg80211_drv_by_wiphy_idx(int wiphy_idx)
 {
        struct cfg80211_registered_device *result = NULL, *drv;
 
+       if (!wiphy_idx_valid(wiphy_idx))
+               return NULL;
+
        list_for_each_entry(drv, &cfg80211_drv_list, list) {
                if (drv->wiphy_idx == wiphy_idx) {
                        result = drv;
@@ -225,7 +228,7 @@ struct wiphy *wiphy_new(struct cfg80211_ops *ops, int sizeof_priv)
 
        drv->wiphy_idx = wiphy_counter++;
 
-       if (unlikely(drv->wiphy_idx < 0)) {
+       if (unlikely(!wiphy_idx_valid(drv->wiphy_idx))) {
                wiphy_counter--;
                mutex_unlock(&cfg80211_drv_mutex);
                /* ugh, wrapped! */
index 178378124800074d0a20c64226704618c334b192..4f2e0fe38ce3fc372c0459603b9029bc8cb8ad76 100644 (file)
@@ -63,6 +63,13 @@ struct cfg80211_registered_device *wiphy_to_dev(struct wiphy *wiphy)
        return container_of(wiphy, struct cfg80211_registered_device, wiphy);
 }
 
+/* Note 0 is valid, hence phy0 */
+static inline
+bool wiphy_idx_valid(int wiphy_idx)
+{
+       return (wiphy_idx >= 0);
+}
+
 extern struct mutex cfg80211_drv_mutex;
 extern struct list_head cfg80211_drv_list;