Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

PCI: xilinx: Check for __get_free_pages() failure

If __get_free_pages() fails, return -ENOMEM to avoid a NULL pointer
dereference.

Signed-off-by: Kangjie Lu <kjlu@umn.edu>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Reviewed-by: Steven Price <steven.price@arm.com>
Reviewed-by: Mukesh Ojha <mojha@codeaurora.org>

authored by

Kangjie Lu and committed by
Lorenzo Pieralisi
699ca301 9e98c678

+10 -2
+10 -2
drivers/pci/controller/pcie-xilinx.c
··· 336 336 * xilinx_pcie_enable_msi - Enable MSI support 337 337 * @port: PCIe port information 338 338 */ 339 - static void xilinx_pcie_enable_msi(struct xilinx_pcie_port *port) 339 + static int xilinx_pcie_enable_msi(struct xilinx_pcie_port *port) 340 340 { 341 341 phys_addr_t msg_addr; 342 342 343 343 port->msi_pages = __get_free_pages(GFP_KERNEL, 0); 344 + if (!port->msi_pages) 345 + return -ENOMEM; 346 + 344 347 msg_addr = virt_to_phys((void *)port->msi_pages); 345 348 pcie_write(port, 0x0, XILINX_PCIE_REG_MSIBASE1); 346 349 pcie_write(port, msg_addr, XILINX_PCIE_REG_MSIBASE2); 350 + 351 + return 0; 347 352 } 348 353 349 354 /* INTx Functions */ ··· 503 498 struct device *dev = port->dev; 504 499 struct device_node *node = dev->of_node; 505 500 struct device_node *pcie_intc_node; 501 + int ret; 506 502 507 503 /* Setup INTx */ 508 504 pcie_intc_node = of_get_next_child(node, NULL); ··· 532 526 return -ENODEV; 533 527 } 534 528 535 - xilinx_pcie_enable_msi(port); 529 + ret = xilinx_pcie_enable_msi(port); 530 + if (ret) 531 + return ret; 536 532 } 537 533 538 534 return 0;