2022-03-09 19:37:19

by Krzysztof Kozlowski

[permalink] [raw]
Subject: [PATCH] phy: samsung: exynos5250-sata: fix missing device put in probe error paths

The actions of of_find_i2c_device_by_node() in probe function should be
reversed in error paths by putting the reference to obtained device.

Fixes: bcff4cba41bc ("PHY: Exynos: Add Exynos5250 SATA PHY driver")
Signed-off-by: Krzysztof Kozlowski <[email protected]>

---

Rebased on top of (although it is independent, no conflicts):
https://lore.kernel.org/linux-samsung-soc/[email protected]/T/#u
---
drivers/phy/samsung/phy-exynos5250-sata.c | 20 ++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/drivers/phy/samsung/phy-exynos5250-sata.c b/drivers/phy/samsung/phy-exynos5250-sata.c
index 6c305a3fe187..595adba5fb8f 100644
--- a/drivers/phy/samsung/phy-exynos5250-sata.c
+++ b/drivers/phy/samsung/phy-exynos5250-sata.c
@@ -196,20 +196,21 @@ static int exynos_sata_phy_probe(struct platform_device *pdev)
sata_phy->phyclk = devm_clk_get(dev, "sata_phyctrl");
if (IS_ERR(sata_phy->phyclk)) {
dev_err(dev, "failed to get clk for PHY\n");
- return PTR_ERR(sata_phy->phyclk);
+ ret = PTR_ERR(sata_phy->phyclk);
+ goto put_dev;
}

ret = clk_prepare_enable(sata_phy->phyclk);
if (ret < 0) {
dev_err(dev, "failed to enable source clk\n");
- return ret;
+ goto put_dev;
}

sata_phy->phy = devm_phy_create(dev, NULL, &exynos_sata_phy_ops);
if (IS_ERR(sata_phy->phy)) {
- clk_disable_unprepare(sata_phy->phyclk);
dev_err(dev, "failed to create PHY\n");
- return PTR_ERR(sata_phy->phy);
+ ret = PTR_ERR(sata_phy->phy);
+ goto clk_disable;
}

phy_set_drvdata(sata_phy->phy, sata_phy);
@@ -217,11 +218,18 @@ static int exynos_sata_phy_probe(struct platform_device *pdev)
phy_provider = devm_of_phy_provider_register(dev,
of_phy_simple_xlate);
if (IS_ERR(phy_provider)) {
- clk_disable_unprepare(sata_phy->phyclk);
- return PTR_ERR(phy_provider);
+ ret = PTR_ERR(phy_provider);
+ goto clk_disable;
}

return 0;
+
+clk_disable:
+ clk_disable_unprepare(sata_phy->phyclk);
+put_dev:
+ put_device(&sata_phy->client->dev);
+
+ return ret;
}

