Skip to contentSkip to conversation

PCI: qcom-ep: check return value after calling platform_get_resource_byname()

PATCH Applied Yang Yingliang 3 participants 3 messages Apr 29, 2022 – Aug 16, 2022

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PCI: qcom-ep: check return value after calling platform_get_resource_byname()

If platform_get_resource_byname() fails, 'mmio_res' will be set to null pointer, it will cause null-ptr-deref when it used in qcom_pcie_perst_deassert(), so we need check the return value.

Fixes f55fee56a631 ("PCI: qcom-ep: Add Qualcomm PCIe Endpoint controller driver")
---
 drivers/pci/controller/dwc/pcie-qcom-ep.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/pci/controller/dwc/pcie-qcom-ep.c +4 -0
index 6ce8eddf3a37..becb0c2ff870 100644
@@ -416,6 +416,10 @@ static int qcom_pcie_ep_get_io_resources(struct platform_device *pdev,
 
 	pcie_ep->mmio_res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
 							 "mmio");
+	if (!pcie_ep->mmio_res) {
+		dev_err(dev, "Failed to get mmio resource\n");
+		return -EINVAL;
+	}
 
 	syscon = of_parse_phandle(dev->of_node, "qcom,perst-regs", 0);
 	if (!syscon) {
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 28 lines · Yang Yingliang

If platform_get_resource_byname() fails, 'mmio_res' will be set to null pointer, it will cause null-ptr-deref when it used in qcom_pcie_perst_deassert(), so we need check the return value.

Fixes f55fee56a631 ("PCI: qcom-ep: Add Qualcomm PCIe Endpoint controller driver")
---
 drivers/pci/controller/dwc/pcie-qcom-ep.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/pci/controller/dwc/pcie-qcom-ep.c +4 -0
index 6ce8eddf3a37..becb0c2ff870 100644
@@ -416,6 +416,10 @@ static int qcom_pcie_ep_get_io_resources(struct platform_device *pdev,
 
 	pcie_ep->mmio_res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
 							 "mmio");
+	if (!pcie_ep->mmio_res) {
+		dev_err(dev, "Failed to get mmio resource\n");
+		return -EINVAL;
+	}
 
 	syscon = of_parse_phandle(dev->of_node, "qcom,perst-regs", 0);
 	if (!syscon) {
Signature · 1 line
2.25.1
maintainer Applied
#2 lore raw
In reply to Yang Yingliang
Quoted 5 lines · Yang Yingliang

If platform_get_resource_byname() fails, 'mmio_res' will be set to null pointer, it will cause null-ptr-deref when it used in qcom_pcie_perst_deassert(), so we need check the return value.

Applied to pci/endpoint, thanks!

[1/1] PCI: qcom-ep: check return value after calling platform_get_resource_byname()

      https://git.kernel.org/lpieralisi/pci/c/a6f7fbae8371

Thanks,
Lorenzo