[PATCH] PCI: imx6: Avoid dereferencing a NULL clock name

Rudi Heitbaum posted 1 patch 2 months ago
There is a newer version of this series
drivers/pci/controller/dwc/pci-imx6.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
[PATCH] PCI: imx6: Avoid dereferencing a NULL clock name
Posted by Rudi Heitbaum 2 months ago
of_clk_bulk_get() leaves clk_bulk_data::id as NULL for every clock that
has no matching entry in "clock-names", which is legal: a node may list
more "clocks" phandles than it names. The extref scan dereferences that
id unconditionally, so such a node oopses during probe.

Check clk_bulk_data::id before dereferencing it.

Fixes: d8574ce57d76 ("PCI: imx6: Add external reference clock input mode support")
Cc: stable@vger.kernel.org
Signed-off-by: Rudi Heitbaum <rudi@heitbaum.com>
---
 drivers/pci/controller/dwc/pci-imx6.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c
index f7389b5437df..dcdeba1856f7 100644
--- a/drivers/pci/controller/dwc/pci-imx6.c
+++ b/drivers/pci/controller/dwc/pci-imx6.c
@@ -1831,7 +1831,8 @@ static int imx_pcie_probe(struct platform_device *pdev)
 		return dev_err_probe(dev, imx_pcie->num_clks,
 				     "failed to get clocks\n");
 	for (i = 0; i < imx_pcie->num_clks; i++)
-		if (strncmp(imx_pcie->clks[i].id, "extref", 6) == 0)
+		if (imx_pcie->clks[i].id &&
+		    strncmp(imx_pcie->clks[i].id, "extref", 6) == 0)
 			imx_pcie->enable_ext_refclk = true;
 
 	if (imx_check_flag(imx_pcie, IMX_PCIE_FLAG_HAS_PHYDRV)) {
-- 
2.53.0
Re: [PATCH] PCI: imx6: Avoid dereferencing a NULL clock name
Posted by Manivannan Sadhasivam 3 weeks, 1 day ago
On Sun, Aug 02, 2026 at 10:55:03AM +0000, Rudi Heitbaum wrote:
> of_clk_bulk_get() leaves clk_bulk_data::id as NULL for every clock that
> has no matching entry in "clock-names", which is legal: a node may list
> more "clocks" phandles than it names. The extref scan dereferences that
> id unconditionally, so such a node oopses during probe.
> 
> Check clk_bulk_data::id before dereferencing it.
> 
> Fixes: d8574ce57d76 ("PCI: imx6: Add external reference clock input mode support")
> Cc: stable@vger.kernel.org
> Signed-off-by: Rudi Heitbaum <rudi@heitbaum.com>
> ---
>  drivers/pci/controller/dwc/pci-imx6.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c
> index f7389b5437df..dcdeba1856f7 100644
> --- a/drivers/pci/controller/dwc/pci-imx6.c
> +++ b/drivers/pci/controller/dwc/pci-imx6.c
> @@ -1831,7 +1831,8 @@ static int imx_pcie_probe(struct platform_device *pdev)
>  		return dev_err_probe(dev, imx_pcie->num_clks,
>  				     "failed to get clocks\n");
>  	for (i = 0; i < imx_pcie->num_clks; i++)
> -		if (strncmp(imx_pcie->clks[i].id, "extref", 6) == 0)
> +		if (imx_pcie->clks[i].id &&
> +		    strncmp(imx_pcie->clks[i].id, "extref", 6) == 0)

As Sashiko mentioned, there are other places in this driver without the check.
Please fix all of them in a single patch.

- Mani

-- 
மணிவண்ணன் சதாசிவம்