static const struct of_device_id exynos_sata_phy_of_match[] = {
--
2.32.0


2022-03-11 02:54:51

by Alim Akhtar

[permalink] [raw]
Subject: RE: [PATCH] phy: samsung: exynos5250-sata: fix missing device put in probe error paths

Hi Krzysztof

>-----Original Message-----
>From: Krzysztof Kozlowski [mailto:[email protected]]
>Sent: Wednesday, March 9, 2022 10:30 PM
>To: Kishon Vijay Abraham I <[email protected]>; Vinod Koul
><[email protected]>; Krzysztof Kozlowski
><[email protected]>; Alim Akhtar
><[email protected]>; Miaoqian Lin <[email protected]>; linux-
>[email protected]; [email protected]; linux-
>[email protected]; [email protected]
>Subject: [PATCH] phy: samsung: exynos5250-sata: fix missing device put in
>probe error paths
>
>The actions of of_find_i2c_device_by_node() in probe function should be
>reversed in error paths by putting the reference to obtained device.
>
>Fixes: bcff4cba41bc ("PHY: Exynos: Add Exynos5250 SATA PHY driver")
>Signed-off-by: Krzysztof Kozlowski <[email protected]>
>
Thanks for fixing this.

Reviewed-by: Alim Akhtar <[email protected]>

>---
>
>Rebased on top of (although it is independent, no conflicts):
>https://lore.kernel.org/linux-samsung-soc/20220309124856.32632-1-
>[email protected]/T/#u
>---
> drivers/phy/samsung/phy-exynos5250-sata.c | 20 ++++++++++++++------
> 1 file changed, 14 insertions(+), 6 deletions(-)
>
>diff --git a/drivers/phy/samsung/phy-exynos5250-sata.c
>b/drivers/phy/samsung/phy-exynos5250-sata.c
>index 6c305a3fe187..595adba5fb8f 100644
>--- a/drivers/phy/samsung/phy-exynos5250-sata.c
>+++ b/drivers/phy/samsung/phy-exynos5250-sata.c
>@@ -196,20 +196,21 @@ static int exynos_sata_phy_probe(struct
>platform_device *pdev)
> sata_phy->phyclk = devm_clk_get(dev, "sata_phyctrl");
> if (IS_ERR(sata_phy->phyclk)) {
> dev_err(dev, "failed to get clk for PHY\n");
>- return PTR_ERR(sata_phy->phyclk);
>+ ret = PTR_ERR(sata_phy->phyclk);
>+ goto put_dev;
> }
>
> ret = clk_prepare_enable(sata_phy->phyclk);
> if (ret < 0) {
> dev_err(dev, "failed to enable source clk\n");
>- return ret;
>+ goto put_dev;
> }
>
> sata_phy->phy = devm_phy_create(dev, NULL,
>&exynos_sata_phy_ops);
> if (IS_ERR(sata_phy->phy)) {
>- clk_disable_unprepare(sata_phy->phyclk);
> dev_err(dev, "failed to create PHY\n");
>- return PTR_ERR(sata_phy->phy);
>+ ret = PTR_ERR(sata_phy->phy);
>+ goto clk_disable;
> }
>
> phy_set_drvdata(sata_phy->phy, sata_phy); @@ -217,11 +218,18
>@@ static int exynos_sata_phy_probe(struct platform_device *pdev)
> phy_provider = devm_of_phy_provider_register(dev,
> of_phy_simple_xlate);
> if (IS_ERR(phy_provider)) {
>- clk_disable_unprepare(sata_phy->phyclk);
>- return PTR_ERR(phy_provider);
>+ ret = PTR_ERR(phy_provider);
>+ goto clk_disable;
> }
>
> return 0;
>+
>+clk_disable:
>+ clk_disable_unprepare(sata_phy->phyclk);
>+put_dev:
>+ put_device(&sata_phy->client->dev);
>+
>+ return ret;
> }
>
> static const struct of_device_id exynos_sata_phy_of_match[] = {
>--
>2.32.0


2022-04-13 11:31:38

by Krzysztof Kozlowski

[permalink] [raw]
Subject: Re: [PATCH] phy: samsung: exynos5250-sata: fix missing device put in probe error paths

On 13/04/2022 11:51, Vinod Koul wrote:
> On 09-03-22, 18:00, Krzysztof Kozlowski wrote:
>> The actions of of_find_i2c_device_by_node() in probe function should be
>> reversed in error paths by putting the reference to obtained device.
>
> This fails to apply on phy-fixes, pls rebase

You applied resent version, so you can ignore this one.

https://git.kernel.org/pub/scm/linux/kernel/git/phy/linux-phy.git/commit/?h=fixes&id=5c8402c4db45dd55c2c93c8d730f5dfa7c78a702


Best regards,
Krzysztof

2022-04-13 14:42:29

by Vinod Koul

[permalink] [raw]
Subject: Re: [PATCH] phy: samsung: exynos5250-sata: fix missing device put in probe error paths

On 09-03-22, 18:00, Krzysztof Kozlowski wrote:
> The actions of of_find_i2c_device_by_node() in probe function should be
> reversed in error paths by putting the reference to obtained device.

This fails to apply on phy-fixes, pls rebase

>
> Fixes: bcff4cba41bc ("PHY: Exynos: Add Exynos5250 SATA PHY driver")
> Signed-off-by: Krzysztof Kozlowski <[email protected]>
>
> ---
>
> Rebased on top of (although it is independent, no conflicts):
> https://lore.kernel.org/linux-samsung-soc/[email protected]/T/#u
> ---
> drivers/phy/samsung/phy-exynos5250-sata.c | 20 ++++++++++++++------
> 1 file changed, 14 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/phy/samsung/phy-exynos5250-sata.c b/drivers/phy/samsung/phy-exynos5250-sata.c
> index 6c305a3fe187..595adba5fb8f 100644
> --- a/drivers/phy/samsung/phy-exynos5250-sata.c
> +++ b/drivers/phy/samsung/phy-exynos5250-sata.c
> @@ -196,20 +196,21 @@ static int exynos_sata_phy_probe(struct platform_device *pdev)
> sata_phy->phyclk = devm_clk_get(dev, "sata_phyctrl");
> if (IS_ERR(sata_phy->phyclk)) {
> dev_err(dev, "failed to get clk for PHY\n");
> - return PTR_ERR(sata_phy->phyclk);
> + ret = PTR_ERR(sata_phy->phyclk);
> + goto put_dev;
> }
>
> ret = clk_prepare_enable(sata_phy->phyclk);
> if (ret < 0) {
> dev_err(dev, "failed to enable source clk\n");
> - return ret;
> + goto put_dev;
> }
>
> sata_phy->phy = devm_phy_create(dev, NULL, &exynos_sata_phy_ops);
> if (IS_ERR(sata_phy->phy)) {
> - clk_disable_unprepare(sata_phy->phyclk);
> dev_err(dev, "failed to create PHY\n");
> - return PTR_ERR(sata_phy->phy);
> + ret = PTR_ERR(sata_phy->phy);
> + goto clk_disable;
> }
>
> phy_set_drvdata(sata_phy->phy, sata_phy);
> @@ -217,11 +218,18 @@ static int exynos_sata_phy_probe(struct platform_device *pdev)
> phy_provider = devm_of_phy_provider_register(dev,
> of_phy_simple_xlate);
> if (IS_ERR(phy_provider)) {
> - clk_disable_unprepare(sata_phy->phyclk);
> - return PTR_ERR(phy_provider);
> + ret = PTR_ERR(phy_provider);
> + goto clk_disable;
> }
>
> return 0;
> +
> +clk_disable:
> + clk_disable_unprepare(sata_phy->phyclk);
> +put_dev:
> + put_device(&sata_phy->client->dev);
> +
> + return ret;
> }
>
> static const struct of_device_id exynos_sata_phy_of_match[] = {
> --
> 2.32.0

--
~Vinod