Message ID | 20250131094812.118340-1-biju.das.jz@bp.renesas.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | of: base: Add of_get_available_child_by_name() | expand |
Hi Biju, On Fri, 31 Jan 2025 at 10:48, Biju Das <biju.das.jz@bp.renesas.com> wrote: > There are lot of drivers using of_get_child_by_name() followed > by of_device_is_available() to check the child node availabilty > by name for a given parent. Provide a helper for these users to > simplify the code. > > Suggested-by: Geert Uytterhoeven <geert+renesas@glider.be> > Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com> Thanks for your patch! > --- a/drivers/of/base.c > +++ b/drivers/of/base.c > @@ -824,6 +824,34 @@ struct device_node *of_get_child_by_name(const struct device_node *node, > } > EXPORT_SYMBOL(of_get_child_by_name); > > +/** > + * of_get_available_child_by_name - Find the child node availabilty by name for a given parent available child node? > + * @node: parent node > + * @name: child name to look for. > + * > + * This function looks for child node for given matching name and check the checks > + * device availability for use. device's > + * > + * Return: A node pointer if found, with refcount incremented, use > + * of_node_put() on it when done. > + * Returns NULL if node is not found. > + */ > +struct device_node *of_get_available_child_by_name(const struct device_node *node, > + const char *name) > +{ > + struct device_node *child; > + > + for_each_child_of_node(node, child) > + if (of_node_name_eq(child, name)) > + break; child = of_get_child_by_name(node, name); > + > + if (child && !of_device_is_available(child)) > + of_node_put(child); Missing return NULL. > + > + return child; > +} > +EXPORT_SYMBOL(of_get_available_child_by_name); > + > struct device_node *__of_find_node_by_path(const struct device_node *parent, > const char *path) > { Gr{oetje,eeting}s, Geert
Hi Geert, Thanks for the feedback. > -----Original Message----- > From: Geert Uytterhoeven <geert@linux-m68k.org> > Sent: 31 January 2025 09:53 > Subject: Re: [PATCH] of: base: Add of_get_available_child_by_name() > > Hi Biju, > > On Fri, 31 Jan 2025 at 10:48, Biju Das <biju.das.jz@bp.renesas.com> wrote: > > There are lot of drivers using of_get_child_by_name() followed by > > of_device_is_available() to check the child node availabilty by name > > for a given parent. Provide a helper for these users to simplify the > > code. > > > > Suggested-by: Geert Uytterhoeven <geert+renesas@glider.be> > > Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com> > > Thanks for your patch! > > > --- a/drivers/of/base.c > > +++ b/drivers/of/base.c > > @@ -824,6 +824,34 @@ struct device_node *of_get_child_by_name(const > > struct device_node *node, } EXPORT_SYMBOL(of_get_child_by_name); > > > > +/** > > + * of_get_available_child_by_name - Find the child node availabilty > > +by name for a given parent > > available child node? OK, Find the available child node by name for a given parent. > > > + * @node: parent node > > + * @name: child name to look for. > > + * > > + * This function looks for child node for given matching name and > > + check the > > checks OK > > > + * device availability for use. > > device's OK. > > > + * > > + * Return: A node pointer if found, with refcount incremented, use > > + * of_node_put() on it when done. > > + * Returns NULL if node is not found. > > + */ > > +struct device_node *of_get_available_child_by_name(const struct device_node *node, > > + const char *name) { > > + struct device_node *child; > > + > > + for_each_child_of_node(node, child) > > + if (of_node_name_eq(child, name)) > > + break; > > child = of_get_child_by_name(node, name); OK, Will use the above API to avoid duplication. > > > + > > + if (child && !of_device_is_available(child)) > > + of_node_put(child); > > Missing return NULL. OK. Will fix this in next version. Cheers, Biju
diff --git a/drivers/of/base.c b/drivers/of/base.c index af6c68bbb427..3f5119fbfdb4 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -824,6 +824,34 @@ struct device_node *of_get_child_by_name(const struct device_node *node, } EXPORT_SYMBOL(of_get_child_by_name); +/** + * of_get_available_child_by_name - Find the child node availabilty by name for a given parent + * @node: parent node + * @name: child name to look for. + * + * This function looks for child node for given matching name and check the + * device availability for use. + * + * Return: A node pointer if found, with refcount incremented, use + * of_node_put() on it when done. + * Returns NULL if node is not found. + */ +struct device_node *of_get_available_child_by_name(const struct device_node *node, + const char *name) +{ + struct device_node *child; + + for_each_child_of_node(node, child) + if (of_node_name_eq(child, name)) + break; + + if (child && !of_device_is_available(child)) + of_node_put(child); + + return child; +} +EXPORT_SYMBOL(of_get_available_child_by_name); + struct device_node *__of_find_node_by_path(const struct device_node *parent, const char *path) { diff --git a/include/linux/of.h b/include/linux/of.h index eaf0e2a2b75c..9d6b8a61607f 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -301,6 +301,8 @@ extern struct device_node *of_get_compatible_child(const struct device_node *par const char *compatible); extern struct device_node *of_get_child_by_name(const struct device_node *node, const char *name); +extern struct device_node *of_get_available_child_by_name(const struct device_node *node, + const char *name); /* cache lookup */ extern struct device_node *of_find_next_cache_node(const struct device_node *); @@ -578,6 +580,13 @@ static inline struct device_node *of_get_child_by_name( return NULL; } +static inline struct device_node *of_get_available_child_by_name( + const struct device_node *node, + const char *name) +{ + return NULL; +} + static inline int of_device_is_compatible(const struct device_node *device, const char *name) {
There are lot of drivers using of_get_child_by_name() followed by of_device_is_available() to check the child node availabilty by name for a given parent. Provide a helper for these users to simplify the code. Suggested-by: Geert Uytterhoeven <geert+renesas@glider.be> Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com> --- grep showed the below files will be the user for this new API. I will be updating these drivers once this patch is in mainline. drivers/net/dsa/rzn1_a5psw.c drivers/net/can/rcar/rcar_canfd.c drivers/net/ethernet/mediatek/mtk_star_emac.c drivers/net/dsa/mt7530.c drivers/net/dsa/sja1105/sja1105_mdio.c drivers/net/dsa/qca/qca8k-8xxx.c drivers/net/wireless/mediatek/mt76/mac80211.c drivers/net/ethernet/ibm/emac/core.c drivers/net/ethernet/ti/am65-cpsw-nuss.c drivers/net/ethernet/actions/owl-emac.c drivers/net/ethernet/mediatek/mtk_eth_soc.c drivers/media/platform/samsung/exynos4-is/media-dev.h drivers/gpu/drm/tegra/rgb.c drivers/gpu/drm/msm/adreno/adreno_gpu.c drivers/clk/davinci/pll.c --- drivers/of/base.c | 28 ++++++++++++++++++++++++++++ include/linux/of.h | 9 +++++++++ 2 files changed, 37 insertions(+)