Skip to contentSkip to conversation

phy: tegra: Use PTR_ERR_OR_ZERO() to simplify code

PATCH In review Aishwarya Ramakrishnan 3 participants 3 messages May 5, 2020 – May 6, 2020

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

PATCH 1/1 phy: tegra: Use PTR_ERR_OR_ZERO() to simplify code

PTR_ERR_OR_ZERO contains if(IS_ERR(...)) + PTR_ERR.

Generated by: scripts/coccinelle/api/ptr_ret.cocci

---
 drivers/phy/tegra/phy-tegra194-p2u.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/phy/tegra/phy-tegra194-p2u.c +1 -4
index 7042bed9feaa..42394d27f4cb 100644
@@ -92,10 +92,7 @@ static int tegra_p2u_probe(struct platform_device *pdev)
 	phy_set_drvdata(generic_phy, phy);
 
 	phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
-	if (IS_ERR(phy_provider))
-		return PTR_ERR(phy_provider);
-
-	return 0;
+	return PTR_ERR_OR_ZERO(phy_provider);
 }
 
 static const struct of_device_id tegra_p2u_id_table[] = {
Signature · 1 line
2.17.1
Reviewed-by on v1 1/1
#1 lore raw

Thanks for pushing this change.
I'm fine with this change as it is attempting to change only the last occurrence of the (IS_ERR(...)) + PTR_ERR combination.
But, this code was initially written with PTR_ERR_OR_ZERO() itself but later changed to use (IS_ERR(...)) + PTR_ERR based on the review comment from Dmitry Osipenko ( https://lkml.org/lkml/2019/6/20/1457 )

Adding Dmitry as well to review the change.

I'm fine with this change.

Quoted 31 lines · Aishwarya Ramakrishnan

External email: Use caution opening links or attachments

PTR_ERR_OR_ZERO contains if(IS_ERR(...)) + PTR_ERR.

Generated by: scripts/coccinelle/api/ptr_ret.cocci

---
  drivers/phy/tegra/phy-tegra194-p2u.c | 5 +----
  1 file changed, 1 insertion(+), 4 deletions(-)
drivers/phy/tegra/phy-tegra194-p2u.c +1 -5
index 7042bed9feaa..42394d27f4cb 100644
@@ -92,10 +92,7 @@ static int tegra_p2u_probe(struct platform_device *pdev)
         phy_set_drvdata(generic_phy, phy);
 
         phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
-       if (IS_ERR(phy_provider))
-               return PTR_ERR(phy_provider);
-
-       return 0;
+       return PTR_ERR_OR_ZERO(phy_provider);
  }
 
  static const struct of_device_id tegra_p2u_id_table[] = {
--

2.17.1

#2 lore raw

06.05.2020 14:47, Vidya Sagar пишет:

Quoted 34 lines

Thanks for pushing this change.
I'm fine with this change as it is attempting to change only the last occurrence of the (IS_ERR(...)) + PTR_ERR combination.
But, this code was initially written with PTR_ERR_OR_ZERO() itself but later changed to use (IS_ERR(...)) + PTR_ERR based on the review comment from Dmitry Osipenko ( https://lkml.org/lkml/2019/6/20/1457 )

Adding Dmitry as well to review the change.

I'm fine with this change.

Quoted 21 lines · Aishwarya Ramakrishnan

External email: Use caution opening links or attachments

PTR_ERR_OR_ZERO contains if(IS_ERR(...)) + PTR_ERR.

Generated by: scripts/coccinelle/api/ptr_ret.cocci

---
  drivers/phy/tegra/phy-tegra194-p2u.c | 5 +----

  1 file changed, 1 insertion(+), 4 deletions(-)
drivers/phy/tegra/phy-tegra194-p2u.c +0 -0
index 7042bed9feaa..42394d27f4cb 100644
@@ -92,10 +92,7 @@ static int tegra_p2u_probe(struct platform_device
 *pdev)
          phy_set_drvdata(generic_phy, phy);
 
Quoted 8 lines

drivers/phy/tegra/phy-tegra194-p2u.c static int tegra_p2u_probe(struct platform_device *pdev) · line 96

Quoted 8 lines
drivers/phy/tegra/phy-tegra194-p2u.c +1 -4
          phy_provider = devm_of_phy_provider_register(dev,
 of_phy_simple_xlate);
-       if (IS_ERR(phy_provider))
-               return PTR_ERR(phy_provider);
-
-       return 0;
+       return PTR_ERR_OR_ZERO(phy_provider);
   }

Quite some people think that such a change doesn't bring any benefits, it doesn't help readability of the code, it even makes harder to read the code for a human being.

IIRC, there were some requests in the past to remove that cocci rule to stop such auto-generated patches to re-occur over and over again.

The PTR_ERR_OR_ZERO is good to use in a cases where it's not returned directly, like this:

phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate); err = PTR_ERR_OR_ZERO(phy_provider);
if (err)

	return err;

return 0;