Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 85fd129a authored by Luis R. Rodriguez's avatar Luis R. Rodriguez Committed by John W. Linville
Browse files

cfg80211: add wiphy_idx_valid to check for wiphy_idx sanity



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: default avatarLuis R. Rodriguez <lrodriguez@atheros.com>
Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
parent b5850a7a
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -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! */
+7 −0
Original line number Diff line number Diff line
@@ -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;