Skip to contentSkip to conversation

PCI: xilinx-nwl: Use devm_clk_get_enabled() in nwl_pcie_probe()

PATCH In review Markus Elfring 3 participants 3 messages Dec 4

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

PATCH v2 1/1 PCI: xilinx-nwl: Use devm_clk_get_enabled() in nwl_pcie_probe()

From: Markus Elfring <[email protected]>
Date: Fri, 4 Dec 2026 15:00:34 +0100

Replace the combination of devm_clk_get() and clk_prepare_enable() by a devm_clk_get_enabled() call.
Delete a clk_disable_unprepare() call on an error handling path and in the implementation of the function “nwl_pcie_remove”. Drop the label “err_clk”.

This issue was detected by using the Coccinelle software.

---

V2:
Frank Li and Manivannan Sadhasivam requested a different change description.

 drivers/pci/controller/pcie-xilinx-nwl.c | 13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)
drivers/pci/controller/pcie-xilinx-nwl.c +2 -11
index 0dee19fa24ca..fd134317e9c4 100644
@@ -844,20 +844,14 @@ static int nwl_pcie_probe(struct platform_device *pdev)
 		return err;
 	}
 
-	pcie->clk = devm_clk_get(dev, NULL);
+	pcie->clk = devm_clk_get_enabled(dev, NULL);
 	if (IS_ERR(pcie->clk))
 		return PTR_ERR(pcie->clk);
 
-	err = clk_prepare_enable(pcie->clk);
-	if (err) {
-		dev_err(dev, "can't enable PCIe ref clock\n");
-		return err;
-	}
-
 	err = nwl_pcie_phy_enable(pcie);
 	if (err) {
 		dev_err(dev, "could not enable PHYs\n");
-		goto err_clk;
+		return err;
 	}
 
 	err = nwl_pcie_bridge_init(pcie);
@@ -889,8 +883,6 @@ static int nwl_pcie_probe(struct platform_device *pdev)
 
 err_phy:
 	nwl_pcie_phy_disable(pcie);
-err_clk:
-	clk_disable_unprepare(pcie->clk);
 	return err;
 }
 
@@ -899,7 +891,6 @@ static void nwl_pcie_remove(struct platform_device *pdev)
 	struct nwl_pcie *pcie = platform_get_drvdata(pdev);
 
 	nwl_pcie_phy_disable(pcie);
-	clk_disable_unprepare(pcie->clk);
 }
 
 static struct platform_driver nwl_pcie_driver = {
Signature · 1 line
2.56.1
#1 lore raw
Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [Low] PCI: xilinx-nwl: commit message lacks rationale and prose formatting - [Low] PCI: xilinx-nwl: unused…

Thank you for your contribution! Sashiko AI review found 3 potential issues to consider:
- [Low] PCI: xilinx-nwl: commit message lacks rationale and prose formatting
- [Low] PCI: xilinx-nwl: unused clk field retained in struct nwl_pcie
- [Low] PCI: xilinx-nwl: dropped error log on clock failure in nwl_pcie_probe()
--

commit ea3dc9c7727e38909d19bde17e7137893bae16bc
Author: Markus Elfring <[email protected]>

Quoted 11 lines

PCI: xilinx-nwl: Use devm_clk_get_enabled() in nwl_pcie_probe()

Replace the combination of devm_clk_get() and clk_prepare_enable() by a devm_clk_get_enabled() call.
Delete a clk_disable_unprepare() call on an error handling path and in the implementation of the function “nwl_pcie_remove”. Drop the label “err_clk”.

This issue was detected by using the Coccinelle software.

[Severity: Low]
As reported by Manivannan Sadhasivam on v1 [1], the commit message should be contiguous prose explaining what the patch does and why it is needed, rather than listing edits line by line and calling this cleanup an issue detected by Coccinelle.

It also omits mentioning that the dev_err() message on clock enable failure is removed.

drivers/pci/controller/pcie-xilinx-nwl.c static int nwl_pcie_probe(struct platform_device *pdev) · line 849

Quoted 12 lines
drivers/pci/controller/pcie-xilinx-nwl.c +1 -1
index 0dee19fa24ca3..fd134317e9c48 100644
@@ -844,20 +844,14 @@ static int nwl_pcie_probe(struct platform_device *pdev)
 		return err;
 	}
 
-	pcie->clk = devm_clk_get(dev, NULL);
+	pcie->clk = devm_clk_get_enabled(dev, NULL);
 	if (IS_ERR(pcie->clk))
 		return PTR_ERR(pcie->clk);

[Severity: Low]
Is the clk field in struct nwl_pcie still needed? With both clk_disable_unprepare() calls removed from nwl_pcie_probe() and nwl_pcie_remove(), pcie->clk is never read outside this check, so a local struct clk *clk variable can be used instead and the struct member dropped.

drivers/pci/controller/pcie-xilinx-nwl.c static int nwl_pcie_probe(struct platform_device *pdev) · line 855

Quoted 5 lines
drivers/pci/controller/pcie-xilinx-nwl.c +0 -5
-	err = clk_prepare_enable(pcie->clk);
-	if (err) {
-		dev_err(dev, "can't enable PCIe ref clock\n");
-		return err;
-	}

[Severity: Low]
Should this preserve an error log when getting or enabling the clock fails? devm_clk_get_enabled() does not print an error on failure, so returning PTR_ERR(pcie->clk) silently drops the diagnostic message. Using dev_err_probe() would keep the failure log while handling -EPROBE_DEFER.

[1] https://lore.kernel.org/r/179562889095.5580.5805178037943195830.b4-reply@b4

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Reviewed-by on v2 1/1
#2 lore raw
In reply to Markus Elfring
Quoted 5 lines · Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 4 Dec 2026 15:00:34 +0100

Replace the combination of devm_clk_get() and clk_prepare_enable() by a devm_clk_get_enabled() call.

Nit: Need a empty line between paragraph.

Quoted 8 lines

Delete a clk_disable_unprepare() call on an error handling path and in the implementation of the function “nwl_pcie_remove”. Drop the label “err_clk”.

This issue was detected by using the Coccinelle software.

---

Quoted 55 lines

V2:
Frank Li and Manivannan Sadhasivam requested a different change description.

 drivers/pci/controller/pcie-xilinx-nwl.c | 13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)
drivers/pci/controller/pcie-xilinx-nwl.c +2 -12
index 0dee19fa24ca..fd134317e9c4 100644
@@ -844,20 +844,14 @@ static int nwl_pcie_probe(struct platform_device *pdev)
 		return err;
 	}
 
-	pcie->clk = devm_clk_get(dev, NULL);
+	pcie->clk = devm_clk_get_enabled(dev, NULL);
 	if (IS_ERR(pcie->clk))
 		return PTR_ERR(pcie->clk);
 
-	err = clk_prepare_enable(pcie->clk);
-	if (err) {
-		dev_err(dev, "can't enable PCIe ref clock\n");
-		return err;
-	}
-
 	err = nwl_pcie_phy_enable(pcie);
 	if (err) {
 		dev_err(dev, "could not enable PHYs\n");
-		goto err_clk;
+		return err;
 	}
 
 	err = nwl_pcie_bridge_init(pcie);
@@ -889,8 +883,6 @@ static int nwl_pcie_probe(struct platform_device *pdev)
 
 err_phy:
 	nwl_pcie_phy_disable(pcie);
-err_clk:
-	clk_disable_unprepare(pcie->clk);
 	return err;
 }
 
@@ -899,7 +891,6 @@ static void nwl_pcie_remove(struct platform_device *pdev)
 	struct nwl_pcie *pcie = platform_get_drvdata(pdev);
 
 	nwl_pcie_phy_disable(pcie);
-	clk_disable_unprepare(pcie->clk);
 }
 
 static struct platform_driver nwl_pcie_driver = {
--

2.56.1