diff mbox series

pci: pcie-rcar: fix a potential NULL pointer dereference

Message ID 20190314055608.5209-1-kjlu@umn.edu (mailing list archive)
State Superseded
Delegated to: Geert Uytterhoeven
Headers show
Series pci: pcie-rcar: fix a potential NULL pointer dereference | expand

Commit Message

Kangjie Lu March 14, 2019, 5:56 a.m. UTC
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@umn.edu>
---
 drivers/pci/controller/pcie-rcar.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Geert Uytterhoeven March 14, 2019, 7:30 a.m. UTC | #1
Hi Kangjie,

On Thu, Mar 14, 2019 at 6:56 AM Kangjie Lu <kjlu@umn.edu> wrote:
> 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@umn.edu>

Thanks for your patch!

> --- 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");

Please drop the dev_err().
The memory allocation core will already have printed a warning, cfr.
warn_alloc() in mm/page_alloc.c.

With that fixed:
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>

> +               err = -ENOMEM;
> +               goto err;
> +       }
> +

Gr{oetje,eeting}s,

                        Geert
diff mbox series

Patch

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);