From: Kangjie Lu <kjlu@umn.edu> To: kjlu@umn.edu Cc: pakki001@umn.edu, Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>, Bjorn Helgaas <bhelgaas@google.com>, Michal Simek <michal.simek@xilinx.com>, linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] pci: pcie-xilinx: fix a missing-check bug for __get_free_pages Date: Mon, 25 Mar 2019 16:31:13 -0500 [thread overview] Message-ID: <20190325213113.24705-1-kjlu@umn.edu> (raw) In-Reply-To: <d0aa29e9-54c6-bc8b-4827-0562b277265f@arm.com> In case __get_free_pages fail, the fix returns -ENOMEMto avoid NULL pointer dereference. Signed-off-by: Kangjie Lu <kjlu@umn.edu> Reviewed-by: Steven Price <steven.price@arm.com> --- v2: caller is redefined to accept the error code, as suggested by Steven Price <steven.price@arm.com> --- drivers/pci/controller/pcie-xilinx.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/pci/controller/pcie-xilinx.c b/drivers/pci/controller/pcie-xilinx.c index 9bd1a35cd5d8..abc214e94f7c 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 = { * xilinx_pcie_enable_msi - Enable MSI support * @port: PCIe port information */ -static void xilinx_pcie_enable_msi(struct xilinx_pcie_port *port) +static int xilinx_pcie_enable_msi(struct xilinx_pcie_port *port) { phys_addr_t msg_addr; port->msi_pages = __get_free_pages(GFP_KERNEL, 0); + if (unlikely(!port->msi_pages)) + return -ENOMEM; + msg_addr = virt_to_phys((void *)port->msi_pages); pcie_write(port, 0x0, XILINX_PCIE_REG_MSIBASE1); pcie_write(port, msg_addr, XILINX_PCIE_REG_MSIBASE2); + + return 0; } /* INTx Functions */ @@ -498,6 +503,7 @@ static int xilinx_pcie_init_irq_domain(struct xilinx_pcie_port *port) struct device *dev = port->dev; struct device_node *node = dev->of_node; struct device_node *pcie_intc_node; + int ret; /* Setup INTx */ 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) return -ENODEV; } - xilinx_pcie_enable_msi(port); + ret = xilinx_pcie_enable_msi(port); + if (ret) + return ret; } return 0; -- 2.17.1
WARNING: multiple messages have this Message-ID (diff)
From: Kangjie Lu <kjlu@umn.edu> To: kjlu@umn.edu Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>, linux-pci@vger.kernel.org, Michal Simek <michal.simek@xilinx.com>, linux-kernel@vger.kernel.org, pakki001@umn.edu, Bjorn Helgaas <bhelgaas@google.com>, linux-arm-kernel@lists.infradead.org Subject: [PATCH v2] pci: pcie-xilinx: fix a missing-check bug for __get_free_pages Date: Mon, 25 Mar 2019 16:31:13 -0500 [thread overview] Message-ID: <20190325213113.24705-1-kjlu@umn.edu> (raw) In-Reply-To: <d0aa29e9-54c6-bc8b-4827-0562b277265f@arm.com> In case __get_free_pages fail, the fix returns -ENOMEMto avoid NULL pointer dereference. Signed-off-by: Kangjie Lu <kjlu@umn.edu> Reviewed-by: Steven Price <steven.price@arm.com> --- v2: caller is redefined to accept the error code, as suggested by Steven Price <steven.price@arm.com> --- drivers/pci/controller/pcie-xilinx.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/pci/controller/pcie-xilinx.c b/drivers/pci/controller/pcie-xilinx.c index 9bd1a35cd5d8..abc214e94f7c 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 = { * xilinx_pcie_enable_msi - Enable MSI support * @port: PCIe port information */ -static void xilinx_pcie_enable_msi(struct xilinx_pcie_port *port) +static int xilinx_pcie_enable_msi(struct xilinx_pcie_port *port) { phys_addr_t msg_addr; port->msi_pages = __get_free_pages(GFP_KERNEL, 0); + if (unlikely(!port->msi_pages)) + return -ENOMEM; + msg_addr = virt_to_phys((void *)port->msi_pages); pcie_write(port, 0x0, XILINX_PCIE_REG_MSIBASE1); pcie_write(port, msg_addr, XILINX_PCIE_REG_MSIBASE2); + + return 0; } /* INTx Functions */ @@ -498,6 +503,7 @@ static int xilinx_pcie_init_irq_domain(struct xilinx_pcie_port *port) struct device *dev = port->dev; struct device_node *node = dev->of_node; struct device_node *pcie_intc_node; + int ret; /* Setup INTx */ 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) return -ENODEV; } - xilinx_pcie_enable_msi(port); + ret = xilinx_pcie_enable_msi(port); + if (ret) + return ret; } return 0; -- 2.17.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2019-03-25 21:31 UTC|newest] Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-03-14 5:58 [PATCH] pci: pcie-xilinx: fix a missing-check bug for __get_free_pages Kangjie Lu 2019-03-14 5:58 ` Kangjie Lu 2019-03-22 16:26 ` Steven Price 2019-03-22 16:26 ` Steven Price 2019-03-25 21:31 ` Kangjie Lu [this message] 2019-03-25 21:31 ` [PATCH v2] " Kangjie Lu 2019-03-25 21:51 ` Bjorn Helgaas 2019-03-25 21:51 ` Bjorn Helgaas 2019-03-25 22:19 ` [PATCH v3] PCI: xilinx: Check for __get_free_pages() failure Kangjie Lu 2019-03-25 22:19 ` Kangjie Lu 2019-03-26 11:40 ` Steven Price 2019-03-26 11:40 ` Steven Price 2019-03-27 13:36 ` Mukesh Ojha 2019-03-27 13:36 ` Mukesh Ojha 2019-03-29 16:36 ` Lorenzo Pieralisi 2019-03-29 16:36 ` Lorenzo Pieralisi 2019-03-23 21:04 [PATCH v2] pci: pcie-xilinx: fix a missing-check bug for __get_free_pages Aditya Pakki 2019-03-23 21:04 ` Aditya Pakki 2019-03-25 12:08 ` Steven Price 2019-03-25 12:08 ` Steven Price 2019-03-26 13:01 ` Robin Murphy 2019-03-26 13:01 ` Robin Murphy
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20190325213113.24705-1-kjlu@umn.edu \ --to=kjlu@umn.edu \ --cc=bhelgaas@google.com \ --cc=linux-arm-kernel@lists.infradead.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-pci@vger.kernel.org \ --cc=lorenzo.pieralisi@arm.com \ --cc=michal.simek@xilinx.com \ --cc=pakki001@umn.edu \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.