ALSA: korg1212: Fix wrongly shuffled firmware loader code
authorTakashi Iwai <tiwai@suse.de>
Tue, 20 Jul 2021 22:28:01 +0000 (00:28 +0200)
committerTakashi Iwai <tiwai@suse.de>
Tue, 20 Jul 2021 22:32:25 +0000 (00:32 +0200)
The recent change for the devres introduced the wrong code shuffling
in the korg1212 firmware loader function that may lead to a bad
pointer access.  Restore the calls in the right order (and put back
the release_firmware() call in the error path, too).

Fixes: b5cde369b618 ("ALSA: korg1212: Allocate resources with device-managed APIs")
Reported-by: Nathan Chancellor <nathan@kernel.org>
Link: https://lore.kernel.org/r/s5heebsoc26.wl-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/pci/korg1212/korg1212.c

index 7872abb..49ed2bf 100644 (file)
@@ -2256,17 +2256,19 @@ static int snd_korg1212_create(struct snd_card *card, struct pci_dev *pci)
         korg1212->AdatTimeCodePhy = korg1212->sharedBufferPhy +
                offsetof(struct KorgSharedBuffer, AdatTimeCode);
 
-       korg1212->dma_dsp = snd_devm_alloc_pages(&pci->dev, SNDRV_DMA_TYPE_DEV,
-                                                dsp_code->size);
-       if (!korg1212->dma_dsp)
-               return -ENOMEM;
-
        err = request_firmware(&dsp_code, "korg/k1212.dsp", &pci->dev);
        if (err < 0) {
                snd_printk(KERN_ERR "firmware not available\n");
                return err;
        }
 
+       korg1212->dma_dsp = snd_devm_alloc_pages(&pci->dev, SNDRV_DMA_TYPE_DEV,
+                                                dsp_code->size);
+       if (!korg1212->dma_dsp) {
+               release_firmware(dsp_code);
+               return -ENOMEM;
+       }
+
         K1212_DEBUG_PRINTK("K1212_DEBUG: DSP Code area = 0x%p (0x%08x) %d bytes [%s]\n",
                   korg1212->dma_dsp->area, korg1212->dma_dsp->addr, dsp_code->size,
                   stateName[korg1212->cardState]);