1 From 5beea4f7eaf98c304889664ae67b81ce2d3123b3 Mon Sep 17 00:00:00 2001
2 From: Kangjie Lu <kjlu@umn.edu>
3 Date: Mon, 25 Mar 2019 17:19:09 -0500
4 Subject: PCI: xilinx: Check for __get_free_pages() failure
6 [ Upstream commit 699ca30162686bf305cdf94861be02eb0cf9bda2 ]
8 If __get_free_pages() fails, return -ENOMEM to avoid a NULL pointer
11 Signed-off-by: Kangjie Lu <kjlu@umn.edu>
12 Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
13 Reviewed-by: Steven Price <steven.price@arm.com>
14 Reviewed-by: Mukesh Ojha <mojha@codeaurora.org>
15 Signed-off-by: Sasha Levin <sashal@kernel.org>
17 drivers/pci/host/pcie-xilinx.c | 12 ++++++++++--
18 1 file changed, 10 insertions(+), 2 deletions(-)
20 diff --git a/drivers/pci/host/pcie-xilinx.c b/drivers/pci/host/pcie-xilinx.c
21 index 61332f4d51c3..c3964fca57b0 100644
22 --- a/drivers/pci/host/pcie-xilinx.c
23 +++ b/drivers/pci/host/pcie-xilinx.c
24 @@ -337,14 +337,19 @@ static const struct irq_domain_ops msi_domain_ops = {
25 * xilinx_pcie_enable_msi - Enable MSI support
26 * @port: PCIe port information
28 -static void xilinx_pcie_enable_msi(struct xilinx_pcie_port *port)
29 +static int xilinx_pcie_enable_msi(struct xilinx_pcie_port *port)
33 port->msi_pages = __get_free_pages(GFP_KERNEL, 0);
34 + if (!port->msi_pages)
37 msg_addr = virt_to_phys((void *)port->msi_pages);
38 pcie_write(port, 0x0, XILINX_PCIE_REG_MSIBASE1);
39 pcie_write(port, msg_addr, XILINX_PCIE_REG_MSIBASE2);
45 @@ -516,6 +521,7 @@ static int xilinx_pcie_init_irq_domain(struct xilinx_pcie_port *port)
46 struct device *dev = port->dev;
47 struct device_node *node = dev->of_node;
48 struct device_node *pcie_intc_node;
52 pcie_intc_node = of_get_next_child(node, NULL);
53 @@ -544,7 +550,9 @@ static int xilinx_pcie_init_irq_domain(struct xilinx_pcie_port *port)
57 - xilinx_pcie_enable_msi(port);
58 + ret = xilinx_pcie_enable_msi(port);