Skip to contentSkip to conversation

usb: chipidea: removing of_find_property

PATCH Superseded Saurabh Sengar 3 participants 13 messages Nov 17, 2015 – Nov 18, 2015

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

PATCH 1/1 usb: chipidea: removing of_find_property

call to of_find_property() before of_property_read_u32() is unnecessary. of_property_read_u32() anyway calls to of_find_property() only.

---
 drivers/usb/chipidea/core.c | 67 ++++++++++++++++++++++-----------------------
 1 file changed, 32 insertions(+), 35 deletions(-)
drivers/usb/chipidea/core.c +32 -35
index 965d0e2..8a4c22c 100644
@@ -643,6 +643,7 @@ static int ci_get_platdata(struct device *dev,
 	struct extcon_dev *ext_vbus, *ext_id;
 	struct ci_hdrc_cable *cable;
 	int ret;
+	u32 pval;
 
 	if (!platdata->phy_mode)
 		platdata->phy_mode = of_usb_get_phy_mode(dev->of_node);
@@ -688,52 +689,48 @@ static int ci_get_platdata(struct device *dev,
 	if (usb_get_maximum_speed(dev) == USB_SPEED_FULL)
 		platdata->flags |= CI_HDRC_FORCE_FULLSPEED;
 
-	if (of_find_property(dev->of_node, "phy-clkgate-delay-us", NULL))
-		of_property_read_u32(dev->of_node, "phy-clkgate-delay-us",
-				     &platdata->phy_clkgate_delay_us);
+	if (!of_property_read_u32(dev->of_node, "phy-clkgate-delay-us",
+				     &pval))
+		platdata->phy_clkgate_delay_us = pval;
 
 	platdata->itc_setting = 1;
-	if (of_find_property(dev->of_node, "itc-setting", NULL)) {
-		ret = of_property_read_u32(dev->of_node, "itc-setting",
-			&platdata->itc_setting);
-		if (ret) {
-			dev_err(dev,
-				"failed to get itc-setting\n");
-			return ret;
-		}
+
+	ret = of_property_read_u32(dev->of_node, "itc-setting", &pval);
+	if (!ret)
+		platdata->itc_setting = pval;
+	else if (ret != -EINVAL) {
+		dev_err(dev, "failed to get itc-setting\n");
+		return ret;
 	}
 
-	if (of_find_property(dev->of_node, "ahb-burst-config", NULL)) {
-		ret = of_property_read_u32(dev->of_node, "ahb-burst-config",
-			&platdata->ahb_burst_config);
-		if (ret) {
-			dev_err(dev,
-				"failed to get ahb-burst-config\n");
-			return ret;
-		}
+	ret = of_property_read_u32(dev->of_node, "ahb-burst-config",
+				&pval);
+	if (!ret) {
+		platdata->ahb_burst_config = pval;
 		platdata->flags |= CI_HDRC_OVERRIDE_AHB_BURST;
+	} else if (ret != -EINVAL) {
+		dev_err(dev, "failed to get ahb-burst-config\n");
+		return ret;
 	}
 
-	if (of_find_property(dev->of_node, "tx-burst-size-dword", NULL)) {
-		ret = of_property_read_u32(dev->of_node, "tx-burst-size-dword",
-			&platdata->tx_burst_size);
-		if (ret) {
-			dev_err(dev,
-				"failed to get tx-burst-size-dword\n");
-			return ret;
-		}
+	ret = of_property_read_u32(dev->of_node, "tx-burst-size-dword",
+				&pval);
+	if (!ret) {
+		platdata->tx_burst_size = pval;
 		platdata->flags |= CI_HDRC_OVERRIDE_TX_BURST;
+	} else if (ret != -EINVAL) {
+		dev_err(dev, "failed to get tx-burst-size-dword\n");
+		return ret;
 	}
 
-	if (of_find_property(dev->of_node, "rx-burst-size-dword", NULL)) {
-		ret = of_property_read_u32(dev->of_node, "rx-burst-size-dword",
-			&platdata->rx_burst_size);
-		if (ret) {
-			dev_err(dev,
-				"failed to get rx-burst-size-dword\n");
-			return ret;
-		}
+	ret = of_property_read_u32(dev->of_node, "rx-burst-size-dword",
+				&pval);
+	if (!ret) {
+		platdata->rx_burst_size = pval;
 		platdata->flags |= CI_HDRC_OVERRIDE_RX_BURST;
+	} else if (ret != -EINVAL) {
+		dev_err(dev, "failed to get rx-burst-size-dword\n");
+		return ret;
 	}
 
 	ext_id = ERR_PTR(-ENODEV);
Signature · 1 line
1.9.1
#1 lore raw
Quoted 21 lines · Saurabh Sengar

call to of_find_property() before of_property_read_u32() is unnecessary. of_property_read_u32() anyway calls to of_find_property() only.

---
 drivers/usb/chipidea/core.c | 67 ++++++++++++++++++++++-----------------------
 1 file changed, 32 insertions(+), 35 deletions(-)
drivers/usb/chipidea/core.c +1 -0
index 965d0e2..8a4c22c 100644
@@ -643,6 +643,7 @@ static int ci_get_platdata(struct device *dev,
 	struct extcon_dev *ext_vbus, *ext_id;
 	struct ci_hdrc_cable *cable;
 	int ret;
+	u32 pval;
 
 	if (!platdata->phy_mode)
 		platdata->phy_mode = of_usb_get_phy_mode(dev->of_node);

drivers/usb/chipidea/core.c static int ci_get_platdata(struct device *dev, · line 694

Quoted 9 lines
drivers/usb/chipidea/core.c +3 -3
@@ -688,52 +689,48 @@ static int ci_get_platdata(struct device *dev,
 	if (usb_get_maximum_speed(dev) == USB_SPEED_FULL)
 		platdata->flags |= CI_HDRC_FORCE_FULLSPEED;
 
-	if (of_find_property(dev->of_node, "phy-clkgate-delay-us", NULL))
-		of_property_read_u32(dev->of_node, "phy-clkgate-delay-us",
-				     &platdata->phy_clkgate_delay_us);
+	if (!of_property_read_u32(dev->of_node, "phy-clkgate-delay-us",
+				     &pval))
+		platdata->phy_clkgate_delay_us = pval;

You don't need to use the pval temporary as of_property_read_u32 only modifies the destination on success.

Signature · 2 lines
Måns Rullgård
[email protected]
#2 lore raw

PATCH v2 1/1 usb: chipidea: removing of_find_property

call to of_find_property() before of_property_read_u32() is unnecessary. of_property_read_u32() anyway calls to of_find_property() only.

---
v2: removed pval variable

 drivers/usb/chipidea/core.c | 61 +++++++++++++++++++--------------------------
 1 file changed, 26 insertions(+), 35 deletions(-)
drivers/usb/chipidea/core.c +26 -35
index 965d0e2..916a20d 100644
@@ -688,52 +688,43 @@ static int ci_get_platdata(struct device *dev,
 	if (usb_get_maximum_speed(dev) == USB_SPEED_FULL)
 		platdata->flags |= CI_HDRC_FORCE_FULLSPEED;
 
-	if (of_find_property(dev->of_node, "phy-clkgate-delay-us", NULL))
-		of_property_read_u32(dev->of_node, "phy-clkgate-delay-us",
-				     &platdata->phy_clkgate_delay_us);
+	if (!of_property_read_u32(dev->of_node, "phy-clkgate-delay-us",
+				     &platdata->phy_clkgate_delay_us))
 
 	platdata->itc_setting = 1;
-	if (of_find_property(dev->of_node, "itc-setting", NULL)) {
-		ret = of_property_read_u32(dev->of_node, "itc-setting",
-			&platdata->itc_setting);
-		if (ret) {
-			dev_err(dev,
-				"failed to get itc-setting\n");
-			return ret;
-		}
+
+	ret = of_property_read_u32(dev->of_node, "itc-setting",
+					&platdata->itc_setting);
+	if (ret && ret != -EINVAL) {
+		dev_err(dev, "failed to get itc-setting\n");
+		return ret;
 	}
 
-	if (of_find_property(dev->of_node, "ahb-burst-config", NULL)) {
-		ret = of_property_read_u32(dev->of_node, "ahb-burst-config",
-			&platdata->ahb_burst_config);
-		if (ret) {
-			dev_err(dev,
-				"failed to get ahb-burst-config\n");
-			return ret;
-		}
+	ret = of_property_read_u32(dev->of_node, "ahb-burst-config",
+				&platdata->ahb_burst_config);
+	if (!ret) {
 		platdata->flags |= CI_HDRC_OVERRIDE_AHB_BURST;
+	} else if (ret != -EINVAL) {
+		dev_err(dev, "failed to get ahb-burst-config\n");
+		return ret;
 	}
 
-	if (of_find_property(dev->of_node, "tx-burst-size-dword", NULL)) {
-		ret = of_property_read_u32(dev->of_node, "tx-burst-size-dword",
-			&platdata->tx_burst_size);
-		if (ret) {
-			dev_err(dev,
-				"failed to get tx-burst-size-dword\n");
-			return ret;
-		}
+	ret = of_property_read_u32(dev->of_node, "tx-burst-size-dword",
+				&platdata->tx_burst_size);
+	if (!ret) {
 		platdata->flags |= CI_HDRC_OVERRIDE_TX_BURST;
+	} else if (ret != -EINVAL) {
+		dev_err(dev, "failed to get tx-burst-size-dword\n");
+		return ret;
 	}
 
-	if (of_find_property(dev->of_node, "rx-burst-size-dword", NULL)) {
-		ret = of_property_read_u32(dev->of_node, "rx-burst-size-dword",
-			&platdata->rx_burst_size);
-		if (ret) {
-			dev_err(dev,
-				"failed to get rx-burst-size-dword\n");
-			return ret;
-		}
+	ret = of_property_read_u32(dev->of_node, "rx-burst-size-dword",
+				&platdata->rx_burst_size);
+	if (!ret) {
 		platdata->flags |= CI_HDRC_OVERRIDE_RX_BURST;
+	} else if (ret != -EINVAL) {
+		dev_err(dev, "failed to get rx-burst-size-dword\n");
+		return ret;
 	}
 
 	ext_id = ERR_PTR(-ENODEV);
Signature · 1 line
1.9.1
#3 lore raw
Quoted 14 lines · Saurabh Sengar

call to of_find_property() before of_property_read_u32() is unnecessary. of_property_read_u32() anyway calls to of_find_property() only.

---
v2: removed pval variable

 drivers/usb/chipidea/core.c | 61 +++++++++++++++++++--------------------------
 1 file changed, 26 insertions(+), 35 deletions(-)
drivers/usb/chipidea/core.c +0 -0
index 965d0e2..916a20d 100644

drivers/usb/chipidea/core.c static int ci_get_platdata(struct device *dev, · line 694

Quoted 10 lines
drivers/usb/chipidea/core.c +2 -3
@@ -688,52 +688,43 @@ static int ci_get_platdata(struct device *dev,
 	if (usb_get_maximum_speed(dev) == USB_SPEED_FULL)
 		platdata->flags |= CI_HDRC_FORCE_FULLSPEED;
 
-	if (of_find_property(dev->of_node, "phy-clkgate-delay-us", NULL))
-		of_property_read_u32(dev->of_node, "phy-clkgate-delay-us",
-				     &platdata->phy_clkgate_delay_us);
+	if (!of_property_read_u32(dev->of_node, "phy-clkgate-delay-us",
+				     &platdata->phy_clkgate_delay_us))
 
 	platdata->itc_setting = 1;

Drop that if(). Since we're ignoring of_property_read_u32() failing, there is no need to test its return value, and code above incorrectly makes the next statement conditional.

Signature · 2 lines
Måns Rullgård
[email protected]
#4 lore raw

PATCH v3 1/1 usb: chipidea: removing of_find_property

call to of_find_property() before of_property_read_u32() is unnecessary. of_property_read_u32() anyway calls to of_find_property() only.

---
v2 : removed pval variable
v3 : removed unnecessary if condition

 drivers/usb/chipidea/core.c | 59 +++++++++++++++++++--------------------------
 1 file changed, 25 insertions(+), 34 deletions(-)
drivers/usb/chipidea/core.c +25 -34
index 965d0e2..960a925 100644
@@ -688,52 +688,43 @@ static int ci_get_platdata(struct device *dev,
 	if (usb_get_maximum_speed(dev) == USB_SPEED_FULL)
 		platdata->flags |= CI_HDRC_FORCE_FULLSPEED;
 
-	if (of_find_property(dev->of_node, "phy-clkgate-delay-us", NULL))
-		of_property_read_u32(dev->of_node, "phy-clkgate-delay-us",
+	of_property_read_u32(dev->of_node, "phy-clkgate-delay-us",
 				     &platdata->phy_clkgate_delay_us);
 
 	platdata->itc_setting = 1;
-	if (of_find_property(dev->of_node, "itc-setting", NULL)) {
-		ret = of_property_read_u32(dev->of_node, "itc-setting",
-			&platdata->itc_setting);
-		if (ret) {
-			dev_err(dev,
-				"failed to get itc-setting\n");
-			return ret;
-		}
+
+	ret = of_property_read_u32(dev->of_node, "itc-setting",
+					&platdata->itc_setting);
+	if (ret && ret != -EINVAL) {
+		dev_err(dev, "failed to get itc-setting\n");
+		return ret;
 	}
 
-	if (of_find_property(dev->of_node, "ahb-burst-config", NULL)) {
-		ret = of_property_read_u32(dev->of_node, "ahb-burst-config",
-			&platdata->ahb_burst_config);
-		if (ret) {
-			dev_err(dev,
-				"failed to get ahb-burst-config\n");
-			return ret;
-		}
+	ret = of_property_read_u32(dev->of_node, "ahb-burst-config",
+				&platdata->ahb_burst_config);
+	if (!ret) {
 		platdata->flags |= CI_HDRC_OVERRIDE_AHB_BURST;
+	} else if (ret != -EINVAL) {
+		dev_err(dev, "failed to get ahb-burst-config\n");
+		return ret;
 	}
 
-	if (of_find_property(dev->of_node, "tx-burst-size-dword", NULL)) {
-		ret = of_property_read_u32(dev->of_node, "tx-burst-size-dword",
-			&platdata->tx_burst_size);
-		if (ret) {
-			dev_err(dev,
-				"failed to get tx-burst-size-dword\n");
-			return ret;
-		}
+	ret = of_property_read_u32(dev->of_node, "tx-burst-size-dword",
+				&platdata->tx_burst_size);
+	if (!ret) {
 		platdata->flags |= CI_HDRC_OVERRIDE_TX_BURST;
+	} else if (ret != -EINVAL) {
+		dev_err(dev, "failed to get tx-burst-size-dword\n");
+		return ret;
 	}
 
-	if (of_find_property(dev->of_node, "rx-burst-size-dword", NULL)) {
-		ret = of_property_read_u32(dev->of_node, "rx-burst-size-dword",
-			&platdata->rx_burst_size);
-		if (ret) {
-			dev_err(dev,
-				"failed to get rx-burst-size-dword\n");
-			return ret;
-		}
+	ret = of_property_read_u32(dev->of_node, "rx-burst-size-dword",
+				&platdata->rx_burst_size);
+	if (!ret) {
 		platdata->flags |= CI_HDRC_OVERRIDE_RX_BURST;
+	} else if (ret != -EINVAL) {
+		dev_err(dev, "failed to get rx-burst-size-dword\n");
+		return ret;
 	}
 
 	ext_id = ERR_PTR(-ENODEV);
Signature · 1 line
1.9.1
#5 lore raw
Quoted 29 lines · Saurabh Sengar

call to of_find_property() before of_property_read_u32() is unnecessary. of_property_read_u32() anyway calls to of_find_property() only.

---
v2 : removed pval variable
v3 : removed unnecessary if condition

 drivers/usb/chipidea/core.c | 59 +++++++++++++++++++--------------------------
 1 file changed, 25 insertions(+), 34 deletions(-)
drivers/usb/chipidea/core.c +1 -7
index 965d0e2..960a925 100644
@@ -688,52 +688,43 @@ static int ci_get_platdata(struct device *dev,
 	if (usb_get_maximum_speed(dev) == USB_SPEED_FULL)
 		platdata->flags |= CI_HDRC_FORCE_FULLSPEED;
 
-	if (of_find_property(dev->of_node, "phy-clkgate-delay-us", NULL))
-		of_property_read_u32(dev->of_node, "phy-clkgate-delay-us",
+	of_property_read_u32(dev->of_node, "phy-clkgate-delay-us",
 				     &platdata->phy_clkgate_delay_us);
 
 	platdata->itc_setting = 1;
-	if (of_find_property(dev->of_node, "itc-setting", NULL)) {
-		ret = of_property_read_u32(dev->of_node, "itc-setting",
-			&platdata->itc_setting);
-		if (ret) {
-			dev_err(dev,

drivers/usb/chipidea/core.c static int ci_get_platdata(struct device *dev, · line 701

Quoted 10 lines
drivers/usb/chipidea/core.c +6 -3
-				"failed to get itc-setting\n");
-			return ret;
-		}
+
+	ret = of_property_read_u32(dev->of_node, "itc-setting",
+					&platdata->itc_setting);
+	if (ret && ret != -EINVAL) {
+		dev_err(dev, "failed to get itc-setting\n");
+		return ret;
 	}

For this one, you may not need to check return value, since platdata->itc_setting is optional, and doesn't need to set any flags if platdata->itc_setting is valid.

Other changes are ok for me.

Peter

Quoted 56 lines
drivers/usb/chipidea/core.c +18 -24
-	if (of_find_property(dev->of_node, "ahb-burst-config", NULL)) {
-		ret = of_property_read_u32(dev->of_node, "ahb-burst-config",
-			&platdata->ahb_burst_config);
-		if (ret) {
-			dev_err(dev,
-				"failed to get ahb-burst-config\n");
-			return ret;
-		}
+	ret = of_property_read_u32(dev->of_node, "ahb-burst-config",
+				&platdata->ahb_burst_config);
+	if (!ret) {
 		platdata->flags |= CI_HDRC_OVERRIDE_AHB_BURST;
+	} else if (ret != -EINVAL) {
+		dev_err(dev, "failed to get ahb-burst-config\n");
+		return ret;
 	}
 
-	if (of_find_property(dev->of_node, "tx-burst-size-dword", NULL)) {
-		ret = of_property_read_u32(dev->of_node, "tx-burst-size-dword",
-			&platdata->tx_burst_size);
-		if (ret) {
-			dev_err(dev,
-				"failed to get tx-burst-size-dword\n");
-			return ret;
-		}
+	ret = of_property_read_u32(dev->of_node, "tx-burst-size-dword",
+				&platdata->tx_burst_size);
+	if (!ret) {
 		platdata->flags |= CI_HDRC_OVERRIDE_TX_BURST;
+	} else if (ret != -EINVAL) {
+		dev_err(dev, "failed to get tx-burst-size-dword\n");
+		return ret;
 	}
 
-	if (of_find_property(dev->of_node, "rx-burst-size-dword", NULL)) {
-		ret = of_property_read_u32(dev->of_node, "rx-burst-size-dword",
-			&platdata->rx_burst_size);
-		if (ret) {
-			dev_err(dev,
-				"failed to get rx-burst-size-dword\n");
-			return ret;
-		}
+	ret = of_property_read_u32(dev->of_node, "rx-burst-size-dword",
+				&platdata->rx_burst_size);
+	if (!ret) {
 		platdata->flags |= CI_HDRC_OVERRIDE_RX_BURST;
+	} else if (ret != -EINVAL) {
+		dev_err(dev, "failed to get rx-burst-size-dword\n");
+		return ret;
 	}
 
 	ext_id = ERR_PTR(-ENODEV);
Signature · 1 line
1.9.1
Signature · 2 lines
Best Regards,
Peter Chen
#6 lore raw

Hi Peter,

Yes itc_setting is still optional, in case dts does not pass this property, return type will be -EINVAL and there would be no problem. The function will break only if there is 'No data'(-ENODATA) or 'overflow'(-ENODATA) error for this property.
In case this is not OK, I will send a another patch(v4) as you have suggested.

Regards,
Saurabh

Quoted 110 lines · Peter Chen
Quoted 29 lines · Saurabh Sengar

call to of_find_property() before of_property_read_u32() is unnecessary. of_property_read_u32() anyway calls to of_find_property() only.

---
v2 : removed pval variable
v3 : removed unnecessary if condition

 drivers/usb/chipidea/core.c | 59 +++++++++++++++++++--------------------------
 1 file changed, 25 insertions(+), 34 deletions(-)
drivers/usb/chipidea/core.c +1 -7
index 965d0e2..960a925 100644
@@ -688,52 +688,43 @@ static int ci_get_platdata(struct device *dev,
      if (usb_get_maximum_speed(dev) == USB_SPEED_FULL)
              platdata->flags |= CI_HDRC_FORCE_FULLSPEED;
 
-     if (of_find_property(dev->of_node, "phy-clkgate-delay-us", NULL))
-             of_property_read_u32(dev->of_node, "phy-clkgate-delay-us",
+     of_property_read_u32(dev->of_node, "phy-clkgate-delay-us",
                                   &platdata->phy_clkgate_delay_us);
 
      platdata->itc_setting = 1;
-     if (of_find_property(dev->of_node, "itc-setting", NULL)) {
-             ret = of_property_read_u32(dev->of_node, "itc-setting",
-                     &platdata->itc_setting);
-             if (ret) {
-                     dev_err(dev,

drivers/usb/chipidea/core.c static int ci_get_platdata(struct device *dev, · line 701

Quoted 10 lines
drivers/usb/chipidea/core.c +6 -3
-                             "failed to get itc-setting\n");
-                     return ret;
-             }
+
+     ret = of_property_read_u32(dev->of_node, "itc-setting",
+                                     &platdata->itc_setting);
+     if (ret && ret != -EINVAL) {
+             dev_err(dev, "failed to get itc-setting\n");
+             return ret;
      }

For this one, you may not need to check return value, since platdata->itc_setting is optional, and doesn't need to set any flags if platdata->itc_setting is valid.

Other changes are ok for me.

Peter

Quoted 54 lines
drivers/usb/chipidea/core.c +18 -25
-     if (of_find_property(dev->of_node, "ahb-burst-config", NULL)) {
-             ret = of_property_read_u32(dev->of_node, "ahb-burst-config",
-                     &platdata->ahb_burst_config);
-             if (ret) {
-                     dev_err(dev,
-                             "failed to get ahb-burst-config\n");
-                     return ret;
-             }
+     ret = of_property_read_u32(dev->of_node, "ahb-burst-config",
+                             &platdata->ahb_burst_config);
+     if (!ret) {
              platdata->flags |= CI_HDRC_OVERRIDE_AHB_BURST;
+     } else if (ret != -EINVAL) {
+             dev_err(dev, "failed to get ahb-burst-config\n");
+             return ret;
      }
 
-     if (of_find_property(dev->of_node, "tx-burst-size-dword", NULL)) {
-             ret = of_property_read_u32(dev->of_node, "tx-burst-size-dword",
-                     &platdata->tx_burst_size);
-             if (ret) {
-                     dev_err(dev,
-                             "failed to get tx-burst-size-dword\n");
-                     return ret;
-             }
+     ret = of_property_read_u32(dev->of_node, "tx-burst-size-dword",
+                             &platdata->tx_burst_size);
+     if (!ret) {
              platdata->flags |= CI_HDRC_OVERRIDE_TX_BURST;
+     } else if (ret != -EINVAL) {
+             dev_err(dev, "failed to get tx-burst-size-dword\n");
+             return ret;
      }
 
-     if (of_find_property(dev->of_node, "rx-burst-size-dword", NULL)) {
-             ret = of_property_read_u32(dev->of_node, "rx-burst-size-dword",
-                     &platdata->rx_burst_size);
-             if (ret) {
-                     dev_err(dev,
-                             "failed to get rx-burst-size-dword\n");
-                     return ret;
-             }
+     ret = of_property_read_u32(dev->of_node, "rx-burst-size-dword",
+                             &platdata->rx_burst_size);
+     if (!ret) {
              platdata->flags |= CI_HDRC_OVERRIDE_RX_BURST;
+     } else if (ret != -EINVAL) {
+             dev_err(dev, "failed to get rx-burst-size-dword\n");
+             return ret;
      }
 
      ext_id = ERR_PTR(-ENODEV);
--
Quoted 2 lines

1.9.1

--

Best Regards,
Peter Chen

#7 lore raw

PATCH v4 1/1 usb: chipidea: removing of_find_property

call to of_find_property() before of_property_read_u32() is unnecessary. of_property_read_u32() anyway calls to of_find_property() only.

---
v4 : removed return type check for optional property 'itc-setting'

 drivers/usb/chipidea/core.c | 57 +++++++++++++++++----------------------------
 1 file changed, 22 insertions(+), 35 deletions(-)
drivers/usb/chipidea/core.c +22 -35
index 965d0e2..3d1c3c5 100644
@@ -688,52 +688,39 @@ static int ci_get_platdata(struct device *dev,
 	if (usb_get_maximum_speed(dev) == USB_SPEED_FULL)
 		platdata->flags |= CI_HDRC_FORCE_FULLSPEED;
 
-	if (of_find_property(dev->of_node, "phy-clkgate-delay-us", NULL))
-		of_property_read_u32(dev->of_node, "phy-clkgate-delay-us",
+	of_property_read_u32(dev->of_node, "phy-clkgate-delay-us",
 				     &platdata->phy_clkgate_delay_us);
 
 	platdata->itc_setting = 1;
-	if (of_find_property(dev->of_node, "itc-setting", NULL)) {
-		ret = of_property_read_u32(dev->of_node, "itc-setting",
-			&platdata->itc_setting);
-		if (ret) {
-			dev_err(dev,
-				"failed to get itc-setting\n");
-			return ret;
-		}
-	}
 
-	if (of_find_property(dev->of_node, "ahb-burst-config", NULL)) {
-		ret = of_property_read_u32(dev->of_node, "ahb-burst-config",
-			&platdata->ahb_burst_config);
-		if (ret) {
-			dev_err(dev,
-				"failed to get ahb-burst-config\n");
-			return ret;
-		}
+	of_property_read_u32(dev->of_node, "itc-setting",
+					&platdata->itc_setting);
+
+	ret = of_property_read_u32(dev->of_node, "ahb-burst-config",
+				&platdata->ahb_burst_config);
+	if (!ret) {
 		platdata->flags |= CI_HDRC_OVERRIDE_AHB_BURST;
+	} else if (ret != -EINVAL) {
+		dev_err(dev, "failed to get ahb-burst-config\n");
+		return ret;
 	}
 
-	if (of_find_property(dev->of_node, "tx-burst-size-dword", NULL)) {
-		ret = of_property_read_u32(dev->of_node, "tx-burst-size-dword",
-			&platdata->tx_burst_size);
-		if (ret) {
-			dev_err(dev,
-				"failed to get tx-burst-size-dword\n");
-			return ret;
-		}
+	ret = of_property_read_u32(dev->of_node, "tx-burst-size-dword",
+				&platdata->tx_burst_size);
+	if (!ret) {
 		platdata->flags |= CI_HDRC_OVERRIDE_TX_BURST;
+	} else if (ret != -EINVAL) {
+		dev_err(dev, "failed to get tx-burst-size-dword\n");
+		return ret;
 	}
 
-	if (of_find_property(dev->of_node, "rx-burst-size-dword", NULL)) {
-		ret = of_property_read_u32(dev->of_node, "rx-burst-size-dword",
-			&platdata->rx_burst_size);
-		if (ret) {
-			dev_err(dev,
-				"failed to get rx-burst-size-dword\n");
-			return ret;
-		}
+	ret = of_property_read_u32(dev->of_node, "rx-burst-size-dword",
+				&platdata->rx_burst_size);
+	if (!ret) {
 		platdata->flags |= CI_HDRC_OVERRIDE_RX_BURST;
+	} else if (ret != -EINVAL) {
+		dev_err(dev, "failed to get rx-burst-size-dword\n");
+		return ret;
 	}
 
 	ext_id = ERR_PTR(-ENODEV);
Signature · 1 line
1.9.1
#8 lore raw
Quoted 43 lines · Saurabh Sengar

call to of_find_property() before of_property_read_u32() is unnecessary. of_property_read_u32() anyway calls to of_find_property() only.

---
v4 : removed return type check for optional property 'itc-setting'

 drivers/usb/chipidea/core.c | 57 +++++++++++++++++----------------------------
 1 file changed, 22 insertions(+), 35 deletions(-)
drivers/usb/chipidea/core.c +2 -19
index 965d0e2..3d1c3c5 100644
@@ -688,52 +688,39 @@ static int ci_get_platdata(struct device *dev,
 	if (usb_get_maximum_speed(dev) == USB_SPEED_FULL)
 		platdata->flags |= CI_HDRC_FORCE_FULLSPEED;
 
-	if (of_find_property(dev->of_node, "phy-clkgate-delay-us", NULL))
-		of_property_read_u32(dev->of_node, "phy-clkgate-delay-us",
+	of_property_read_u32(dev->of_node, "phy-clkgate-delay-us",
 				     &platdata->phy_clkgate_delay_us);
 
 	platdata->itc_setting = 1;
-	if (of_find_property(dev->of_node, "itc-setting", NULL)) {
-		ret = of_property_read_u32(dev->of_node, "itc-setting",
-			&platdata->itc_setting);
-		if (ret) {
-			dev_err(dev,
-				"failed to get itc-setting\n");
-			return ret;
-		}
-	}
 
-	if (of_find_property(dev->of_node, "ahb-burst-config", NULL)) {
-		ret = of_property_read_u32(dev->of_node, "ahb-burst-config",
-			&platdata->ahb_burst_config);
-		if (ret) {
-			dev_err(dev,
-				"failed to get ahb-burst-config\n");
-			return ret;
-		}
+	of_property_read_u32(dev->of_node, "itc-setting",

drivers/usb/chipidea/core.c static int ci_get_platdata(struct device *dev, · line 706

Quoted 10 lines
drivers/usb/chipidea/core.c +8 -0
+					&platdata->itc_setting);
+
+	ret = of_property_read_u32(dev->of_node, "ahb-burst-config",
+				&platdata->ahb_burst_config);
+	if (!ret) {
 		platdata->flags |= CI_HDRC_OVERRIDE_AHB_BURST;
+	} else if (ret != -EINVAL) {
+		dev_err(dev, "failed to get ahb-burst-config\n");
+		return ret;
 	}

Sorry, one more comment, why we don't quit if the 'ret' is other error value?

Peter

Quoted 39 lines
drivers/usb/chipidea/core.c +12 -16
-	if (of_find_property(dev->of_node, "tx-burst-size-dword", NULL)) {
-		ret = of_property_read_u32(dev->of_node, "tx-burst-size-dword",
-			&platdata->tx_burst_size);
-		if (ret) {
-			dev_err(dev,
-				"failed to get tx-burst-size-dword\n");
-			return ret;
-		}
+	ret = of_property_read_u32(dev->of_node, "tx-burst-size-dword",
+				&platdata->tx_burst_size);
+	if (!ret) {
 		platdata->flags |= CI_HDRC_OVERRIDE_TX_BURST;
+	} else if (ret != -EINVAL) {
+		dev_err(dev, "failed to get tx-burst-size-dword\n");
+		return ret;
 	}
 
-	if (of_find_property(dev->of_node, "rx-burst-size-dword", NULL)) {
-		ret = of_property_read_u32(dev->of_node, "rx-burst-size-dword",
-			&platdata->rx_burst_size);
-		if (ret) {
-			dev_err(dev,
-				"failed to get rx-burst-size-dword\n");
-			return ret;
-		}
+	ret = of_property_read_u32(dev->of_node, "rx-burst-size-dword",
+				&platdata->rx_burst_size);
+	if (!ret) {
 		platdata->flags |= CI_HDRC_OVERRIDE_RX_BURST;
+	} else if (ret != -EINVAL) {
+		dev_err(dev, "failed to get rx-burst-size-dword\n");
+		return ret;
 	}
 
 	ext_id = ERR_PTR(-ENODEV);
Signature · 1 line
1.9.1
Signature · 2 lines
Best Regards,
Peter Chen
#9 lore raw
Quoted 58 lines · Peter Chen
Quoted 43 lines · Saurabh Sengar

call to of_find_property() before of_property_read_u32() is unnecessary. of_property_read_u32() anyway calls to of_find_property() only.

---
v4 : removed return type check for optional property 'itc-setting'

 drivers/usb/chipidea/core.c | 57 +++++++++++++++++----------------------------
 1 file changed, 22 insertions(+), 35 deletions(-)
drivers/usb/chipidea/core.c +2 -19
index 965d0e2..3d1c3c5 100644
@@ -688,52 +688,39 @@ static int ci_get_platdata(struct device *dev,
      if (usb_get_maximum_speed(dev) == USB_SPEED_FULL)
              platdata->flags |= CI_HDRC_FORCE_FULLSPEED;
 
-     if (of_find_property(dev->of_node, "phy-clkgate-delay-us", NULL))
-             of_property_read_u32(dev->of_node, "phy-clkgate-delay-us",
+     of_property_read_u32(dev->of_node, "phy-clkgate-delay-us",
                                   &platdata->phy_clkgate_delay_us);
 
      platdata->itc_setting = 1;
-     if (of_find_property(dev->of_node, "itc-setting", NULL)) {
-             ret = of_property_read_u32(dev->of_node, "itc-setting",
-                     &platdata->itc_setting);
-             if (ret) {
-                     dev_err(dev,
-                             "failed to get itc-setting\n");
-                     return ret;
-             }
-     }
 
-     if (of_find_property(dev->of_node, "ahb-burst-config", NULL)) {
-             ret = of_property_read_u32(dev->of_node, "ahb-burst-config",
-                     &platdata->ahb_burst_config);
-             if (ret) {
-                     dev_err(dev,
-                             "failed to get ahb-burst-config\n");
-                     return ret;
-             }
+     of_property_read_u32(dev->of_node, "itc-setting",

drivers/usb/chipidea/core.c static int ci_get_platdata(struct device *dev, · line 706

Quoted 10 lines
drivers/usb/chipidea/core.c +8 -0
+                                     &platdata->itc_setting);
+
+     ret = of_property_read_u32(dev->of_node, "ahb-burst-config",
+                             &platdata->ahb_burst_config);
+     if (!ret) {
              platdata->flags |= CI_HDRC_OVERRIDE_AHB_BURST;
+     } else if (ret != -EINVAL) {
+             dev_err(dev, "failed to get ahb-burst-config\n");
+             return ret;
      }

Sorry, one more comment, why we don't quit if the 'ret' is other error value?

Quoted 1 line

Peter

We quit if error is anything other then -EINVAL.
In case of -EINVAL, it means we are deliberating ignoring that property thus left it.
Also the previous functionality was like this when we were using of_find_property().
Please let me know if this need to be changed, that we need to return in all kind of error, I will fix it and send it in patch v5.

Regards,
Saurabh

#10 lore raw
Quoted 61 lines · Saurabh Sengar
Quoted 58 lines · Peter Chen
Quoted 43 lines · Saurabh Sengar

call to of_find_property() before of_property_read_u32() is unnecessary. of_property_read_u32() anyway calls to of_find_property() only.

---
v4 : removed return type check for optional property 'itc-setting'

 drivers/usb/chipidea/core.c | 57 +++++++++++++++++----------------------------
 1 file changed, 22 insertions(+), 35 deletions(-)
drivers/usb/chipidea/core.c +2 -19
index 965d0e2..3d1c3c5 100644
@@ -688,52 +688,39 @@ static int ci_get_platdata(struct device *dev,
      if (usb_get_maximum_speed(dev) == USB_SPEED_FULL)
              platdata->flags |= CI_HDRC_FORCE_FULLSPEED;
 
-     if (of_find_property(dev->of_node, "phy-clkgate-delay-us", NULL))
-             of_property_read_u32(dev->of_node, "phy-clkgate-delay-us",
+     of_property_read_u32(dev->of_node, "phy-clkgate-delay-us",
                                   &platdata->phy_clkgate_delay_us);
 
      platdata->itc_setting = 1;
-     if (of_find_property(dev->of_node, "itc-setting", NULL)) {
-             ret = of_property_read_u32(dev->of_node, "itc-setting",
-                     &platdata->itc_setting);
-             if (ret) {
-                     dev_err(dev,
-                             "failed to get itc-setting\n");
-                     return ret;
-             }
-     }
 
-     if (of_find_property(dev->of_node, "ahb-burst-config", NULL)) {
-             ret = of_property_read_u32(dev->of_node, "ahb-burst-config",
-                     &platdata->ahb_burst_config);
-             if (ret) {
-                     dev_err(dev,
-                             "failed to get ahb-burst-config\n");
-                     return ret;
-             }
+     of_property_read_u32(dev->of_node, "itc-setting",

drivers/usb/chipidea/core.c static int ci_get_platdata(struct device *dev, · line 706

Quoted 10 lines
drivers/usb/chipidea/core.c +8 -0
+                                     &platdata->itc_setting);
+
+     ret = of_property_read_u32(dev->of_node, "ahb-burst-config",
+                             &platdata->ahb_burst_config);
+     if (!ret) {
              platdata->flags |= CI_HDRC_OVERRIDE_AHB_BURST;
+     } else if (ret != -EINVAL) {
+             dev_err(dev, "failed to get ahb-burst-config\n");
+             return ret;
      }

Sorry, one more comment, why we don't quit if the 'ret' is other error value?

Quoted 1 line

Peter

Quoted 8 lines

We quit if error is anything other then -EINVAL.
In case of -EINVAL, it means we are deliberating ignoring that property thus left it.
Also the previous functionality was like this when we were using of_find_property().
Please let me know if this need to be changed, that we need to return in all kind of error, I will fix it and send it in patch v5.

I am clear now, I will queue it.

Signature · 2 lines
Best Regards,
Peter Chen
#11 lore raw
Quoted 1 line · Peter Chen

I am clear now, I will queue it.

Thank you

#12 lore raw
In reply to Saurabh Sengar
Quoted 6 lines · Saurabh Sengar

Hi Peter,

Yes itc_setting is still optional, in case dts does not pass this property, return type will be -EINVAL and there would be no problem. The function will break only if there is 'No data'(-ENODATA) or 'overflow'(-ENODATA) error for this property.

If there is an error, the variable pass to of_property_read_u32 will not be changed.

Peter

Quoted 116 lines

In case this is not OK, I will send a another patch(v4) as you have suggested.

Regards,
Saurabh

Quoted 110 lines · Peter Chen
Quoted 29 lines · Saurabh Sengar

call to of_find_property() before of_property_read_u32() is unnecessary. of_property_read_u32() anyway calls to of_find_property() only.

---
v2 : removed pval variable
v3 : removed unnecessary if condition

 drivers/usb/chipidea/core.c | 59 +++++++++++++++++++--------------------------
 1 file changed, 25 insertions(+), 34 deletions(-)
drivers/usb/chipidea/core.c +1 -7
index 965d0e2..960a925 100644
@@ -688,52 +688,43 @@ static int ci_get_platdata(struct device *dev,
      if (usb_get_maximum_speed(dev) == USB_SPEED_FULL)
              platdata->flags |= CI_HDRC_FORCE_FULLSPEED;
 
-     if (of_find_property(dev->of_node, "phy-clkgate-delay-us", NULL))
-             of_property_read_u32(dev->of_node, "phy-clkgate-delay-us",
+     of_property_read_u32(dev->of_node, "phy-clkgate-delay-us",
                                   &platdata->phy_clkgate_delay_us);
 
      platdata->itc_setting = 1;
-     if (of_find_property(dev->of_node, "itc-setting", NULL)) {
-             ret = of_property_read_u32(dev->of_node, "itc-setting",
-                     &platdata->itc_setting);
-             if (ret) {
-                     dev_err(dev,

drivers/usb/chipidea/core.c static int ci_get_platdata(struct device *dev, · line 701

Quoted 10 lines
drivers/usb/chipidea/core.c +6 -3
-                             "failed to get itc-setting\n");
-                     return ret;
-             }
+
+     ret = of_property_read_u32(dev->of_node, "itc-setting",
+                                     &platdata->itc_setting);
+     if (ret && ret != -EINVAL) {
+             dev_err(dev, "failed to get itc-setting\n");
+             return ret;
      }

For this one, you may not need to check return value, since platdata->itc_setting is optional, and doesn't need to set any flags if platdata->itc_setting is valid.

Other changes are ok for me.

Peter

Quoted 54 lines
drivers/usb/chipidea/core.c +18 -25
-     if (of_find_property(dev->of_node, "ahb-burst-config", NULL)) {
-             ret = of_property_read_u32(dev->of_node, "ahb-burst-config",
-                     &platdata->ahb_burst_config);
-             if (ret) {
-                     dev_err(dev,
-                             "failed to get ahb-burst-config\n");
-                     return ret;
-             }
+     ret = of_property_read_u32(dev->of_node, "ahb-burst-config",
+                             &platdata->ahb_burst_config);
+     if (!ret) {
              platdata->flags |= CI_HDRC_OVERRIDE_AHB_BURST;
+     } else if (ret != -EINVAL) {
+             dev_err(dev, "failed to get ahb-burst-config\n");
+             return ret;
      }
 
-     if (of_find_property(dev->of_node, "tx-burst-size-dword", NULL)) {
-             ret = of_property_read_u32(dev->of_node, "tx-burst-size-dword",
-                     &platdata->tx_burst_size);
-             if (ret) {
-                     dev_err(dev,
-                             "failed to get tx-burst-size-dword\n");
-                     return ret;
-             }
+     ret = of_property_read_u32(dev->of_node, "tx-burst-size-dword",
+                             &platdata->tx_burst_size);
+     if (!ret) {
              platdata->flags |= CI_HDRC_OVERRIDE_TX_BURST;
+     } else if (ret != -EINVAL) {
+             dev_err(dev, "failed to get tx-burst-size-dword\n");
+             return ret;
      }
 
-     if (of_find_property(dev->of_node, "rx-burst-size-dword", NULL)) {
-             ret = of_property_read_u32(dev->of_node, "rx-burst-size-dword",
-                     &platdata->rx_burst_size);
-             if (ret) {
-                     dev_err(dev,
-                             "failed to get rx-burst-size-dword\n");
-                     return ret;
-             }
+     ret = of_property_read_u32(dev->of_node, "rx-burst-size-dword",
+                             &platdata->rx_burst_size);
+     if (!ret) {
              platdata->flags |= CI_HDRC_OVERRIDE_RX_BURST;
+     } else if (ret != -EINVAL) {
+             dev_err(dev, "failed to get rx-burst-size-dword\n");
+             return ret;
      }
 
      ext_id = ERR_PTR(-ENODEV);
--
Quoted 2 lines

1.9.1

--

Best Regards,
Peter Chen

Signature · 2 lines
Best Regards,
Peter Chen