Skip to content

Commit 5089b3d

Browse files
Zhongqiu Hankwilczynski
authored andcommitted
PCI: endpoint: epf-mhi: Avoid NULL dereference if DT lacks 'mmio'
If platform_get_resource_byname() fails and returns NULL because DT lacks an 'mmio' property for the MHI endpoint, dereferencing res->start will cause a NULL pointer access. Add a check to prevent it. Fixes: 1bf5f25 ("PCI: endpoint: Add PCI Endpoint function driver for MHI bus") Link: https://lore.kernel.org/r/20241105120735.1240728-1-quic_zhonhan@quicinc.com Signed-off-by: Zhongqiu Han <quic_zhonhan@quicinc.com> [kwilczynski: error message update per the review feedback] Signed-off-by: Krzysztof Wilczyński <kwilczynski@kernel.org> [bhelgaas: commit log] Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Reviewed-by: Niklas Cassel <cassel@kernel.org>
1 parent 9b80bdb commit 5089b3d

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

drivers/pci/endpoint/functions/pci-epf-mhi.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -867,12 +867,18 @@ static int pci_epf_mhi_bind(struct pci_epf *epf)
867867
{
868868
struct pci_epf_mhi *epf_mhi = epf_get_drvdata(epf);
869869
struct pci_epc *epc = epf->epc;
870+
struct device *dev = &epf->dev;
870871
struct platform_device *pdev = to_platform_device(epc->dev.parent);
871872
struct resource *res;
872873
int ret;
873874

874875
/* Get MMIO base address from Endpoint controller */
875876
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mmio");
877+
if (!res) {
878+
dev_err(dev, "Failed to get \"mmio\" resource\n");
879+
return -ENODEV;
880+
}
881+
876882
epf_mhi->mmio_phys = res->start;
877883
epf_mhi->mmio_size = resource_size(res);
878884

0 commit comments

Comments
 (0)