return ret;
 
        host->base = pcim_iomap(pdev, 0, pci_resource_len(pdev, 0));
-       if (!host->base)
-               return -EINVAL;
+       if (!host->base) {
+               ret = -EINVAL;
+               goto error;
+       }
 
        /* On ThunderX these are identical */
        host->dma_base = host->base;
        host->reg_off_dma = 0x160;
 
        host->clk = devm_clk_get(dev, NULL);
-       if (IS_ERR(host->clk))
-               return PTR_ERR(host->clk);
+       if (IS_ERR(host->clk)) {
+               ret = PTR_ERR(host->clk);
+               goto error;
+       }
 
        ret = clk_prepare_enable(host->clk);
        if (ret)
-               return ret;
+               goto error;
        host->sys_freq = clk_get_rate(host->clk);
 
        spin_lock_init(&host->irq_handler_lock);
                }
        }
        clk_disable_unprepare(host->clk);
+       pci_release_regions(pdev);
        return ret;
 }
 
        writeq(dma_cfg, host->dma_base + MIO_EMM_DMA_CFG(host));
 
        clk_disable_unprepare(host->clk);
+       pci_release_regions(pdev);
 }
 
 static const struct pci_device_id thunder_mmc_id_table[] = {