public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Niklas Cassel <cassel@kernel.org>
To: Zhongqiu Han <quic_zhonhan@quicinc.com>
Cc: manivannan.sadhasivam@linaro.org, kw@linux.com,
	kishon@kernel.org, bhelgaas@google.com, lpieralisi@kernel.org,
	dlemoal@kernel.org, mhi@lists.linux.dev,
	linux-arm-msm@vger.kernel.org, linux-pci@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] PCI: epf-mhi: Fix potential NULL dereference in pci_epf_mhi_bind()
Date: Tue, 5 Nov 2024 14:36:04 +0100	[thread overview]
Message-ID: <ZyofRAZoAE5IgCVi@ryzen> (raw)
In-Reply-To: <20241105120735.1240728-1-quic_zhonhan@quicinc.com>

On Tue, Nov 05, 2024 at 08:07:35PM +0800, Zhongqiu Han wrote:
> If platform_get_resource_byname() fails and returns NULL, dereferencing
> res->start will cause a NULL pointer access. Add a check to prevent it.
> 
> Fixes: 1bf5f25324f7 ("PCI: endpoint: Add PCI Endpoint function driver for MHI bus")
> Signed-off-by: Zhongqiu Han <quic_zhonhan@quicinc.com>
> ---
>  drivers/pci/endpoint/functions/pci-epf-mhi.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/pci/endpoint/functions/pci-epf-mhi.c b/drivers/pci/endpoint/functions/pci-epf-mhi.c
> index 7d070b1def11..2712026733ab 100644
> --- a/drivers/pci/endpoint/functions/pci-epf-mhi.c
> +++ b/drivers/pci/endpoint/functions/pci-epf-mhi.c
> @@ -873,6 +873,11 @@ static int pci_epf_mhi_bind(struct pci_epf *epf)
>  
>  	/* Get MMIO base address from Endpoint controller */
>  	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mmio");
> +	if (!res) {
> +		dev_err(&pdev->dev, "Failed to get MMIO base address\n");

dev_err(&epf->dev, "Failed to get mmio resource\n");
or
dev_err(&epf->dev, "Failed to get \"mmio\" resource\n");

Note: &epf->dev instead of &pdev->dev in order to be consistent with other
EPF ->bind() functions.

With that, feel free to add:
Reviewed-by: Niklas Cassel <cassel@kernel.org>


Kind regards,
Niklas

> +		return -ENODEV;
> +	}
> +
>  	epf_mhi->mmio_phys = res->start;
>  	epf_mhi->mmio_size = resource_size(res);
>  
> -- 
> 2.25.1
> 

  reply	other threads:[~2024-11-05 13:36 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-05 12:07 [PATCH] PCI: epf-mhi: Fix potential NULL dereference in pci_epf_mhi_bind() Zhongqiu Han
2024-11-05 13:36 ` Niklas Cassel [this message]
2024-11-05 16:07   ` Krzysztof Wilczyński
2024-11-05 17:38 ` Krzysztof Wilczyński

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=ZyofRAZoAE5IgCVi@ryzen \
    --to=cassel@kernel.org \
    --cc=bhelgaas@google.com \
    --cc=dlemoal@kernel.org \
    --cc=kishon@kernel.org \
    --cc=kw@linux.com \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lpieralisi@kernel.org \
    --cc=manivannan.sadhasivam@linaro.org \
    --cc=mhi@lists.linux.dev \
    --cc=quic_zhonhan@quicinc.com \
    /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: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox