From patchwork Sat Feb 1 09:31:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Biju Das X-Patchwork-Id: 13956144 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 87FA2C0218A for ; Sat, 1 Feb 2025 09:33:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=/y1tCaIJIRMuWtY5X8ScN+Ehwj3HaJvQiyS5r+vb39k=; b=zNYL1hMr7wkPL2WQqGmy0/Y49m xyObZBqJq5vop2IGhMDXeNooMNOpuk7vVuE0Wpm+IwYbnRiReKy//f3aiS1B0tvHHoIcKn4hviHuI wBEdkFti+1kerVYVralo0JLWJxP3dVhWFf2VW27DmFqsSqhlTm5TbT0J9Dn6myB+cKcXtp9f9bPWP Gw1DdoEj1wonrnHnMP91XMoFrk0E4FJUoB1PSi0GORLc10UvPBiSunWY3yjm2fMJQCYRu1zQwR5O6 59JPe/Ggvhdc9ktMtrS08FONSqrPcewtW0ccNAzJRITKZx+PLbkUa7SD0CM1VTkdxlqne6GHuIoQT Hor7KqQw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1te9sG-0000000C5nn-1C20; Sat, 01 Feb 2025 09:33:12 +0000 Received: from relmlor1.renesas.com ([210.160.252.171] helo=relmlie5.idc.renesas.com) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1te9qu-0000000C5lK-0xhu; Sat, 01 Feb 2025 09:31:49 +0000 X-CSE-ConnectionGUID: AkWdZp+FTmOL0FXebDBvzw== X-CSE-MsgGUID: l7gPDljdTleUh2byncMmtA== Received: from unknown (HELO relmlir6.idc.renesas.com) ([10.200.68.152]) by relmlie5.idc.renesas.com with ESMTP; 01 Feb 2025 18:31:43 +0900 Received: from localhost.localdomain (unknown [10.226.92.62]) by relmlir6.idc.renesas.com (Postfix) with ESMTP id 8AC2941D4003; Sat, 1 Feb 2025 18:31:28 +0900 (JST) From: Biju Das To: Rob Herring , Saravana Kannan , Matthias Brugger , AngeloGioacchino Del Regno Cc: Biju Das , devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Geert Uytterhoeven , Prabhakar Mahadev Lad , Biju Das , linux-renesas-soc@vger.kernel.org Subject: [PATCH v2] of: base: Add of_get_available_child_by_name() Date: Sat, 1 Feb 2025 09:31:24 +0000 Message-ID: <20250201093126.7322-1-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250201_013148_372688_73145F51 X-CRM114-Status: GOOD ( 11.70 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org 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 Signed-off-by: Biju Das --- 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(+) 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) {