diff mbox series

[v2] of: base: Add of_get_available_child_by_name()

Message ID 20250201093126.7322-1-biju.das.jz@bp.renesas.com (mailing list archive)
State New
Delegated to: Geert Uytterhoeven
Headers show
Series [v2] of: base: Add of_get_available_child_by_name() | expand

Commit Message

Biju Das Feb. 1, 2025, 9:31 a.m. UTC
There are lot of drivers using of_get_child_by_name() followed by
of_device_is_available() to find the available child node 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>
---
v1->v2:
 * Updated commit description.
 * Updated kerneldoc comment block
 * Avoided code duplication by using of_get_child_by_name().

Note:
grep showed the below files will be the users 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  | 27 +++++++++++++++++++++++++++
 include/linux/of.h |  9 +++++++++
 2 files changed, 36 insertions(+)

Comments

Rob Herring (Arm) Feb. 3, 2025, 4:52 p.m. UTC | #1
On Sat, Feb 1, 2025 at 3:31 AM 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 find the available child node 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>

Reviewed-by: Rob Herring <robh@kernel.org>

> ---
> v1->v2:
>  * Updated commit description.
>  * Updated kerneldoc comment block
>  * Avoided code duplication by using of_get_child_by_name().
>
> Note:
> grep showed the below files will be the users for this new API.
> I will be updating these drivers once this patch is in mainline.

No need to wait. Please convert all the net ones and send this patch with them.

>
> 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
Biju Das Feb. 3, 2025, 5:17 p.m. UTC | #2
Hi Rob,

+Cc relevant subsystems.

> -----Original Message-----
> From: Rob Herring <robh@kernel.org>
> Sent: 03 February 2025 16:53
> Subject: Re: [PATCH v2] of: base: Add of_get_available_child_by_name()
> 
> On Sat, Feb 1, 2025 at 3:31 AM 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 find the available child node 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>
> 
> Reviewed-by: Rob Herring <robh@kernel.org>
> 
> > ---
> > v1->v2:
> >  * Updated commit description.
> >  * Updated kerneldoc comment block
> >  * Avoided code duplication by using of_get_child_by_name().
> >
> > Note:
> > grep showed the below files will be the users for this new API.
> > I will be updating these drivers once this patch is in mainline.
> 
> No need to wait. Please convert all the net ones and send this patch with them.

Thanks for the feedback.

Subsequently, I have send the patches. However, Andrew[1]/Krystoff[2]
mentioned me to wait till this patch appear in -rc , 

Can it be fast tracked to 6.14-rcX?? Otherwise, it needs to wait till 6.15-rc1
and other patches will then appear on 6.16-rc1.


[1] https://lore.kernel.org/all/96fbccd3-fd79-4b2f-8f41-bd0e3fdb2c69@lunn.ch/

[2] https://lore.kernel.org/all/7fe9dad9-85e2-4cf0-98bc-cca20ff62df5@kernel.org/


Cheers,
Biju
Rob Herring (Arm) Feb. 3, 2025, 9:05 p.m. UTC | #3
On Mon, Feb 3, 2025 at 11:17 AM Biju Das <biju.das.jz@bp.renesas.com> wrote:
>
> Hi Rob,
>
> +Cc relevant subsystems.
>
> > -----Original Message-----
> > From: Rob Herring <robh@kernel.org>
> > Sent: 03 February 2025 16:53
> > Subject: Re: [PATCH v2] of: base: Add of_get_available_child_by_name()
> >
> > On Sat, Feb 1, 2025 at 3:31 AM 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 find the available child node 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>
> >
> > Reviewed-by: Rob Herring <robh@kernel.org>
> >
> > > ---
> > > v1->v2:
> > >  * Updated commit description.
> > >  * Updated kerneldoc comment block
> > >  * Avoided code duplication by using of_get_child_by_name().
> > >
> > > Note:
> > > grep showed the below files will be the users for this new API.
> > > I will be updating these drivers once this patch is in mainline.
> >
> > No need to wait. Please convert all the net ones and send this patch with them.
>
> Thanks for the feedback.
>
> Subsequently, I have send the patches. However, Andrew[1]/Krystoff[2]
> mentioned me to wait till this patch appear in -rc ,
>
> Can it be fast tracked to 6.14-rcX?? Otherwise, it needs to wait till 6.15-rc1
> and other patches will then appear on 6.16-rc1.

