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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5C703C4167E for ; Sat, 19 Nov 2022 02:26:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233526AbiKSC0o (ORCPT ); Fri, 18 Nov 2022 21:26:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235694AbiKSCYy (ORCPT ); Fri, 18 Nov 2022 21:24:54 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E81C8C75A6; Fri, 18 Nov 2022 18:15:48 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 9C6D1B82676; Sat, 19 Nov 2022 02:15:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3101CC433C1; Sat, 19 Nov 2022 02:15:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668824146; bh=Ozq4YijtQR1i493lILMjhtixt579srGVeKDDIqRh5xc=; h=From:To:Cc:Subject:Date:From; b=WOGch68keh07hPGHWq1Qe1c8qCBywtR1vKcVb0s8W3BWdTX3xDnnltViUHyXVwn6c fjIO7cv8clyd7OnnODZ1toJznnTqH/9mexEkmkHxugG5TJwhisJkIvyaDQllpWC+fo B5nE+1KiYpXLpVjq0Y/IXQXpXPnqWile0ZLKSzun96c2L/ripSDh8gOTxS7RuVbo2J VMuhyGb5RTa+uUCF+/VFde5xCz9hf+WpEsBQ7HZo3UEavL7K3JDWl23q0KPcdGuc0P 0WPcEx8E7+OH/y4mN6St5gASkNhbfFPSOGSs/vIXx4b4IKZLO0BSSOrC7MHjf1vKeo +3xKhphoVOM4Q== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: taozhang , Johannes Berg , Sasha Levin , johannes@sipsolutions.net, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux-wireless@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH AUTOSEL 5.4 01/11] wifi: mac80211: fix memory free error when registering wiphy fail Date: Fri, 18 Nov 2022 21:15:33 -0500 Message-Id: <20221119021543.1775315-1-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 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: taozhang [ Upstream commit 50b2e8711462409cd368c41067405aa446dfa2af ] ieee80211_register_hw free the allocated cipher suites when registering wiphy fail, and ieee80211_free_hw will re-free it. set wiphy_ciphers_allocated to false after freeing allocated cipher suites. Signed-off-by: taozhang Signed-off-by: Johannes Berg Signed-off-by: Sasha Levin --- net/mac80211/main.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/net/mac80211/main.c b/net/mac80211/main.c index f215218a88c9..fa2ac02063cf 100644 --- a/net/mac80211/main.c +++ b/net/mac80211/main.c @@ -1315,8 +1315,10 @@ int ieee80211_register_hw(struct ieee80211_hw *hw) ieee80211_led_exit(local); destroy_workqueue(local->workqueue); fail_workqueue: - if (local->wiphy_ciphers_allocated) + if (local->wiphy_ciphers_allocated) { kfree(local->hw.wiphy->cipher_suites); + local->wiphy_ciphers_allocated = false; + } kfree(local->int_scan_req); return result; } @@ -1386,8 +1388,10 @@ void ieee80211_free_hw(struct ieee80211_hw *hw) mutex_destroy(&local->iflist_mtx); mutex_destroy(&local->mtx); - if (local->wiphy_ciphers_allocated) + if (local->wiphy_ciphers_allocated) { kfree(local->hw.wiphy->cipher_suites); + local->wiphy_ciphers_allocated = false; + } idr_for_each(&local->ack_status_frames, ieee80211_free_ack_frame, NULL); -- 2.35.1