mt76: mt7921s: fix possible sdio deadlock in command fail
authorDeren Wu <deren.wu@mediatek.com>
Tue, 14 Jun 2022 07:50:24 +0000 (15:50 +0800)
committerFelix Fietkau <nbd@nbd.name>
Mon, 11 Jul 2022 11:40:02 +0000 (13:40 +0200)
Move sdio_release_host() to final resource handing

Fixes: b12deb5e86fa ("mt76: mt7921s: fix mt7921s_mcu_[fw|drv]_pmctrl")
Reported-by: YN Chen <YN.Chen@mediatek.com>
Co-developed-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
drivers/net/wireless/mediatek/mt76/mt7921/sdio_mcu.c

index 04cdeba..efcbe06 100644 (file)
@@ -135,8 +135,8 @@ int mt7921s_mcu_fw_pmctrl(struct mt7921_dev *dev)
        struct sdio_func *func = dev->mt76.sdio.func;
        struct mt76_phy *mphy = &dev->mt76.phy;
        struct mt76_connac_pm *pm = &dev->pm;
-       int err = 0;
        u32 status;
+       int err;
 
        sdio_claim_host(func);
 
@@ -147,7 +147,7 @@ int mt7921s_mcu_fw_pmctrl(struct mt7921_dev *dev)
                                         2000, 1000000);
                if (err < 0) {
                        dev_err(dev->mt76.dev, "mailbox ACK not cleared\n");
-                       goto err;
+                       goto out;
                }
        }
 
@@ -155,18 +155,18 @@ int mt7921s_mcu_fw_pmctrl(struct mt7921_dev *dev)
 
        err = readx_poll_timeout(mt76s_read_pcr, &dev->mt76, status,
                                 !(status & WHLPCR_IS_DRIVER_OWN), 2000, 1000000);
+out:
        sdio_release_host(func);
 
-err:
        if (err < 0) {
                dev_err(dev->mt76.dev, "firmware own failed\n");
                clear_bit(MT76_STATE_PM, &mphy->state);
-               err = -EIO;
+               return -EIO;
        }
 
        pm->stats.last_doze_event = jiffies;
        pm->stats.awake_time += pm->stats.last_doze_event -
                                pm->stats.last_wake_event;
 
-       return err;
+       return 0;
 }