linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] PCI: qcom-ep: check return value after calling platform_get_resource_byname()
@ 2022-04-29  8:07 Yang Yingliang
  2022-04-29 12:36 ` Andrew Halaney
  2022-08-16 11:02 ` Lorenzo Pieralisi
  0 siblings, 2 replies; 3+ messages in thread
From: Yang Yingliang @ 2022-04-29  8:07 UTC (permalink / raw)
  To: linux-kernel, linux-arm-msm, linux-pci; +Cc: mani, lorenzo.pieralisi

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")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
 drivers/pci/controller/dwc/pcie-qcom-ep.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/pci/controller/dwc/pcie-qcom-ep.c b/drivers/pci/controller/dwc/pcie-qcom-ep.c
index 6ce8eddf3a37..becb0c2ff870 100644
--- a/drivers/pci/controller/dwc/pcie-qcom-ep.c
+++ b/drivers/pci/controller/dwc/pcie-qcom-ep.c
@@ -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) {
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] PCI: qcom-ep: check return value after calling platform_get_resource_byname()
  2022-04-29  8:07 [PATCH] PCI: qcom-ep: check return value after calling platform_get_resource_byname() Yang Yingliang
@ 2022-04-29 12:36 ` Andrew Halaney
  2022-08-16 11:02 ` Lorenzo Pieralisi
  1 sibling, 0 replies; 3+ messages in thread
From: Andrew Halaney @ 2022-04-29 12:36 UTC (permalink / raw)
  To: Yang Yingliang
  Cc: linux-kernel, linux-arm-msm, linux-pci, mani, lorenzo.pieralisi

On Fri, Apr 29, 2022 at 04:07:40PM +0800, Yang Yingliang wrote:
> 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")
> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
> ---
>  drivers/pci/controller/dwc/pcie-qcom-ep.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/pci/controller/dwc/pcie-qcom-ep.c b/drivers/pci/controller/dwc/pcie-qcom-ep.c
> index 6ce8eddf3a37..becb0c2ff870 100644
> --- a/drivers/pci/controller/dwc/pcie-qcom-ep.c
> +++ b/drivers/pci/controller/dwc/pcie-qcom-ep.c
> @@ -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) {
> -- 
> 2.25.1
> 

Reviewed-by: Andrew Halaney <ahalaney@redhat.com>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] PCI: qcom-ep: check return value after calling platform_get_resource_byname()
  2022-04-29  8:07 [PATCH] PCI: qcom-ep: check return value after calling platform_get_resource_byname() Yang Yingliang
  2022-04-29 12:36 ` Andrew Halaney
@ 2022-08-16 11:02 ` Lorenzo Pieralisi
  1 sibling, 0 replies; 3+ messages in thread
From: Lorenzo Pieralisi @ 2022-08-16 11:02 UTC (permalink / raw)
  To: linux-arm-msm, Yang Yingliang, linux-kernel, linux-pci
  Cc: Lorenzo Pieralisi, mani

On Fri, 29 Apr 2022 16:07:40 +0800, Yang Yingliang wrote:
> 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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-08-16 11:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-29  8:07 [PATCH] PCI: qcom-ep: check return value after calling platform_get_resource_byname() Yang Yingliang
2022-04-29 12:36 ` Andrew Halaney
2022-08-16 11:02 ` Lorenzo Pieralisi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).