[PATCH] pci: pcie-rcar: fix a potential NULL pointer dereference

From: Kangjie Lu
Date: Thu Mar 14 2019 - 01:56:21 EST


In case __get_free_pages fails and returns NULL, the fix returns
-ENOMEM and releases resources to avoid NULL pointer dereference.

Signed-off-by: Kangjie Lu <kjlu@xxxxxxx>
---
drivers/pci/controller/pcie-rcar.c | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/drivers/pci/controller/pcie-rcar.c b/drivers/pci/controller/pcie-rcar.c
index c8febb009454..0ba26c31d928 100644
--- a/drivers/pci/controller/pcie-rcar.c
+++ b/drivers/pci/controller/pcie-rcar.c
@@ -929,6 +929,12 @@ static int rcar_pcie_enable_msi(struct rcar_pcie *pcie)

/* setup MSI data target */
msi->pages = __get_free_pages(GFP_KERNEL, 0);
+ if (!msi->pages) {
+ dev_err(dev, "failed to get free pages\n");
+ err = -ENOMEM;
+ goto err;
+ }
+
base = virt_to_phys((void *)msi->pages);

rcar_pci_write_reg(pcie, base | MSIFE, PCIEMSIALR);
--
2.17.1