From patchwork Mon Mar 31 10:39:21 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Kazior X-Patchwork-Id: 3913591 Return-Path: X-Original-To: patchwork-linux-wireless@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 85DA89F357 for ; Mon, 31 Mar 2014 11:43:23 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id ACE99203AC for ; Mon, 31 Mar 2014 11:43:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CED0620386 for ; Mon, 31 Mar 2014 11:43:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752666AbaCaLnR (ORCPT ); Mon, 31 Mar 2014 07:43:17 -0400 Received: from mail-we0-f172.google.com ([74.125.82.172]:47142 "EHLO mail-we0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752979AbaCaLnI (ORCPT ); Mon, 31 Mar 2014 07:43:08 -0400 Received: by mail-we0-f172.google.com with SMTP id t61so4697465wes.3 for ; Mon, 31 Mar 2014 04:43:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tieto.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=cQXJcd9pz7fdtgpVbaeLgLiX1X+n8I+DAQkpOHfZmH8=; b=Ou0nMoS0O+PmSAaIWAYQ/kKinj4fzA6NDfIp+N24eqUKU8mKqug3YloumBxMPmsJRm CUFh8uG9CrwgXOlTg7Ci9tdNgf15swyXJ4mGHi0gM7W7zggghRhEtUrDEp+ZjmEvSEQi kKtCpgbfIOs/DI+0JTQNwtoUupuNbXvCoroqg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=cQXJcd9pz7fdtgpVbaeLgLiX1X+n8I+DAQkpOHfZmH8=; b=QDMyexiIhpdAkpS1KQuJr2Z6e3QOvwMUioWqpISm+W95VSh3+Ws7ghQwQ4a1/ITU6b upN1KWFlhgZwJoSkAhqwr6pNiyd+M/BVm9zdeR2ovdxK4ExKnMrXykzK5A3RI9EdjKJT DuOvhnIPG1jMg4alP0/SOcwrFmPve1bVaDJzhH0383Y77/oUiCQ4AWXRkdHkmVKxNRry wtWJ13zuoK/2nUgk0s+OIX05KCPpZcphr3Unu9hrSbysSp0OQRAzYb2KB+bahW8CNEFJ BHnyw1f6L248A0JUQPkiFS4RAjnLJuxBsEGqObmbe2kkgVM84j2JjCseSgkiNjiGfEyE n61Q== X-Gm-Message-State: ALoCoQms/XfPHPqQyDQVzwYW6cfn19zUjFfivMaeYbM/AMMMdF4OTO/AT+I1B9OHD9vo9wIwL/We+1+Gma1Xf6AV4VYO/KAuT+ZPaKF4rC0tqvRalxFrTB8= X-Received: by 10.180.105.65 with SMTP id gk1mr11807531wib.12.1396266187518; Mon, 31 Mar 2014 04:43:07 -0700 (PDT) Received: from localhost.localdomain ([91.198.246.8]) by mx.google.com with ESMTPSA id q49sm32467516eem.34.2014.03.31.04.43.05 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 31 Mar 2014 04:43:06 -0700 (PDT) From: Michal Kazior To: linux-wireless@vger.kernel.org Cc: johannes@sipsolutions.net, Michal Kazior Subject: [PATCH v3 03/13] mac80211: prevent chanctx overcommit Date: Mon, 31 Mar 2014 12:39:21 +0200 Message-Id: <1396262371-6466-4-git-send-email-michal.kazior@tieto.com> X-Mailer: git-send-email 1.8.5.3 In-Reply-To: <1396262371-6466-1-git-send-email-michal.kazior@tieto.com> References: <1395409651-26120-1-git-send-email-michal.kazior@tieto.com> <1396262371-6466-1-git-send-email-michal.kazior@tieto.com> X-DomainID: tieto.com Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Do not allocate more channel contexts than a driver is capable for currently matching interface combination. This allows the ieee80211_vif_reserve_chanctx() to act as a guard against breaking interface combinations. Signed-off-by: Michal Kazior --- net/mac80211/chan.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/net/mac80211/chan.c b/net/mac80211/chan.c index 122033d..90cac10 100644 --- a/net/mac80211/chan.c +++ b/net/mac80211/chan.c @@ -9,6 +9,25 @@ #include "ieee80211_i.h" #include "driver-ops.h" +static int ieee80211_num_chanctx(struct ieee80211_local *local) +{ + struct ieee80211_chanctx *ctx; + int num = 0; + + lockdep_assert_held(&local->chanctx_mtx); + + list_for_each_entry(ctx, &local->chanctx_list, list) + num++; + + return num; +} + +static bool ieee80211_can_create_new_chanctx(struct ieee80211_local *local) +{ + lockdep_assert_held(&local->chanctx_mtx); + return ieee80211_num_chanctx(local) < ieee80211_max_num_channels(local); +} + static enum nl80211_chan_width ieee80211_get_sta_bw(struct ieee80211_sta *sta) { switch (sta->bandwidth) { @@ -752,13 +771,16 @@ int ieee80211_vif_reserve_chanctx(struct ieee80211_sub_if_data *sdata, * context, reserve our current context */ new_ctx = curr_ctx; - } else { + } else if (ieee80211_can_create_new_chanctx(local)) { /* create a new context and reserve it */ new_ctx = ieee80211_new_chanctx(local, chandef, mode); if (IS_ERR(new_ctx)) { ret = PTR_ERR(new_ctx); goto out; } + } else { + ret = -EBUSY; + goto out; } }