Most maintainer trees are based on rc1. So are you sure everyone is
going to be fine with a rc2 dependency? Generally, new APIs don't go
in without a user.

That being said, if this was 10s of different trees I'd reconsider,
but since most of the callers are in net, I'm less willing to apply
"not a fix" to fixes.

> [1] https://lore.kernel.org/all/96fbccd3-fd79-4b2f-8f41-bd0e3fdb2c69@lunn.ch/
>
> [2] https://lore.kernel.org/all/7fe9dad9-85e2-4cf0-98bc-cca20ff62df5@kernel.org/

It's not like they are saying to do the opposite of what I said. If
the dependency is not part of your series, then it needs to be in rc1.

Rob
Biju Das Feb. 4, 2025, 8:59 a.m. UTC | #4
Hi Rob,

> -----Original Message-----
> From: Rob Herring <robh@kernel.org>
> Sent: 03 February 2025 21:06
> Subject: Re: [PATCH v2] of: base: Add of_get_available_child_by_name()
> 
> On Mon, Feb 3, 2025 at 11:17 AM Biju Das <biju.das.jz@bp.renesas.com> wrote:
> >
> > Hi Rob,
> >
> > +Cc relevant subsystems.
> >
> > > -----Original Message-----
> > > From: Rob Herring <robh@kernel.org>
> > > Sent: 03 February 2025 16:53
> > > Subject: Re: [PATCH v2] of: base: Add
> > > of_get_available_child_by_name()
> > >
> > > On Sat, Feb 1, 2025 at 3:31 AM 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 find the available child node 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>
> > >
> > > Reviewed-by: Rob Herring <robh@kernel.org>
> > >
> > > > ---
> > > > v1->v2:
> > > >  * Updated commit description.
> > > >  * Updated kerneldoc comment block
> > > >  * Avoided code duplication by using of_get_child_by_name().
> > > >
> > > > Note:
> > > > grep showed the below files will be the users for this new API.
> > > > I will be updating these drivers once this patch is in mainline.
> > >
> > > No need to wait. Please convert all the net ones and send this patch with them.
> >
> > Thanks for the feedback.
> >
> > Subsequently, I have send the patches. However, Andrew[1]/Krystoff[2]
> > mentioned me to wait till this patch appear in -rc ,
> >
> > Can it be fast tracked to 6.14-rcX?? Otherwise, it needs to wait till
> > 6.15-rc1 and other patches will then appear on 6.16-rc1.
> 
> Most maintainer trees are based on rc1. So are you sure everyone is going to be fine with a rc2
> dependency? Generally, new APIs don't go in without a user.


From [1], looks like 'net' rebase on rcX for fixes and 'net-next' rebase on 'net'?

[1]
https://www.kernel.org/doc/Documentation/networking/netdev-FAQ.txt

> 
> That being said, if this was 10s of different trees I'd reconsider, but since most of the callers are
> in net, I'm less willing to apply "not a fix" to fixes.
> 
> > [1]
> > https://lore.kernel.org/all/96fbccd3-fd79-4b2f-8f41-bd0e3fdb2c69@lunn.
> > ch/
> >
> > [2]
> > https://lore.kernel.org/all/7fe9dad9-85e2-4cf0-98bc-cca20ff62df5@kerne
> > l.org/
> 
> It's not like they are saying to do the opposite of what I said. If the dependency is not part of your
> series, then it needs to be in rc1.

OK. As you suggested, since 'net' is the main user of this API, I will send this patch along with other net patches,
to net subsystem as net-next is open now.

Cheers,
Biju
diff mbox series

Patch

diff --git a/drivers/of/base.c b/drivers/of/base.c
index af6c68bbb427..e37b088f1fad 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -824,6 +824,33 @@  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 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 checks the
+ * device's 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;
+
+	child = of_get_child_by_name(node, name);
+	if (child && !of_device_is_available(child)) {
+		of_node_put(child);
+		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)
 {
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)
 {