Skip to content

Commit d73c419

Browse files
kengitergregkh
authored andcommitted
PCI: xilinx: Check for __get_free_pages() failure
[ Upstream commit 699ca30 ] If __get_free_pages() fails, return -ENOMEM to avoid a NULL pointer dereference. Signed-off-by: Kangjie Lu <[email protected]> Signed-off-by: Lorenzo Pieralisi <[email protected]> Reviewed-by: Steven Price <[email protected]> Reviewed-by: Mukesh Ojha <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 9cc334c commit d73c419

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

drivers/pci/host/pcie-xilinx.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,14 +337,19 @@ static const struct irq_domain_ops msi_domain_ops = {
337337
* xilinx_pcie_enable_msi - Enable MSI support
338338
* @port: PCIe port information
339339
*/
340-
static void xilinx_pcie_enable_msi(struct xilinx_pcie_port *port)
340+
static int xilinx_pcie_enable_msi(struct xilinx_pcie_port *port)
341341
{
342342
phys_addr_t msg_addr;
343343

344344
port->msi_pages = __get_free_pages(GFP_KERNEL, 0);
345+
if (!port->msi_pages)
346+
return -ENOMEM;
347+
345348
msg_addr = virt_to_phys((void *)port->msi_pages);
346349
pcie_write(port, 0x0, XILINX_PCIE_REG_MSIBASE1);
347350
pcie_write(port, msg_addr, XILINX_PCIE_REG_MSIBASE2);
351+
352+
return 0;
348353
}
349354

350355
/* INTx Functions */
@@ -516,6 +521,7 @@ static int xilinx_pcie_init_irq_domain(struct xilinx_pcie_port *port)
516521
struct device *dev = port->dev;
517522
struct device_node *node = dev->of_node;
518523
struct device_node *pcie_intc_node;
524+
int ret;
519525

520526
/* Setup INTx */
521527
pcie_intc_node = of_get_next_child(node, NULL);
@@ -544,7 +550,9 @@ static int xilinx_pcie_init_irq_domain(struct xilinx_pcie_port *port)
544550
return -ENODEV;
545551
}
546552

547-
xilinx_pcie_enable_msi(port);
553+
ret = xilinx_pcie_enable_msi(port);
554+
if (ret)
555+
return ret;
548556
}
549557

550558
return 0;

0 commit comments

Comments
 (0)