* [PATCH 0/5] of: Introduce *_read_*_default helpers and convert regulator drivers
@ 2026-01-19 2:02 Peng Fan (OSS)
2026-01-19 2:02 ` [PATCH 1/5] of: Add of_property_read_[u32,s32]_default Peng Fan (OSS)
` (4 more replies)
0 siblings, 5 replies; 8+ messages in thread
From: Peng Fan (OSS) @ 2026-01-19 2:02 UTC (permalink / raw)
To: Rob Herring, Saravana Kannan, Liam Girdwood, Mark Brown,
Alexis Czezar Torreno
Cc: devicetree, linux-kernel, Peng Fan
Introduces new helper functions of_property_read_u32_default() and
of_property_read_s32_default() to simplify reading optional Device Tree
properties with well-defined default values.
A common pattern in drivers is to initialize a variable with a default
value and then override it when a DT property is present, or to explicitly
check the return value of of_property_read_*() and fall back to a default.
While correct, this leads to repetitive boilerplate code and obscures the
intent that the property is optional.
The new helpers make this intent explicit by directly expressing
“optional property with default”. They intentionally ignore error codes
and are meant for cases where a missing or invalid property is not
considered fatal and a sensible default exists.
On top of introducing the helpers, this series converts several
regulator drivers to use them, reducing boilerplate while preserving
existing behavior. No functional changes, except for a minor fix in one
error path where dev_err_probe() is now called with a proper error code.
Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
Peng Fan (5):
of: Add of_property_read_[u32,s32]_default
regulator: of: Use of_property_read_u32_default()
regulator: adp5055: use of_property_read_[u32|s32]_default()
regulator: max77620: Use of_property_read_u32_default() for DT parsing
regulator: fan53555: Use of_property_read_u32_default() for DT parsing
drivers/regulator/adp5055-regulator.c | 30 ++++++++++---------------
drivers/regulator/fan53555.c | 8 ++-----
drivers/regulator/max77620-regulator.c | 40 ++++++++++++++--------------------
drivers/regulator/of_regulator.c | 18 ++++++---------
include/linux/of.h | 38 ++++++++++++++++++++++++++++++++
5 files changed, 74 insertions(+), 60 deletions(-)
---
base-commit: 0f853ca2a798ead9d24d39cad99b0966815c582a
change-id: 20260115-add_dt_default-4ca95f2a6cd7
Best regards,
--
Peng Fan <peng.fan@nxp.com>
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/5] of: Add of_property_read_[u32,s32]_default
2026-01-19 2:02 [PATCH 0/5] of: Introduce *_read_*_default helpers and convert regulator drivers Peng Fan (OSS)
@ 2026-01-19 2:02 ` Peng Fan (OSS)
2026-01-20 22:21 ` Rob Herring
2026-01-19 2:02 ` [PATCH 2/5] regulator: of: Use of_property_read_u32_default() Peng Fan (OSS)
` (3 subsequent siblings)
4 siblings, 1 reply; 8+ messages in thread
From: Peng Fan (OSS) @ 2026-01-19 2:02 UTC (permalink / raw)
To: Rob Herring, Saravana Kannan, Liam Girdwood, Mark Brown,
Alexis Czezar Torreno
Cc: devicetree, linux-kernel, Peng Fan
From: Peng Fan <peng.fan@nxp.com>
Introduce new helper functions of_property_read_u32_default() and
of_property_read_s32_default() to simplify reading optional device tree
properties with a default value.
A very common pattern in drivers is to provide a default value and let
of_property_read_*() override it when the property is present, e.g.:
Y = Y_DEFAULT;
of_property_read_u32(np, "prop", &Y);
or equivalently, checking the return value explicitly:
ret = of_property_read_u32(np, "prop", &val);
if (ret)
Y = Y_DEFAULT;
else
Y = val;
Both forms express the same intent: the property is optional and a
well-defined default should be used if it cannot be read.
With the new helper, this can be expressed more directly as:
Y = of_property_read_u32_default(np, "prop", Y_DEFAULT);
The helpers intentionally ignore the error code and return either the
parsed value or the supplied default. They are meant for optional
properties only. Callers that need to handle or propagate errors should
continue using of_property_read_*() directly.
Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
include/linux/of.h | 38 ++++++++++++++++++++++++++++++++++++++
1 file changed, 38 insertions(+)
diff --git a/include/linux/of.h b/include/linux/of.h
index 9bbdcf25a2b448ba4ec5ddee8b35a105ca4aab8b..ef9f63755b20722969b682eae98a0dbd8cb21d58 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -1450,6 +1450,25 @@ static inline int of_property_read_u32(const struct device_node *np,
return of_property_read_u32_array(np, propname, out_value, 1);
}
+
+/**
+ * of_property_read_u32_default() - Read a u32 DT property or return a default.
+ * @np: device node
+ * @propname: property name
+ * @def: default value to return if the property cannot be read
+ *
+ * Return: The property value on success, or @def if the property is missing
+ * or invalid. This helper intentionally ignores the error code; it
+ * is intended for optional properties with a sensible default.
+ */
+static inline u32 of_property_read_u32_default(const struct device_node *np,
+ const char *propname,
+ u32 def)
+{
+ of_property_read_u32(np, propname, &def);
+ return def;
+}
+
static inline int of_property_read_s32(const struct device_node *np,
const char *propname,
s32 *out_value)
@@ -1457,6 +1476,25 @@ static inline int of_property_read_s32(const struct device_node *np,
return of_property_read_u32(np, propname, (u32*) out_value);
}
+
+/**
+ * of_property_read_s32_default() - Read an s32 DT property or return a default.
+ * @np: device node
+ * @propname: property name
+ * @def: default value to return if the property cannot be read
+ *
+ * Return: The property value on success, or @def if the property is missing
+ * or invalid. This helper intentionally ignores the error code; it
+ * is intended for optional properties with a sensible default.
+ */
+static inline s32 of_property_read_s32_default(const struct device_node *np,
+ const char *propname,
+ s32 def)
+{
+ of_property_read_s32(np, propname, &def);
+ return def;
+}
+
#define of_for_each_phandle(it, err, np, ln, cn, cc) \
for (of_phandle_iterator_init((it), (np), (ln), (cn), (cc)), \
err = of_phandle_iterator_next(it); \
--
2.37.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/5] regulator: of: Use of_property_read_u32_default()
2026-01-19 2:02 [PATCH 0/5] of: Introduce *_read_*_default helpers and convert regulator drivers Peng Fan (OSS)
2026-01-19 2:02 ` [PATCH 1/5] of: Add of_property_read_[u32,s32]_default Peng Fan (OSS)
@ 2026-01-19 2:02 ` Peng Fan (OSS)
2026-01-19 2:02 ` [PATCH 3/5] regulator: adp5055: use of_property_read_[u32|s32]_default() Peng Fan (OSS)
` (2 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Peng Fan (OSS) @ 2026-01-19 2:02 UTC (permalink / raw)
To: Rob Herring, Saravana Kannan, Liam Girdwood, Mark Brown,
Alexis Czezar Torreno
Cc: devicetree, linux-kernel, Peng Fan
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
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 3/5] regulator: adp5055: use of_property_read_[u32|s32]_default()
2026-01-19 2:02 [PATCH 0/5] of: Introduce *_read_*_default helpers and convert regulator drivers Peng Fan (OSS)
2026-01-19 2:02 ` [PATCH 1/5] of: Add of_property_read_[u32,s32]_default Peng Fan (OSS)
2026-01-19 2:02 ` [PATCH 2/5] regulator: of: Use of_property_read_u32_default() Peng Fan (OSS)
@ 2026-01-19 2:02 ` Peng Fan (OSS)
2026-01-19 2:02 ` [PATCH 4/5] regulator: max77620: Use of_property_read_u32_default() for DT parsing Peng Fan (OSS)
2026-01-19 2:02 ` [PATCH 5/5] regulator: fan53555: " Peng Fan (OSS)
4 siblings, 0 replies; 8+ messages in thread
From: Peng Fan (OSS) @ 2026-01-19 2:02 UTC (permalink / raw)
To: Rob Herring, Saravana Kannan, Liam Girdwood, Mark Brown,
Alexis Czezar Torreno
Cc: devicetree, linux-kernel, Peng Fan
From: Peng Fan <peng.fan@nxp.com>
Switch to of_property_read_[u32|s32]_default() to reduce boilerplate and
make the "optional with default" intent explicit when parsing the DVS upper
and lower limits from DT.
While at it, fix dev_err_probe() calls with a proper error code: -EINVAL.
No functional changes apart from the error-path fix.
Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
drivers/regulator/adp5055-regulator.c | 30 +++++++++++-------------------
1 file changed, 11 insertions(+), 19 deletions(-)
diff --git a/drivers/regulator/adp5055-regulator.c b/drivers/regulator/adp5055-regulator.c
index 4b004a6b2f84e8201228e7f542d83903031e00b7..e4a6d4c15772e54537ab00bc82ce05a5b0e7dc4d 100644
--- a/drivers/regulator/adp5055-regulator.c
+++ b/drivers/regulator/adp5055-regulator.c
@@ -218,25 +218,17 @@ static int adp5055_of_parse_cb(struct device_node *np,
adp5055->en_mode_software = true;
}
- ret = of_property_read_u32(np, "adi,dvs-limit-upper-microvolt", &pval);
- if (ret)
- adp5055->dvs_limit_upper[id] = 192000;
- else
- adp5055->dvs_limit_upper[id] = pval;
-
- if (adp5055->dvs_limit_upper[id] > 192000 || adp5055->dvs_limit_upper[id] < 12000)
- return dev_err_probe(config->dev, adp5055->dvs_limit_upper[id],
- "Out of range - dvs-limit-upper-microvolt value.");
-
- ret = of_property_read_u32(np, "adi,dvs-limit-lower-microvolt", &pval);
- if (ret)
- adp5055->dvs_limit_lower[id] = -190500;
- else
- adp5055->dvs_limit_lower[id] = pval;
-
- if (adp5055->dvs_limit_lower[id] > -10500 || adp5055->dvs_limit_lower[id] < -190500)
- return dev_err_probe(config->dev, adp5055->dvs_limit_lower[id],
- "Out of range - dvs-limit-lower-microvolt value.");
+ pval = of_property_read_u32_default(np, "adi,dvs-limit-upper-microvolt", 192000);
+ if (pval > 192000 || pval < 12000)
+ return dev_err_probe(config->dev, -EINVAL,
+ "Out of range - dvs-limit-upper-microvolt value.");
+ adp5055->dvs_limit_upper[id] = pval;
+
+ pval = of_property_read_s32_default(np, "adi,dvs-limit-lower-microvolt", -190500);
+ if (pval > -10500 || pval < -190500)
+ return dev_err_probe(config->dev, -EINVAL,
+ "Out of range - dvs-limit-lower-microvolt value.");
+ adp5055->dvs_limit_lower[id] = pval;
for (i = 0; i < 4; i++) {
ret = of_property_match_string(np, "adi,fast-transient",
--
2.37.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 4/5] regulator: max77620: Use of_property_read_u32_default() for DT parsing
2026-01-19 2:02 [PATCH 0/5] of: Introduce *_read_*_default helpers and convert regulator drivers Peng Fan (OSS)
` (2 preceding siblings ...)
2026-01-19 2:02 ` [PATCH 3/5] regulator: adp5055: use of_property_read_[u32|s32]_default() Peng Fan (OSS)
@ 2026-01-19 2:02 ` Peng Fan (OSS)
2026-01-19 2:02 ` [PATCH 5/5] regulator: fan53555: " Peng Fan (OSS)
4 siblings, 0 replies; 8+ messages in thread
From: Peng Fan (OSS) @ 2026-01-19 2:02 UTC (permalink / raw)
To: Rob Herring, Saravana Kannan, Liam Girdwood, Mark Brown,
Alexis Czezar Torreno
Cc: devicetree, linux-kernel, Peng Fan
From: Peng Fan <peng.fan@nxp.com>
Switch max77620_of_parse_cb() to of_property_read_u32_default() to simplify
device tree property parsing and remove duplicated error handling.
Properties that previously defaulted to -1 now explicitly use -1U,
preserving the original semantics.
No functional changes.
Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
drivers/regulator/max77620-regulator.c | 40 ++++++++++++++--------------------
1 file changed, 16 insertions(+), 24 deletions(-)
diff --git a/drivers/regulator/max77620-regulator.c b/drivers/regulator/max77620-regulator.c
index 7bc87d8e9f686651067b443c06d0791557e1d1e6..6ba3c2a995198234c0aef5dfe445ef291e8be2dd 100644
--- a/drivers/regulator/max77620-regulator.c
+++ b/drivers/regulator/max77620-regulator.c
@@ -605,38 +605,30 @@ static int max77620_of_parse_cb(struct device_node *np,
{
struct max77620_regulator *pmic = config->driver_data;
struct max77620_regulator_pdata *rpdata = &pmic->reg_pdata[desc->id];
- u32 pval;
- int ret;
- ret = of_property_read_u32(np, "maxim,active-fps-source", &pval);
- rpdata->active_fps_src = (!ret) ? pval : MAX77620_FPS_SRC_DEF;
+ rpdata->active_fps_src =
+ of_property_read_u32_default(np, "maxim,active-fps-source", MAX77620_FPS_SRC_DEF);
- ret = of_property_read_u32(np, "maxim,active-fps-power-up-slot", &pval);
- rpdata->active_fps_pu_slot = (!ret) ? pval : -1;
+ rpdata->active_fps_pu_slot =
+ of_property_read_u32_default(np, "maxim,active-fps-power-up-slot", -1U);
- ret = of_property_read_u32(
- np, "maxim,active-fps-power-down-slot", &pval);
- rpdata->active_fps_pd_slot = (!ret) ? pval : -1;
+ rpdata->active_fps_pd_slot =
+ of_property_read_u32_default(np, "maxim,active-fps-power-down-slot", -1U);
- ret = of_property_read_u32(np, "maxim,suspend-fps-source", &pval);
- rpdata->suspend_fps_src = (!ret) ? pval : -1;
+ rpdata->suspend_fps_src =
+ of_property_read_u32_default(np, "maxim,suspend-fps-source", -1U);
- ret = of_property_read_u32(
- np, "maxim,suspend-fps-power-up-slot", &pval);
- rpdata->suspend_fps_pu_slot = (!ret) ? pval : -1;
+ rpdata->suspend_fps_pu_slot =
+ of_property_read_u32_default(np, "maxim,suspend-fps-power-up-slot", -1U);
- ret = of_property_read_u32(
- np, "maxim,suspend-fps-power-down-slot", &pval);
- rpdata->suspend_fps_pd_slot = (!ret) ? pval : -1;
+ rpdata->suspend_fps_pd_slot =
+ of_property_read_u32_default(np, "maxim,suspend-fps-power-down-slot", -1U);
- ret = of_property_read_u32(np, "maxim,power-ok-control", &pval);
- if (!ret)
- rpdata->power_ok = pval;
- else
- rpdata->power_ok = -1;
+ rpdata->power_ok =
+ of_property_read_u32_default(np, "maxim,power-ok-control", -1U);
- ret = of_property_read_u32(np, "maxim,ramp-rate-setting", &pval);
- rpdata->ramp_rate_setting = (!ret) ? pval : 0;
+ rpdata->ramp_rate_setting =
+ of_property_read_u32_default(np, "maxim,ramp-rate-setting", 0);
return max77620_init_pmic(pmic, desc->id);
}
--
2.37.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 5/5] regulator: fan53555: Use of_property_read_u32_default() for DT parsing
2026-01-19 2:02 [PATCH 0/5] of: Introduce *_read_*_default helpers and convert regulator drivers Peng Fan (OSS)
` (3 preceding siblings ...)
2026-01-19 2:02 ` [PATCH 4/5] regulator: max77620: Use of_property_read_u32_default() for DT parsing Peng Fan (OSS)
@ 2026-01-19 2:02 ` Peng Fan (OSS)
4 siblings, 0 replies; 8+ messages in thread
From: Peng Fan (OSS) @ 2026-01-19 2:02 UTC (permalink / raw)
To: Rob Herring, Saravana Kannan, Liam Girdwood, Mark Brown,
Alexis Czezar Torreno
Cc: devicetree, linux-kernel, Peng Fan
From: Peng Fan <peng.fan@nxp.com>
Simplify DT parsing of the optional "fcs,suspend-voltage-selector"
property by using of_property_read_u32_default().
If the property is not specified, default to FAN53555_VSEL_ID_0,
which matches the existing behaviour where the field was zeroed
by devm_kzalloc().
Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
drivers/regulator/fan53555.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/drivers/regulator/fan53555.c b/drivers/regulator/fan53555.c
index c282236959b1803e3cba8f4b9cc15e458f6e8436..2e2b5822fc9ed0399056326d838661cb4752f767 100644
--- a/drivers/regulator/fan53555.c
+++ b/drivers/regulator/fan53555.c
@@ -624,8 +624,6 @@ static struct fan53555_platform_data *fan53555_parse_dt(struct device *dev,
const struct regulator_desc *desc)
{
struct fan53555_platform_data *pdata;
- int ret;
- u32 tmp;
pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
if (!pdata)
@@ -633,10 +631,8 @@ static struct fan53555_platform_data *fan53555_parse_dt(struct device *dev,
pdata->regulator = of_get_regulator_init_data(dev, np, desc);
- ret = of_property_read_u32(np, "fcs,suspend-voltage-selector",
- &tmp);
- if (!ret)
- pdata->sleep_vsel_id = tmp;
+ pdata->sleep_vsel_id = of_property_read_u32_default(np, "fcs,suspend-voltage-selector",
+ FAN53555_VSEL_ID_0);
return pdata;
}
--
2.37.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 1/5] of: Add of_property_read_[u32,s32]_default
2026-01-19 2:02 ` [PATCH 1/5] of: Add of_property_read_[u32,s32]_default Peng Fan (OSS)
@ 2026-01-20 22:21 ` Rob Herring
2026-01-23 6:58 ` Peng Fan
0 siblings, 1 reply; 8+ messages in thread
From: Rob Herring @ 2026-01-20 22:21 UTC (permalink / raw)
To: Peng Fan (OSS)
Cc: Saravana Kannan, Liam Girdwood, Mark Brown, Alexis Czezar Torreno,
devicetree, linux-kernel, Peng Fan
On Mon, Jan 19, 2026 at 10:02:54AM +0800, Peng Fan (OSS) wrote:
> From: Peng Fan <peng.fan@nxp.com>
>
> Introduce new helper functions of_property_read_u32_default() and
> of_property_read_s32_default() to simplify reading optional device tree
> properties with a default value.
>
> A very common pattern in drivers is to provide a default value and let
> of_property_read_*() override it when the property is present, e.g.:
>
> Y = Y_DEFAULT;
> of_property_read_u32(np, "prop", &Y);
This is how defaults were intended to be handled.
>
> or equivalently, checking the return value explicitly:
>
> ret = of_property_read_u32(np, "prop", &val);
> if (ret)
> Y = Y_DEFAULT;
> else
> Y = val;
This is usually only needed if the variable type is different. Probably
the better fix is fix the type difference.
> Both forms express the same intent: the property is optional and a
> well-defined default should be used if it cannot be read.
>
> With the new helper, this can be expressed more directly as:
>
> Y = of_property_read_u32_default(np, "prop", Y_DEFAULT);
>
> The helpers intentionally ignore the error code and return either the
> parsed value or the supplied default. They are meant for optional
> properties only. Callers that need to handle or propagate errors should
> continue using of_property_read_*() directly.
What about u8, u16, etc. and device_property_read_*? I'm really on the
fence whether this is all worth it...
We may also want to do something like of_property_read() implemented
using C11 _Generic(). Not sure if that's worth the churn either. It
would make doing some type checks harder. For example I could extract
all property names from of_property_read_u32() calls and check their
size against the schemas. (I have the first half of that already.) Using
_Generic() would make that harder or impossible.
Rob
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/5] of: Add of_property_read_[u32,s32]_default
2026-01-20 22:21 ` Rob Herring
@ 2026-01-23 6:58 ` Peng Fan
0 siblings, 0 replies; 8+ messages in thread
From: Peng Fan @ 2026-01-23 6:58 UTC (permalink / raw)
To: Rob Herring
Cc: Saravana Kannan, Liam Girdwood, Mark Brown, Alexis Czezar Torreno,
devicetree, linux-kernel, Peng Fan
Hi Rob,
On Tue, Jan 20, 2026 at 04:21:55PM -0600, Rob Herring wrote:
>On Mon, Jan 19, 2026 at 10:02:54AM +0800, Peng Fan (OSS) wrote:
>> From: Peng Fan <peng.fan@nxp.com>
>>
>> Introduce new helper functions of_property_read_u32_default() and
>> of_property_read_s32_default() to simplify reading optional device tree
>> properties with a default value.
>>
>> A very common pattern in drivers is to provide a default value and let
>> of_property_read_*() override it when the property is present, e.g.:
>>
>> Y = Y_DEFAULT;
>> of_property_read_u32(np, "prop", &Y);
>
>This is how defaults were intended to be handled.
>>
>> or equivalently, checking the return value explicitly:
>>
>> ret = of_property_read_u32(np, "prop", &val);
>> if (ret)
>> Y = Y_DEFAULT;
>> else
>> Y = val;
>
>This is usually only needed if the variable type is different. Probably
>the better fix is fix the type difference.
I see. There are a few places that use above style to set default value,
no type conversion.
such as
drivers/clk/socfpga/clk-gate-a10.c:71
drivers/clk/socfpga/clk-periph-a10.c:90
>
>> Both forms express the same intent: the property is optional and a
>> well-defined default should be used if it cannot be read.
>>
>> With the new helper, this can be expressed more directly as:
>>
>> Y = of_property_read_u32_default(np, "prop", Y_DEFAULT);
>>
>> The helpers intentionally ignore the error code and return either the
>> parsed value or the supplied default. They are meant for optional
>> properties only. Callers that need to handle or propagate errors should
>> continue using of_property_read_*() directly.
>
>What about u8, u16, etc. and device_property_read_*? I'm really on the
>fence whether this is all worth it...
My cocci only reports some u32 usage using style "if.. else..".
Let me write a cocci pattern to scan device_property_read_* usage.
>
>We may also want to do something like of_property_read() implemented
>using C11 _Generic(). Not sure if that's worth the churn either. It
>would make doing some type checks harder. For example I could extract
>all property names from of_property_read_u32() calls and check their
>size against the schemas. (I have the first half of that already.) Using
>_Generic() would make that harder or impossible.
I see. _Generic may not be a good idea if it makes type checks harder.
Thanks
Peng
>
>Rob
>
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-01-23 6:58 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-19 2:02 [PATCH 0/5] of: Introduce *_read_*_default helpers and convert regulator drivers Peng Fan (OSS)
2026-01-19 2:02 ` [PATCH 1/5] of: Add of_property_read_[u32,s32]_default Peng Fan (OSS)
2026-01-20 22:21 ` Rob Herring
2026-01-23 6:58 ` Peng Fan
2026-01-19 2:02 ` [PATCH 2/5] regulator: of: Use of_property_read_u32_default() Peng Fan (OSS)
2026-01-19 2:02 ` [PATCH 3/5] regulator: adp5055: use of_property_read_[u32|s32]_default() Peng Fan (OSS)
2026-01-19 2:02 ` [PATCH 4/5] regulator: max77620: Use of_property_read_u32_default() for DT parsing Peng Fan (OSS)
2026-01-19 2:02 ` [PATCH 5/5] regulator: fan53555: " Peng Fan (OSS)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox