mt76: mt7615: load ROM patch before checking patch semaphore status
authorFelix Fietkau <nbd@nbd.name>
Fri, 16 Apr 2021 08:24:46 +0000 (10:24 +0200)
committerFelix Fietkau <nbd@nbd.name>
Wed, 21 Apr 2021 09:42:22 +0000 (11:42 +0200)
For MT7663, the availability of the patch files is used to detect, which
corresponding firmware is going to be used (AP firmware or STA offload
firmware). If the ROM patch was already applied, it could attempt to
load the wrong firmware (without considering the alternative).

Signed-off-by: Felix Fietkau <nbd@nbd.name>
drivers/net/wireless/mediatek/mt76/mt7615/mcu.c

index 5f37255..2e113fd 100644 (file)
@@ -1341,25 +1341,26 @@ static int mt7615_load_patch(struct mt7615_dev *dev, u32 addr, const char *name)
        const struct firmware *fw = NULL;
        int len, ret, sem;
 
+       ret = firmware_request_nowarn(&fw, name, dev->mt76.dev);
+       if (ret)
+               return ret;
+
+       if (!fw || !fw->data || fw->size < sizeof(*hdr)) {
+               dev_err(dev->mt76.dev, "Invalid firmware\n");
+               ret = -EINVAL;
+               goto release_fw;
+       }
+
        sem = mt76_connac_mcu_patch_sem_ctrl(&dev->mt76, true);
        switch (sem) {
        case PATCH_IS_DL:
-               return 0;
+               goto release_fw;
        case PATCH_NOT_DL_SEM_SUCCESS:
                break;
        default:
                dev_err(dev->mt76.dev, "Failed to get patch semaphore\n");
-               return -EAGAIN;
-       }
-
-       ret = firmware_request_nowarn(&fw, name, dev->mt76.dev);
-       if (ret)
-               goto out;
-
-       if (!fw || !fw->data || fw->size < sizeof(*hdr)) {
-               dev_err(dev->mt76.dev, "Invalid firmware\n");
-               ret = -EINVAL;
-               goto out;
+               ret = -EAGAIN;
+               goto release_fw;
        }
 
        hdr = (const struct mt7615_patch_hdr *)(fw->data);
@@ -1388,8 +1389,6 @@ static int mt7615_load_patch(struct mt7615_dev *dev, u32 addr, const char *name)
                dev_err(dev->mt76.dev, "Failed to start patch\n");
 
 out:
-       release_firmware(fw);
-
        sem = mt76_connac_mcu_patch_sem_ctrl(&dev->mt76, false);
        switch (sem) {
        case PATCH_REL_SEM_SUCCESS:
@@ -1400,6 +1399,9 @@ out:
                break;
        }
 
+release_fw:
+       release_firmware(fw);
+
        return ret;
 }