Commit ed68ebca authored by Michal Kazior's avatar Michal Kazior Committed by Johannes Berg

mac80211: split ieee80211_new_chanctx()

The function did a little too much. Split it up so
the code can be easily reused in the future.
Signed-off-by: default avatarMichal Kazior <michal.kazior@tieto.com>
Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
parent 13f348a8
...@@ -351,19 +351,17 @@ static bool ieee80211_is_radar_required(struct ieee80211_local *local) ...@@ -351,19 +351,17 @@ static bool ieee80211_is_radar_required(struct ieee80211_local *local)
} }
static struct ieee80211_chanctx * static struct ieee80211_chanctx *
ieee80211_new_chanctx(struct ieee80211_local *local, ieee80211_alloc_chanctx(struct ieee80211_local *local,
const struct cfg80211_chan_def *chandef, const struct cfg80211_chan_def *chandef,
enum ieee80211_chanctx_mode mode) enum ieee80211_chanctx_mode mode)
{ {
struct ieee80211_chanctx *ctx; struct ieee80211_chanctx *ctx;
u32 changed;
int err;
lockdep_assert_held(&local->chanctx_mtx); lockdep_assert_held(&local->chanctx_mtx);
ctx = kzalloc(sizeof(*ctx) + local->hw.chanctx_data_size, GFP_KERNEL); ctx = kzalloc(sizeof(*ctx) + local->hw.chanctx_data_size, GFP_KERNEL);
if (!ctx) if (!ctx)
return ERR_PTR(-ENOMEM); return NULL;
INIT_LIST_HEAD(&ctx->assigned_vifs); INIT_LIST_HEAD(&ctx->assigned_vifs);
INIT_LIST_HEAD(&ctx->reserved_vifs); INIT_LIST_HEAD(&ctx->reserved_vifs);
...@@ -373,31 +371,63 @@ ieee80211_new_chanctx(struct ieee80211_local *local, ...@@ -373,31 +371,63 @@ ieee80211_new_chanctx(struct ieee80211_local *local,
ctx->mode = mode; ctx->mode = mode;
ctx->conf.radar_enabled = ieee80211_is_radar_required(local); ctx->conf.radar_enabled = ieee80211_is_radar_required(local);
ieee80211_recalc_chanctx_min_def(local, ctx); ieee80211_recalc_chanctx_min_def(local, ctx);
return ctx;
}
static int ieee80211_add_chanctx(struct ieee80211_local *local,
struct ieee80211_chanctx *ctx)
{
u32 changed;
int err;
lockdep_assert_held(&local->mtx);
lockdep_assert_held(&local->chanctx_mtx);
if (!local->use_chanctx) if (!local->use_chanctx)
local->hw.conf.radar_enabled = ctx->conf.radar_enabled; local->hw.conf.radar_enabled = ctx->conf.radar_enabled;
/* we hold the mutex to prevent idle from changing */
lockdep_assert_held(&local->mtx);
/* turn idle off *before* setting channel -- some drivers need that */ /* turn idle off *before* setting channel -- some drivers need that */
changed = ieee80211_idle_off(local); changed = ieee80211_idle_off(local);
if (changed) if (changed)
ieee80211_hw_config(local, changed); ieee80211_hw_config(local, changed);
if (!local->use_chanctx) { if (!local->use_chanctx) {
local->_oper_chandef = *chandef; local->_oper_chandef = ctx->conf.def;
ieee80211_hw_config(local, 0); ieee80211_hw_config(local, 0);
} else { } else {
err = drv_add_chanctx(local, ctx); err = drv_add_chanctx(local, ctx);
if (err) { if (err) {
kfree(ctx);
ieee80211_recalc_idle(local); ieee80211_recalc_idle(local);
return ERR_PTR(err); return err;
} }
} }
/* and keep the mutex held until the new chanctx is on the list */ return 0;
list_add_rcu(&ctx->list, &local->chanctx_list); }
static struct ieee80211_chanctx *
ieee80211_new_chanctx(struct ieee80211_local *local,
const struct cfg80211_chan_def *chandef,
enum ieee80211_chanctx_mode mode)
{
struct ieee80211_chanctx *ctx;
int err;
lockdep_assert_held(&local->mtx);
lockdep_assert_held(&local->chanctx_mtx);
ctx = ieee80211_alloc_chanctx(local, chandef, mode);
if (!ctx)
return ERR_PTR(-ENOMEM);
err = ieee80211_add_chanctx(local, ctx);
if (err) {
kfree(ctx);
return ERR_PTR(err);
}
list_add_rcu(&ctx->list, &local->chanctx_list);
return ctx; return ctx;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment