Skip to contentSkip to conversation

fix: PCI: dra7xx: dra7xx_pcie_probe: fix missing device_link_del on phy error paths

PATCH In review WenTao Liang 3 participants 5 messages Jun 26 – Aug 16

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

PATCH 1/1 fix: PCI: dra7xx: dra7xx_pcie_probe: fix missing device_link_del on phy error paths

In dra7xx_pcie_probe(), when devm_phy_get() fails for a later phy device
(i > 0), the function directly returns PTR_ERR(phy[i]) without calling device_link_del() on previously added device links. Similarly, when dra7xx_pcie_enable_phy() fails, all phy_count device links are leaked as the function returns directly without cleanup.

Change the error paths to jump to the existing err_link label which
properly iterates through link[0..i) and calls device_link_del() for each.

---
 drivers/pci/controller/dwc/pci-dra7xx.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/pci/controller/dwc/pci-dra7xx.c +8 -4
index cd904659c321..153ee6f7dbfc 100644
@@ -743,8 +743,10 @@ static int dra7xx_pcie_probe(struct platform_device *pdev)
 	for (i = 0; i < phy_count; i++) {
 		snprintf(name, sizeof(name), "pcie-phy%d", i);
 		phy[i] = devm_phy_get(dev, name);
-		if (IS_ERR(phy[i]))
-			return PTR_ERR(phy[i]);
+		if (IS_ERR(phy[i])) {
+			ret = PTR_ERR(phy[i]);
+			goto err_link;
+		}
 
 		link[i] = device_link_add(dev, &phy[i]->dev, DL_FLAG_STATELESS);
 		if (!link[i]) {
@@ -767,7 +769,8 @@ static int dra7xx_pcie_probe(struct platform_device *pdev)
 	ret = dra7xx_pcie_enable_phy(dra7xx);
 	if (ret) {
 		dev_err(dev, "failed to enable phy\n");
-		return ret;
+		dra7xx_pcie_disable_phy(dra7xx);
+		goto err_link;
 	}
 
 	platform_set_drvdata(pdev, dra7xx);
@@ -910,7 +913,8 @@ static int dra7xx_pcie_resume_noirq(struct device *dev)
 	ret = dra7xx_pcie_enable_phy(dra7xx);
 	if (ret) {
 		dev_err(dev, "failed to enable phy\n");
-		return ret;
+		dra7xx_pcie_disable_phy(dra7xx);
+		goto err_link;
 	}
 
 	return 0;
Signature · 1 line
2.39.5 (Apple Git-154)
#1 lore raw
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] Double cleanup of PHY resources on error path. - [Low] Compilation error due to undefined label…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Double cleanup of PHY resources on error path.
- [Low] Compilation error due to undefined label err_link.
--

commit 51479d1472b27aa065c936360d150e8e275d37b6
Author: WenTao Liang <[email protected]>

fix: PCI: dra7xx: dra7xx_pcie_probe: fix missing device_link_del on phy error paths

This commit addresses a device link leak in the phy error paths of dra7xx_pcie_probe(). It changes the error paths to jump to the err_link label to properly call device_link_del() for each link. It also updates the phy enable error paths.

Quoted 4 lines
drivers/pci/controller/dwc/pci-dra7xx.c +0 -0
index 3fc889944f021..c54d68cf0e412 100644

[ ... ]

drivers/pci/controller/dwc/pci-dra7xx.c static int dra7xx_pcie_probe(struct platform_device *pdev) · line 773

Quoted 8 lines
drivers/pci/controller/dwc/pci-dra7xx.c +2 -1
@@ -766,7 +768,8 @@ static int dra7xx_pcie_probe(struct platform_device *pdev)
 	ret = dra7xx_pcie_enable_phy(dra7xx);
 	if (ret) {
 		dev_err(dev, "failed to enable phy\n");
-		return ret;
+		dra7xx_pcie_disable_phy(dra7xx);
+		goto err_link;
 	}

[Severity: High]
Does this cause a double cleanup of the PHY resources?

When dra7xx_pcie_enable_phy() fails, it already cleans up any partially enabled PHYs internally before returning. Calling dra7xx_pcie_disable_phy() here will repeat the cleanup on the same PHYs, which could lead to unbalanced reference counts in the PHY framework (underflowing power_count and init_count).

[ ... ]

drivers/pci/controller/dwc/pci-dra7xx.c static int dra7xx_pcie_resume_noirq(struct device *dev) · line 915

Quoted 6 lines
drivers/pci/controller/dwc/pci-dra7xx.c +1 -1
@@ -909,7 +912,8 @@ static int dra7xx_pcie_resume_noirq(struct device *dev)
 	ret = dra7xx_pcie_enable_phy(dra7xx);
 	if (ret) {
 		dev_err(dev, "failed to enable phy\n");
-		return ret;
+		dra7xx_pcie_disable_phy(dra7xx);

[Severity: High]
Similar to the probe function, could this cause a double cleanup of the PHY resources since dra7xx_pcie_enable_phy() handles its own cleanup on failure?

drivers/pci/controller/dwc/pci-dra7xx.c static int dra7xx_pcie_resume_noirq(struct device *dev) · line 916

Quoted 1 line
drivers/pci/controller/dwc/pci-dra7xx.c +1 -0
+		goto err_link;

[Severity: Low]
Does this label exist in this function?

It appears that the err_link label is not defined anywhere in dra7xx_pcie_resume_noirq(), which will result in a compilation error.

Quoted 3 lines
drivers/pci/controller/dwc/pci-dra7xx.c +0 -0
 	}
 
 	return 0;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw
In reply to WenTao Liang
Quoted 59 lines

2026年6月26日 23:48,WenTao Liang <[email protected]> 写道:

In dra7xx_pcie_probe(), when devm_phy_get() fails for a later phy device
(i > 0), the function directly returns PTR_ERR(phy[i]) without calling device_link_del() on previously added device links. Similarly, when dra7xx_pcie_enable_phy() fails, all phy_count device links are leaked as the function returns directly without cleanup.

Change the error paths to jump to the existing err_link label which
properly iterates through link[0..i) and calls device_link_del() for each.

---
drivers/pci/controller/dwc/pci-dra7xx.c | 12 ++++++++----

1 file changed, 8 insertions(+), 4 deletions(-)
drivers/pci/controller/dwc/pci-dra7xx.c +8 -4
index cd904659c321..153ee6f7dbfc 100644
@@ -743,8 +743,10 @@ static int dra7xx_pcie_probe(struct platform_device *pdev)
 	for (i = 0; i < phy_count; i++) {
 		snprintf(name, sizeof(name), "pcie-phy%d", i);
 		phy[i] = devm_phy_get(dev, name);
-		if (IS_ERR(phy[i]))
-			return PTR_ERR(phy[i]);
+		if (IS_ERR(phy[i])) {
+			ret = PTR_ERR(phy[i]);
+			goto err_link;
+		}
 
 		link[i] = device_link_add(dev, &phy[i]->dev, DL_FLAG_STATELESS);
 		if (!link[i]) {
@@ -767,7 +769,8 @@ static int dra7xx_pcie_probe(struct platform_device *pdev)
 	ret = dra7xx_pcie_enable_phy(dra7xx);
 	if (ret) {
 		dev_err(dev, "failed to enable phy\n");
-		return ret;
+		dra7xx_pcie_disable_phy(dra7xx);
+		goto err_link;
 	}
 
 	platform_set_drvdata(pdev, dra7xx);
@@ -910,7 +913,8 @@ static int dra7xx_pcie_resume_noirq(struct device *dev)
 	ret = dra7xx_pcie_enable_phy(dra7xx);
 	if (ret) {
 		dev_err(dev, "failed to enable phy\n");
-		return ret;
+		dra7xx_pcie_disable_phy(dra7xx);
+		goto err_link;
 	}
 
 	return 0;
Signature · 1 line
2.39.5 (Apple Git-154)

Please ignore this patch. I will resend a proper version after learning the kernel submission process.

Apologies for the noise.

Best regards,
WenTao Liang

#3 lore raw
In reply to WenTao Liang
kernel test robot noticed the following build errors:

Hi WenTao,

kernel test robot noticed the following build errors:

[auto build test ERROR on pci/next]
[also build test ERROR on pci/for-linus linus/master v7.2-rc7 next-20260813] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/WenTao-Liang/fix-PCI-dra7xx-dra7xx_pcie_probe-fix-missing-device_link_del-on-phy-error-paths/20260815-023710
base:   https://git.kernel.org/pub/scm/linux/kernel/git/pci/pci.git next
patch link:    https://lore.kernel.org/r/20260626154809.53770-1-vulab%40iscas.ac.cn
patch subject: [PATCH] fix: PCI: dra7xx: dra7xx_pcie_probe: fix missing device_link_del on phy   error paths
config: powerpc-allmodconfig (https://download.01.org/0day-ci/archive/20260815/[email protected]/config)
compiler: powerpc64-linux-gcc (GCC) 16.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260815/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

drivers/pci/controller/dwc/pci-dra7xx.c: In function 'dra7xx_pcie_resume_noirq':

>> drivers/pci/controller/dwc/pci-dra7xx.c:918:17: error: label 'err_link' used but not defined
     918 |                 goto err_link;
         |                 ^~~~

vim +/err_link +918 drivers/pci/controller/dwc/pci-dra7xx.c

908
909 static int dra7xx_pcie_resume_noirq(struct device *dev)
910 {
911 struct dra7xx_pcie *dra7xx = dev_get_drvdata(dev);
912 int ret;
913
914 ret = dra7xx_pcie_enable_phy(dra7xx);
915 if (ret) {
916 dev_err(dev, "failed to enable phy\n");
917 dra7xx_pcie_disable_phy(dra7xx);

 > 918			goto err_link;

919 }
920
921 return 0;
922 }
923

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

#4 lore raw
In reply to WenTao Liang
kernel test robot noticed the following build errors:

Hi WenTao,

kernel test robot noticed the following build errors:

[auto build test ERROR on pci/next]
[also build test ERROR on pci/for-linus linus/master v7.2-rc7 next-20260814] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/WenTao-Liang/fix-PCI-dra7xx-dra7xx_pcie_probe-fix-missing-device_link_del-on-phy-error-paths/20260815-023710
base:   https://git.kernel.org/pub/scm/linux/kernel/git/pci/pci.git next
patch link:    https://lore.kernel.org/r/20260626154809.53770-1-vulab%40iscas.ac.cn
patch subject: [PATCH] fix: PCI: dra7xx: dra7xx_pcie_probe: fix missing device_link_del on phy   error paths
config: arm64-randconfig-001-20260816 (https://download.01.org/0day-ci/archive/20260816/[email protected]/config)
compiler: clang version 24.0.0git (https://github.com/llvm/llvm-project 844a18e753e822736c9805ab779144b647a2c186)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260816/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> drivers/pci/controller/dwc/pci-dra7xx.c:918:8: error: use of undeclared label 'err_link'
     918 |                 goto err_link;
         |                      ^

1 error generated.

vim +/err_link +918 drivers/pci/controller/dwc/pci-dra7xx.c

908
909 static int dra7xx_pcie_resume_noirq(struct device *dev)
910 {
911 struct dra7xx_pcie *dra7xx = dev_get_drvdata(dev);
912 int ret;
913
914 ret = dra7xx_pcie_enable_phy(dra7xx);
915 if (ret) {
916 dev_err(dev, "failed to enable phy\n");
917 dra7xx_pcie_disable_phy(dra7xx);

 > 918			goto err_link;

919 }
920
921 return 0;
922 }
923

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki