ata: sata_mv: use devm clock helpers
PATCH 1/1 ata: sata_mv: use devm clock helpers
Replace clk_get/clk_prepare_enable/clk_put with devm_clk_get_optional_enabled for both the main clock and per-port clocks. This eliminates the need for manual clock cleanup in probe error and remove paths.
The err label is retained for phy_power_off cleanup, since devm_phy_optional_get does not manage phy power state.
--- drivers/ata/sata_mv.c | 45 +++++++++++-------------------------------- 1 file changed, 11 insertions(+), 34 deletions(-)
drivers/ata/sata_mv.c +11 -34
@@ -4090,21 +4090,16 @@ static int mv_platform_probe(struct platform_device *pdev) hpriv->base -=SATAHC0_REG_BASE ; - hpriv->clk =clk_get (&pdev->dev,NULL ); -if (IS_ERR (hpriv->clk)) { -dev_notice (&pdev->dev,"cannot get optional clkdev\n" ); - }else { - rc =clk_prepare_enable (hpriv->clk); -if (rc) - goto err; - } + hpriv->clk =devm_clk_get_optional_enabled (&pdev->dev,NULL ); +if (IS_ERR (hpriv->clk)) +return PTR_ERR (hpriv->clk);for (port =0 ; port < n_ports; port++) {char port_number[16 ];sprintf (port_number,"%d" , port); - hpriv->port_clks[port] =clk_get (&pdev->dev, port_number); -if (!IS_ERR (hpriv->port_clks[port])) -clk_prepare_enable (hpriv->port_clks[port]); + hpriv->port_clks[port] =devm_clk_get_optional_enabled (&pdev->dev, port_number); +if (IS_ERR (hpriv->port_clks[port])) +return PTR_ERR (hpriv->port_clks[port]);sprintf (port_number,"port%d" , port); hpriv->port_phys[port] = devm_phy_optional_get(&pdev->dev,
@@ -4117,9 +4112,9 @@ static int mv_platform_probe(struct platform_device *pdev)/* Cleanup only the initialized ports */ hpriv->n_ports = port; - goto err; - }else -phy_power_on (hpriv->port_phys[port]); +return rc; + } +phy_power_on (hpriv->port_phys[port]); }/* All the ports have been initialized */
@@ -4158,17 +4153,8 @@ static int mv_platform_probe(struct platform_device *pdev)return 0 ; err: -if (!IS_ERR (hpriv->clk)) { -clk_disable_unprepare (hpriv->clk); -clk_put (hpriv->clk); - } -for (port =0 ; port < hpriv->n_ports; port++) { -if (!IS_ERR (hpriv->port_clks[port])) { -clk_disable_unprepare (hpriv->port_clks[port]); -clk_put (hpriv->port_clks[port]); - } +for (port =0 ; port < hpriv->n_ports; port++)phy_power_off (hpriv->port_phys[port]); - }return rc; }
@@ -4188,17 +4174,8 @@ static void mv_platform_remove(struct platform_device *pdev)int port;ata_host_detach (host); -if (!IS_ERR (hpriv->clk)) { -clk_disable_unprepare (hpriv->clk); -clk_put (hpriv->clk); - } -for (port =0 ; port < host->n_ports; port++) { -if (!IS_ERR (hpriv->port_clks[port])) { -clk_disable_unprepare (hpriv->port_clks[port]); -clk_put (hpriv->port_clks[port]); - } +for (port =0 ; port < host->n_ports; port++)phy_power_off (hpriv->port_phys[port]); - } }#ifdef CONFIG_PM_SLEEP
Signature · 1 line
2.54.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Direct returns inside the per-port initialization loop bypass the `err` cleanup block, leaking the…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Direct returns inside the per-port initialization loop bypass the err cleanup block, leaking the power state of previously initialized PHYs. --
commit 6348b987b12e84df8076e5646462dde25b2d8234
Author: Rosen Penev <[email protected]>
ata: sata_mv: use devm clock helpers
This commit replaces manual clock management with devm_clk_get_optional_enabled for the main and per-port clocks. The commit message states the err label is retained for phy_power_off cleanup.
Quoted 3 lines
drivers/ata/sata_mv.c +0
-0
[ ... ]
Quoted 1 line
drivers/ata/sata_mv.c +0
-0@@ -4091,21 +4091,16 @@ static int mv_platform_probe(struct platform_device *pdev)
[ ... ]
drivers/ata/sata_mv.c static int mv_platform_probe(struct platform_device *pdev) · line 4102
Quoted 9 lines
drivers/ata/sata_mv.c +3
-3for (port =0 ; port < n_ports; port++) {char port_number[16 ];sprintf (port_number,"%d" , port); - hpriv->port_clks[port] =clk_get (&pdev->dev, port_number); -if (!IS_ERR (hpriv->port_clks[port])) -clk_prepare_enable (hpriv->port_clks[port]); + hpriv->port_clks[port] =devm_clk_get_optional_enabled (&pdev->dev, port_number); +if (IS_ERR (hpriv->port_clks[port])) +return PTR_ERR (hpriv->port_clks[port]);
[Severity: High]
Does this direct return skip the cleanup for PHYs powered on during previous loop iterations?
If mv_platform_probe() fails to get the port clock on a subsequent port (port > 0), returning directly bypasses the err label where phy_power_off() is called. This could leave the earlier PHYs powered on.
drivers/ata/sata_mv.c static int mv_platform_probe(struct platform_device *pdev) · line 4117
Quoted 11 lines
drivers/ata/sata_mv.c +2
-3sprintf (port_number,"port%d" , port); hpriv->port_phys[port] = devm_phy_optional_get(&pdev->dev,@@ -4118,9 +4113,9 @@ static int mv_platform_probe(struct platform_device *pdev)/* Cleanup only the initialized ports */ hpriv->n_ports = port; - goto err; - }else -phy_power_on (hpriv->port_phys[port]); +return rc; + }
[Severity: High]
Is it intentional to replace the goto err with a direct return here?
The original code used goto err to ensure phy_power_off() would be called for previously initialized ports when devm_phy_optional_get() failed. By returning directly, could this leak the power state if probe is deferred or fails for a later port?
Quoted 2 lines
drivers/ata/sata_mv.c +1
-0+phy_power_on (hpriv->port_phys[port]); }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1