Skip to contentSkip to conversation

phy: miphy28lp: Avoid calling of_get_child_count() multiple times

PATCH In review Axel Lin 2 participants 4 messages Feb 24, 2015 Generic PHY framework

lore
Share & tools
lore

Axel Lin

author
#0 lore raw

PATCH 1/2 phy: miphy28lp: Avoid calling of_get_child_count() multiple times

Currently, of_get_child_count() is called in each iteration of the for loop in miphy28lp_xlate(). This patch stores the return value of of_get_child_count() in miphy_dev->nphys and call of_get_child_count() once in miphy28lp_probe().

---
 drivers/phy/phy-miphy28lp.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/phy/phy-miphy28lp.c +6 -5
index 9b2848e..d444932 100644
@@ -228,6 +228,7 @@ struct miphy28lp_dev {
 	struct regmap *regmap;
 	struct mutex miphy_mutex;
 	struct miphy28lp_phy **phys;
+	int nphys;
 };
 
 struct miphy_initval {
@@ -1116,7 +1117,7 @@ static struct phy *miphy28lp_xlate(struct device *dev,
 		return ERR_PTR(-EINVAL);
 	}
 
-	for (index = 0; index < of_get_child_count(dev->of_node); index++)
+	for (index = 0; index < miphy_dev->nphys; index++)
 		if (phynode == miphy_dev->phys[index]->phy->dev.of_node) {
 			miphy_phy = miphy_dev->phys[index];
 			break;
@@ -1200,15 +1201,15 @@ static int miphy28lp_probe(struct platform_device *pdev)
 	struct miphy28lp_dev *miphy_dev;
 	struct phy_provider *provider;
 	struct phy *phy;
-	int chancount, port = 0;
-	int ret;
+	int ret, port = 0;
 
 	miphy_dev = devm_kzalloc(&pdev->dev, sizeof(*miphy_dev), GFP_KERNEL);
 	if (!miphy_dev)
 		return -ENOMEM;
 
-	chancount = of_get_child_count(np);
-	miphy_dev->phys = devm_kzalloc(&pdev->dev, sizeof(phy) * chancount,
+	miphy_dev->nphys = of_get_child_count(np);
+	miphy_dev->phys = devm_kzalloc(&pdev->dev,
+				       sizeof(phy) * miphy_dev->nphys,
 				       GFP_KERNEL);
 	if (!miphy_dev->phys)
 		return -ENOMEM;
Signature · 1 line
1.9.1
author
#1 lore raw

PATCH 2/2 phy: miphy365x: Avoid calling of_get_child_count() multiple times

Currently, of_get_child_count() is called in each iteration of the for loop in miphy365x_xlate(). This patch stores the return value of of_get_child_count() in miphy_dev->nphys and call of_get_child_count() once in miphy365x_probe().

---
 drivers/phy/phy-miphy365x.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/phy/phy-miphy365x.c +6 -5
index 6c80154..61177a6 100644
@@ -150,6 +150,7 @@ struct miphy365x_dev {
 	struct regmap *regmap;
 	struct mutex miphy_mutex;
 	struct miphy365x_phy **phys;
+	int nphys;
 };
 
 /*
@@ -485,7 +486,7 @@ static struct phy *miphy365x_xlate(struct device *dev,
 		return ERR_PTR(-EINVAL);
 	}
 
-	for (index = 0; index < of_get_child_count(dev->of_node); index++)
+	for (index = 0; index < miphy_dev->nphys; index++)
 		if (phynode == miphy_dev->phys[index]->phy->dev.of_node) {
 			miphy_phy = miphy_dev->phys[index];
 			break;
@@ -541,15 +542,15 @@ static int miphy365x_probe(struct platform_device *pdev)
 	struct miphy365x_dev *miphy_dev;
 	struct phy_provider *provider;
 	struct phy *phy;
-	int chancount, port = 0;
-	int ret;
+	int ret, port = 0;
 
 	miphy_dev = devm_kzalloc(&pdev->dev, sizeof(*miphy_dev), GFP_KERNEL);
 	if (!miphy_dev)
 		return -ENOMEM;
 
-	chancount = of_get_child_count(np);
-	miphy_dev->phys = devm_kzalloc(&pdev->dev, sizeof(phy) * chancount,
+	miphy_dev->nphys = of_get_child_count(np);
+	miphy_dev->phys = devm_kzalloc(&pdev->dev,
+				       sizeof(phy) * miphy_dev->nphys,
 				       GFP_KERNEL);
 	if (!miphy_dev->phys)
 		return -ENOMEM;
Signature · 1 line
1.9.1
#2 lore raw
In reply to Axel Lin

Hi,

Quoted 14 lines · Axel Lin

Currently, of_get_child_count() is called in each iteration of the for loop in miphy28lp_xlate(). This patch stores the return value of of_get_child_count() in miphy_dev->nphys and call of_get_child_count() once in miphy28lp_probe().

---
  drivers/phy/phy-miphy28lp.c | 11 ++++++-----
  1 file changed, 6 insertions(+), 5 deletions(-)
drivers/phy/phy-miphy28lp.c +0 -0
index 9b2848e..d444932 100644

drivers/phy/phy-miphy28lp.c struct miphy28lp_dev { · line 231

Quoted 4 lines
drivers/phy/phy-miphy28lp.c +1 -0
@@ -228,6 +228,7 @@ struct miphy28lp_dev {
  	struct regmap *regmap;
  	struct mutex miphy_mutex;
  	struct miphy28lp_phy **phys;
+	int nphys;

it can just be a local member to miphy28lp_xlate() since it's not used anywhere else.

Cheers
Kishon

author
#3 lore raw

2015-02-24 21:47 GMT+08:00 Kishon Vijay Abraham I <[email protected]>:

Quoted 16 lines

Hi,

Quoted 13 lines · Axel Lin

Currently, of_get_child_count() is called in each iteration of the for loop in
miphy28lp_xlate(). This patch stores the return value of of_get_child_count()
in miphy_dev->nphys and call of_get_child_count() once in miphy28lp_probe().

---
  drivers/phy/phy-miphy28lp.c | 11 ++++++-----
  1 file changed, 6 insertions(+), 5 deletions(-)
Quoted 13 lines

drivers/phy/phy-miphy28lp.c struct miphy28lp_dev { · line 231

Quoted 9 lines
drivers/phy/phy-miphy28lp.c +1 -0
index 9b2848e..d444932 100644
@@ -228,6 +228,7 @@ struct miphy28lp_dev {
        struct regmap *regmap;
        struct mutex miphy_mutex;
        struct miphy28lp_phy **phys;
+       int nphys;

it can just be a local member to miphy28lp_xlate() since it's not used anywhere else.

It's used in both miphy28lp_probe() and miphy28lp_xlate(). miphy_dev->phys replaces the chancount local variable as well.

Regards,
Axel