diff options
| author | Kangjie Lu <kjlu@umn.edu> | 2019-03-25 18:19:09 -0400 |
|---|---|---|
| committer | Lorenzo Pieralisi <lorenzo.pieralisi@arm.com> | 2019-03-29 12:28:20 -0400 |
| commit | 699ca30162686bf305cdf94861be02eb0cf9bda2 (patch) | |
| tree | 34b1504fdd741b0a0149a2d5f79d080837f5d454 | |
| parent | 9e98c678c2d6ae3a17cb2de55d17f69dddaa231b (diff) | |
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>
| -rw-r--r-- | drivers/pci/controller/pcie-xilinx.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/drivers/pci/controller/pcie-xilinx.c b/drivers/pci/controller/pcie-xilinx.c index 9bd1a35cd5d8..5bf3af3b28e6 100644 --- a/drivers/pci/controller/pcie-xilinx.c +++ b/drivers/pci/controller/pcie-xilinx.c | |||
| @@ -336,14 +336,19 @@ static const struct irq_domain_ops msi_domain_ops = { | |||
| 336 | * xilinx_pcie_enable_msi - Enable MSI support | 336 | * xilinx_pcie_enable_msi - Enable MSI support |
| 337 | * @port: PCIe port information | 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 | phys_addr_t msg_addr; | 341 | phys_addr_t msg_addr; |
| 342 | 342 | ||
| 343 | port->msi_pages = __get_free_pages(GFP_KERNEL, 0); | 343 | port->msi_pages = __get_free_pages(GFP_KERNEL, 0); |
| 344 | if (!port->msi_pages) | ||
| 345 | return -ENOMEM; | ||
| 346 | |||
| 344 | msg_addr = virt_to_phys((void *)port->msi_pages); | 347 | msg_addr = virt_to_phys((void *)port->msi_pages); |
| 345 | pcie_write(port, 0x0, XILINX_PCIE_REG_MSIBASE1); | 348 | pcie_write(port, 0x0, XILINX_PCIE_REG_MSIBASE1); |
| 346 | pcie_write(port, msg_addr, XILINX_PCIE_REG_MSIBASE2); | 349 | pcie_write(port, msg_addr, XILINX_PCIE_REG_MSIBASE2); |
| 350 | |||
| 351 | return 0; | ||
| 347 | } | 352 | } |
| 348 | 353 | ||
| 349 | /* INTx Functions */ | 354 | /* INTx Functions */ |
| @@ -498,6 +503,7 @@ static int xilinx_pcie_init_irq_domain(struct xilinx_pcie_port *port) | |||
| 498 | struct device *dev = port->dev; | 503 | struct device *dev = port->dev; |
| 499 | struct device_node *node = dev->of_node; | 504 | struct device_node *node = dev->of_node; |
| 500 | struct device_node *pcie_intc_node; | 505 | struct device_node *pcie_intc_node; |
| 506 | int ret; | ||
| 501 | 507 | ||
| 502 | /* Setup INTx */ | 508 | /* Setup INTx */ |
| 503 | pcie_intc_node = of_get_next_child(node, NULL); | 509 | pcie_intc_node = of_get_next_child(node, NULL); |
| @@ -526,7 +532,9 @@ static int xilinx_pcie_init_irq_domain(struct xilinx_pcie_port *port) | |||
| 526 | return -ENODEV; | 532 | return -ENODEV; |
| 527 | } | 533 | } |
| 528 | 534 | ||
| 529 | xilinx_pcie_enable_msi(port); | 535 | ret = xilinx_pcie_enable_msi(port); |
| 536 | if (ret) | ||
| 537 | return ret; | ||
| 530 | } | 538 | } |
| 531 | 539 | ||
| 532 | return 0; | 540 | return 0; |
