From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 58F1FC433E3 for ; Mon, 29 Mar 2021 22:33:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 33A1161985 for ; Mon, 29 Mar 2021 22:33:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233393AbhC2WcR (ORCPT ); Mon, 29 Mar 2021 18:32:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:47158 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232636AbhC2W1y (ORCPT ); Mon, 29 Mar 2021 18:27:54 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 78B3A619E4; Mon, 29 Mar 2021 22:24:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1617056660; bh=93WRCoQXNfJcy/6OKMEw6h4XEaAxLRwx9CF2+OTunBY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MJbuRMTCnqU75gCyDApCWbnSPt3a4sghgggB7Ta86mlSlm8RAHas/++3N0tjzCDYt FGK3ekVTPNgH0EOFFLidWQkj0I/kjFGTE4LDjJgpIy0o9TeQE0FYOTApPAJPRvm9Tw MQQl4xByrb+hqG07Wet82Qi8Hpp42LnJR9ImgduwMxnR5lz1vvay6gimsGQy2MXN1v nc7dMNutVMK5XJnfbUY7RCKd84vjcGmINe5a5tsO/9V7uf100s90KACI8y4b0hRXSo jtFvlb2Ak2ZcpSlPxORoN9U4dVU2K7y1L0IzxWQ3PVpQUXepvamZE4+9alzI8q9WGA y+zKAtx5XWwEg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Karthikeyan Kathirvel , Johannes Berg , Sasha Levin , linux-wireless@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH AUTOSEL 4.4 4/8] mac80211: choose first enabled channel for monitor Date: Mon, 29 Mar 2021 18:24:10 -0400 Message-Id: <20210329222415.2384075-4-sashal@kernel.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210329222415.2384075-1-sashal@kernel.org> References: <20210329222415.2384075-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Karthikeyan Kathirvel [ Upstream commit 041c881a0ba8a75f71118bd9766b78f04beed469 ] Even if the first channel from sband channel list is invalid or disabled mac80211 ends up choosing it as the default channel for monitor interfaces, making them not usable. Fix this by assigning the first available valid or enabled channel instead. Signed-off-by: Karthikeyan Kathirvel Link: https://lore.kernel.org/r/1615440547-7661-1-git-send-email-kathirve@codeaurora.org [reword commit message, comment, code cleanups] Signed-off-by: Johannes Berg Signed-off-by: Sasha Levin --- net/mac80211/main.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/net/mac80211/main.c b/net/mac80211/main.c index 15d23aeea634..2357b17254e7 100644 --- a/net/mac80211/main.c +++ b/net/mac80211/main.c @@ -889,8 +889,19 @@ int ieee80211_register_hw(struct ieee80211_hw *hw) continue; if (!dflt_chandef.chan) { + /* + * Assign the first enabled channel to dflt_chandef + * from the list of channels + */ + for (i = 0; i < sband->n_channels; i++) + if (!(sband->channels[i].flags & + IEEE80211_CHAN_DISABLED)) + break; + /* if none found then use the first anyway */ + if (i == sband->n_channels) + i = 0; cfg80211_chandef_create(&dflt_chandef, - &sband->channels[0], + &sband->channels[i], NL80211_CHAN_NO_HT); /* init channel we're on */ if (!local->use_chanctx && !local->_oper_chandef.chan) { -- 2.30.1