[PATCH 2/5] regulator: of: Use of_property_read_u32_default()

Peng Fan (OSS) posted 5 patches 3 weeks ago
[PATCH 2/5] regulator: of: Use of_property_read_u32_default()
Posted by Peng Fan (OSS) 3 weeks ago
From: Peng Fan <peng.fan@nxp.com>

Convert open-coded patterns that read optional DT properties and fallback
to defaults into the new of_property_read_u32_default() helper. Keep the
existing behaviour while reducing boilerplate code.

No functional changes.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
 drivers/regulator/of_regulator.c | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c
index 33463926a2a6c10ccfd9aa59d31c0b0c3635833e..83b8a1db8f99c1eefee73ad1e7f234b2280076dc 100644
--- a/drivers/regulator/of_regulator.c
+++ b/drivers/regulator/of_regulator.c
@@ -178,12 +178,9 @@ static int of_get_regulation_constraints(struct device *dev,
 	if (!ret)
 		constraints->enable_time = pval;
 
-	ret = of_property_read_u32(np, "regulator-uv-less-critical-window-ms", &pval);
-	if (!ret)
-		constraints->uv_less_critical_window_ms = pval;
-	else
-		constraints->uv_less_critical_window_ms =
-				REGULATOR_DEF_UV_LESS_CRITICAL_WINDOW_MS;
+	constraints->uv_less_critical_window_ms =
+		of_property_read_u32_default(np, "regulator-uv-less-critical-window-ms",
+					     REGULATOR_DEF_UV_LESS_CRITICAL_WINDOW_MS);
 
 	constraints->soft_start = of_property_read_bool(np,
 					"regulator-soft-start");
@@ -313,11 +310,10 @@ static int of_get_regulation_constraints(struct device *dev,
 				"regulator-suspend-max-microvolt", &pval))
 			suspend_state->max_uV = pval;
 
-		if (!of_property_read_u32(suspend_np,
-					"regulator-suspend-microvolt", &pval))
-			suspend_state->uV = pval;
-		else /* otherwise use min_uV as default suspend voltage */
-			suspend_state->uV = suspend_state->min_uV;
+		/* Use min_uV as default suspend voltage if fail to get property */
+		suspend_state->uV =
+			of_property_read_u32_default(suspend_np, "regulator-suspend-microvolt",
+						     suspend_state->min_uV);
 
 		if (of_property_read_bool(suspend_np,
 					"regulator-changeable-in-suspend"))

-- 
2.37.1