Message ID | 20240703-of_property_for_each_u32-v1-20-42c1fc0b82aa@bootlin.com (mailing list archive) |
---|---|
State | Handled Elsewhere |
Headers | show |
Series | Simplify of_property_for_each_u32() | expand |
On Wed, Jul 03, 2024 at 12:37:04PM +0200, Luca Ceresoli wrote: > of_property_for_each_u32() is meant to disappear. All the call sites not > using the 3rd and 4th arguments have already been replaced by > of_property_for_each_u32_new(). > > Deprecate the old macro. Also rename it to minimize the number of new > usages and encourage conversion to the of_property_for_each_u32_new() macro > in not(-yet)-upstream code. > > Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com> > > --- > > Notes: > > * The following files have not been build-tested simply because I haven't > managed to have a config that enables them so far: > > drivers/irqchip/irq-pic32-evic.c > drivers/pinctrl/pinctrl-k210.c > > * These have not been converted yet as they are not trivial, and they will > need to use a more specific function that does the lookup they need and > returns the result: > > drivers/clk/clk-si5351.c I would do something like this: sz = of_property_read_variable_u32_array(np, "silabs,pll-source", array, 2, 4); if (sz >= 2) pdata->pll_src[array[0]] = val_to_src(array[1]); if (sz >= 4) pdata->pll_src[array[2]] = val_to_src(array[3]); > drivers/clk/clk.c Wouldn't this work: 8<------------------------------------------------------ diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 8cca52be993f..33a8cc193556 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -5371,6 +5371,7 @@ const char *of_clk_get_parent_name(const struct device_node *np, int index) int rc; int count; struct clk *clk; + bool found = false; rc = of_parse_phandle_with_args(np, "clocks", "#clock-cells", index, &clkspec); @@ -5383,15 +5384,16 @@ const char *of_clk_get_parent_name(const struct device_node *np, int index) /* if there is an indices property, use it to transfer the index * specified into an array offset for the clock-output-names property. */ - of_property_for_each_u32(clkspec.np, "clock-indices", prop, vp, pv) { + of_property_for_each_u32_new(clkspec.np, "clock-indices", pv) { if (index == pv) { index = count; + found = true; break; } count++; } /* We went off the end of 'clock-indices' without finding it */ - if (prop && !vp) + if (of_property_present(clkspec.np, "clock-indices") && !found) return NULL; if (of_property_read_string_index(clkspec.np, "clock-output-names",
Hello Rob, On Wed, 3 Jul 2024 12:01:11 -0600 Rob Herring <robh@kernel.org> wrote: > On Wed, Jul 03, 2024 at 12:37:04PM +0200, Luca Ceresoli wrote: > > of_property_for_each_u32() is meant to disappear. All the call sites not > > using the 3rd and 4th arguments have already been replaced by > > of_property_for_each_u32_new(). > > > > Deprecate the old macro. Also rename it to minimize the number of new > > usages and encourage conversion to the of_property_for_each_u32_new() macro > > in not(-yet)-upstream code. > > > > Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com> > > > > --- > > > > Notes: > > > > * The following files have not been build-tested simply because I haven't > > managed to have a config that enables them so far: > > > > drivers/irqchip/irq-pic32-evic.c > > drivers/pinctrl/pinctrl-k210.c > > > > * These have not been converted yet as they are not trivial, and they will > > need to use a more specific function that does the lookup they need and > > returns the result: > > > > drivers/clk/clk-si5351.c > > I would do something like this: Thanks for the suggestions. I literally did not even try to look at what the code does in these few places, and still haven't, simply due to time availability. But I wanted to get a first series out as soon as possible as it would probably be useful to Peng [0]. Yours will be a good starting point for when I tackle those few remaining usages of the "old" macro. Thanks. [0] https://lore.kernel.org/all/20240628161617.6bc9ca3c@booty/ Luca
diff --git a/.clang-format b/.clang-format index db25cde2651a..a91b9bb39d9b 100644 --- a/.clang-format +++ b/.clang-format @@ -569,8 +569,8 @@ ForEachMacros: - 'nr_node_for_each_safe' - 'of_for_each_phandle' - 'of_property_for_each_string' - - 'of_property_for_each_u32' - 'of_property_for_each_u32_new' + - 'of_property_for_each_u32_old' - 'pci_bus_for_each_resource' - 'pci_dev_for_each_resource' - 'pcl_for_each_chunk' diff --git a/drivers/clk/clk-si5351.c b/drivers/clk/clk-si5351.c index 4ce83c5265b8..ff990b15d616 100644 --- a/drivers/clk/clk-si5351.c +++ b/drivers/clk/clk-si5351.c @@ -1191,7 +1191,7 @@ static int si5351_dt_parse(struct i2c_client *client, * property silabs,pll-source : <num src>, [<..>] * allow to selectively set pll source */ - of_property_for_each_u32(np, "silabs,pll-source", prop, p, num) { + of_property_for_each_u32_old(np, "silabs,pll-source", prop, p, num) { if (num >= 2) { dev_err(&client->dev, "invalid pll %d on pll-source prop\n", num); @@ -1232,7 +1232,7 @@ static int si5351_dt_parse(struct i2c_client *client, pdata->pll_reset[0] = true; pdata->pll_reset[1] = true; - of_property_for_each_u32(np, "silabs,pll-reset-mode", prop, p, num) { + of_property_for_each_u32_old(np, "silabs,pll-reset-mode", prop, p, num) { if (num >= 2) { dev_err(&client->dev, "invalid pll %d on pll-reset-mode prop\n", num); diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 8ea168c00997..aae940c18459 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -5383,7 +5383,7 @@ const char *of_clk_get_parent_name(const struct device_node *np, int index) /* if there is an indices property, use it to transfer the index * specified into an array offset for the clock-output-names property. */ - of_property_for_each_u32(clkspec.np, "clock-indices", prop, vp, pv) { + of_property_for_each_u32_old(clkspec.np, "clock-indices", prop, vp, pv) { if (index == pv) { index = count; break; diff --git a/drivers/irqchip/irq-pic32-evic.c b/drivers/irqchip/irq-pic32-evic.c index 1d9bb28d13e5..d9aec87f8b59 100644 --- a/drivers/irqchip/irq-pic32-evic.c +++ b/drivers/irqchip/irq-pic32-evic.c @@ -196,7 +196,7 @@ static void __init pic32_ext_irq_of_init(struct irq_domain *domain) int i = 0; const char *pname = "microchip,external-irqs"; - of_property_for_each_u32(node, pname, prop, p, hwirq) { + of_property_for_each_u32_old(node, pname, prop, p, hwirq) { if (i >= ARRAY_SIZE(priv->ext_irqs)) { pr_warn("More than %d external irq, skip rest\n", ARRAY_SIZE(priv->ext_irqs)); diff --git a/drivers/pinctrl/pinctrl-k210.c b/drivers/pinctrl/pinctrl-k210.c index b6d1ed9ec9a3..03acca8b01ef 100644 --- a/drivers/pinctrl/pinctrl-k210.c +++ b/drivers/pinctrl/pinctrl-k210.c @@ -797,7 +797,7 @@ static int k210_pinctrl_dt_subnode_to_map(struct pinctrl_dev *pctldev, if (ret < 0) goto exit; - of_property_for_each_u32(np, "pinmux", prop, p, pinmux_group) { + of_property_for_each_u32_old(np, "pinmux", prop, p, pinmux_group) { const char *group_name, *func_name; u32 pin = FIELD_GET(K210_PG_PIN, pinmux_group); u32 func = FIELD_GET(K210_PG_FUNC, pinmux_group); diff --git a/include/linux/of.h b/include/linux/of.h index 756847539384..15c291ab6e71 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -1429,7 +1429,8 @@ static inline int of_property_read_s32(const struct device_node *np, err == 0; \ err = of_phandle_iterator_next(it)) -#define of_property_for_each_u32(np, propname, prop, p, u) \ +/* deprecated - will be removed */ +#define of_property_for_each_u32_old(np, propname, prop, p, u) \ for (prop = of_find_property(np, propname, NULL), \ p = of_prop_next_u32(prop, NULL, &u); \ p; \
of_property_for_each_u32() is meant to disappear. All the call sites not using the 3rd and 4th arguments have already been replaced by of_property_for_each_u32_new(). Deprecate the old macro. Also rename it to minimize the number of new usages and encourage conversion to the of_property_for_each_u32_new() macro in not(-yet)-upstream code. Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com> --- Notes: * The following files have not been build-tested simply because I haven't managed to have a config that enables them so far: drivers/irqchip/irq-pic32-evic.c drivers/pinctrl/pinctrl-k210.c * These have not been converted yet as they are not trivial, and they will need to use a more specific function that does the lookup they need and returns the result: drivers/clk/clk-si5351.c drivers/clk/clk.c --- .clang-format | 2 +- drivers/clk/clk-si5351.c | 4 ++-- drivers/clk/clk.c | 2 +- drivers/irqchip/irq-pic32-evic.c | 2 +- drivers/pinctrl/pinctrl-k210.c | 2 +- include/linux/of.h | 3 ++- 6 files changed, 8 insertions(+), 7 deletions(-)