Return-path: Received: from bombadil.infradead.org ([18.85.46.34]:55331 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754002AbZBRXZr (ORCPT ); Wed, 18 Feb 2009 18:25:47 -0500 From: "Luis R. Rodriguez" To: johannes@sipsolutions.net Cc: "Luis R. Rodriguez" , linux-wireless@vger.kernel.org Subject: [PATCH v4 02/15] cfg80211: add wiphy_idx_valid to check for wiphy_idx sanity Date: Wed, 18 Feb 2009 18:25:32 -0500 Message-Id: <1234999545-14357-3-git-send-email-lrodriguez@atheros.com> (sfid-20090219_002600_151669_EADC180D) In-Reply-To: <1234999545-14357-1-git-send-email-lrodriguez@atheros.com> References: <1234999545-14357-1-git-send-email-lrodriguez@atheros.com> To: johannes@sipsolutions.net, linville@tuxdriver.com Sender: linux-wireless-owner@vger.kernel.org List-ID: 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 --- net/wireless/core.c | 5 ++++- net/wireless/core.h | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletions(-) diff --git a/net/wireless/core.c b/net/wireless/core.c index 2b3e786..35d457b 100644 --- a/net/wireless/core.c +++ b/net/wireless/core.c @@ -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! */ diff --git a/net/wireless/core.h b/net/wireless/core.h index 1783781..4f2e0fe 100644 --- a/net/wireless/core.h +++ b/net/wireless/core.h @@ -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; -- 1.6.0.3