From: Lorenzo Bianconi <lorenzo@kernel.org>
To: linux-wireless@vger.kernel.org
Cc: nbd@nbd.name, helmut@subdivi.de, lorenzo.bianconi@redhat.com
Subject: Re: [PATCH wireless] wifi: mt76: do not run mt76_unregister_device() on unregistered hw
Date: Thu, 23 Feb 2023 09:46:24 +0100 [thread overview]
Message-ID: <Y/cn4KVsGVuR27Zg@lore-desk> (raw)
In-Reply-To: <be3457d82f4e44bb71a22b2b5db27b644a37b1e1.1677107277.git.lorenzo@kernel.org>
[-- Attachment #1: Type: text/plain, Size: 2965 bytes --]
> Trying to probe a mt7921e pci card without firmware results in a
> successful probe where ieee80211_register_hw hasn't been called. When
> removing the driver, ieee802111_unregister_hw is called unconditionally
> leading to a kernel NULL pointer dereference.
> Fix the issue running mt76_unregister_device routine just for registered
> hw.
Reviewing the code better, mt7921 is the only driver registering ieee80211_hw in
init work. I do not have a strong opinion if it is better this approach or the
fix posted by Helmut, I am fine both ways.
@Felix: what do you think?
Regards,
Lorenzo
>
> Link: https://bugs.debian.org/1029116
> Link: https://bugs.kali.org/view.php?id=8140
> Reported-by: Stuart Hayhurst <stuart.a.hayhurst@gmail.com>
> Fixes: 1c71e03afe4b ("mt76: mt7921: move mt7921_init_hw in a dedicated work")
> Tested-by: Helmut Grohne <helmut@freexian.com>
> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
> ---
> drivers/net/wireless/mediatek/mt76/mac80211.c | 8 ++++++++
> drivers/net/wireless/mediatek/mt76/mt76.h | 1 +
> 2 files changed, 9 insertions(+)
>
> diff --git a/drivers/net/wireless/mediatek/mt76/mac80211.c b/drivers/net/wireless/mediatek/mt76/mac80211.c
> index b117e4467c87..34abf70f44af 100644
> --- a/drivers/net/wireless/mediatek/mt76/mac80211.c
> +++ b/drivers/net/wireless/mediatek/mt76/mac80211.c
> @@ -539,6 +539,7 @@ int mt76_register_phy(struct mt76_phy *phy, bool vht,
> if (ret)
> return ret;
>
> + set_bit(MT76_STATE_REGISTERED, &phy->state);
> phy->dev->phys[phy->band_idx] = phy;
>
> return 0;
> @@ -549,6 +550,9 @@ void mt76_unregister_phy(struct mt76_phy *phy)
> {
> struct mt76_dev *dev = phy->dev;
>
> + if (!test_bit(MT76_STATE_REGISTERED, &phy->state))
> + return;
> +
> if (IS_ENABLED(CONFIG_MT76_LEDS))
> mt76_led_cleanup(phy);
> mt76_tx_status_check(dev, true);
> @@ -719,6 +723,7 @@ int mt76_register_device(struct mt76_dev *dev, bool vht,
> return ret;
>
> WARN_ON(mt76_worker_setup(hw, &dev->tx_worker, NULL, "tx"));
> + set_bit(MT76_STATE_REGISTERED, &phy->state);
> sched_set_fifo_low(dev->tx_worker.task);
>
> return 0;
> @@ -729,6 +734,9 @@ void mt76_unregister_device(struct mt76_dev *dev)
> {
> struct ieee80211_hw *hw = dev->hw;
>
> + if (!test_bit(MT76_STATE_REGISTERED, &dev->phy.state))
> + return;
> +
> if (IS_ENABLED(CONFIG_MT76_LEDS))
> mt76_led_cleanup(&dev->phy);
> mt76_tx_status_check(dev, true);
> diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h b/drivers/net/wireless/mediatek/mt76/mt76.h
> index ccca0162c8f8..183b0fc5a2d4 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt76.h
> +++ b/drivers/net/wireless/mediatek/mt76/mt76.h
> @@ -402,6 +402,7 @@ struct mt76_tx_cb {
>
> enum {
> MT76_STATE_INITIALIZED,
> + MT76_STATE_REGISTERED,
> MT76_STATE_RUNNING,
> MT76_STATE_MCU_RUNNING,
> MT76_SCANNING,
> --
> 2.39.2
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
next prev parent reply other threads:[~2023-02-23 8:46 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-22 23:10 [PATCH wireless] wifi: mt76: do not run mt76_unregister_device() on unregistered hw Lorenzo Bianconi
2023-02-23 8:46 ` Lorenzo Bianconi [this message]
2023-02-24 16:42 ` Kalle Valo
2023-03-13 13:30 ` Kalle Valo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y/cn4KVsGVuR27Zg@lore-desk \
--to=lorenzo@kernel.org \
--cc=helmut@subdivi.de \
--cc=linux-wireless@vger.kernel.org \
--cc=lorenzo.bianconi@redhat.com \
--cc=nbd@nbd.name \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox