From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7DC63C433E2 for ; Tue, 16 Jun 2020 01:25:40 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 566BC20739 for ; Tue, 16 Jun 2020 01:25:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="C+knmco6" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 566BC20739 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 60C3188584; Tue, 16 Jun 2020 01:25:39 +0000 (UTC) Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8DE0E88584 for ; Tue, 16 Jun 2020 01:25:37 +0000 (UTC) Received: from pendragon.ideasonboard.com (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id E7F66F9; Tue, 16 Jun 2020 03:25:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1592270736; bh=mpgOiz0dJcE6LRudGe/+A7SU0GDZWAt++wOuRnv6/Lw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=C+knmco6WVn43nk19qLKFPhnzpsXiLEEaHjdNRs55O2emO5sLDwrAYy93B7Q3+Vbf v/TP53Nbh283NHVaN+NSX0B2Yixi8x1XzqA+/88hs2DARFY/MbWmo46J+el/vhA+BY sWbICgAW7WPjza/Nh1tVtrzjAKUwwhXOF2WXpe8s= Date: Tue, 16 Jun 2020 04:25:13 +0300 From: Laurent Pinchart To: Dmitry Osipenko Subject: Re: [PATCH v7 1/6] of_graph: add of_graph_get_local_port() Message-ID: <20200616012513.GF1629@pendragon.ideasonboard.com> References: <20200614172234.8856-1-digetx@gmail.com> <20200614172234.8856-2-digetx@gmail.com> <20200616012111.GE1629@pendragon.ideasonboard.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200616012111.GE1629@pendragon.ideasonboard.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Sam Ravnborg , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Rob Herring , Thierry Reding , linux-tegra@vger.kernel.org, Frank Rowand Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" On Tue, Jun 16, 2020 at 04:21:12AM +0300, Laurent Pinchart wrote: > Hi Dmitry, > > Thank you for the patch. > > On Sun, Jun 14, 2020 at 08:22:29PM +0300, Dmitry Osipenko wrote: > > In some case, like a DRM display code for example, it's useful to silently > > check whether port node exists at all in a device-tree before proceeding > > with parsing the graph. > > > > This patch adds of_graph_get_local_port() which returns pointer to a local > > port node, or NULL if graph isn't specified in a device-tree for a given > > device node. > > > > Reviewed-by: Rob Herring > > Reviewed-by: Sam Ravnborg > > Signed-off-by: Dmitry Osipenko > > --- > > drivers/of/property.c | 32 +++++++++++++++++++++++--------- > > include/linux/of_graph.h | 7 +++++++ > > 2 files changed, 30 insertions(+), 9 deletions(-) > > > > diff --git a/drivers/of/property.c b/drivers/of/property.c > > index 1f2086f4e7ce..05c5f619b8bb 100644 > > --- a/drivers/of/property.c > > +++ b/drivers/of/property.c > > @@ -608,15 +608,7 @@ struct device_node *of_graph_get_next_endpoint(const struct device_node *parent, > > * parent port node. > > */ > > if (!prev) { > > - struct device_node *node; > > - > > - node = of_get_child_by_name(parent, "ports"); > > - if (node) > > - parent = node; > > - > > - port = of_get_child_by_name(parent, "port"); > > - of_node_put(node); > > - > > + port = of_graph_get_local_port(parent); > > if (!port) { > > pr_err("graph: no port node found in %pOF\n", parent); > > return NULL; > > @@ -765,6 +757,28 @@ struct device_node *of_graph_get_remote_port(const struct device_node *node) > > } > > EXPORT_SYMBOL(of_graph_get_remote_port); > > > > +/** > > + * of_graph_get_local_port() - get local port node > > + * @node: pointer to a local endpoint device_node > > + * > > + * Return: First local port node associated with local endpoint node linked > > + * to @node. Use of_node_put() on it when done. > > + */ > > +struct device_node *of_graph_get_local_port(const struct device_node *node) I forgot to mention that, given that there could be multiple 'port' nodes, this function would be better named of_graph_get_first_local_port(). 'first' here would refer to the nodes order in the device tree, which I believe may not match the port number. For instance, in the following case ports { #address-cells = <1>; #size-cells = <1>; port@1 { reg = <1>; }; port@0 { reg = <0>; }; }; the function would I believe return port@1. It may be a good idea to explain this in the documentation. Depending on how you use this function, if your only use case is to test for the presence of port nodes, it may be best to return a bool and name it of_graph_has_port() or something similar. > > +{ > > + struct device_node *ports, *port; > > + > > + ports = of_get_child_by_name(node, "ports"); > > + if (ports) > > + node = ports; > > + > > + port = of_get_child_by_name(node, "port"); > > + of_node_put(ports); > > + > > + return port; > > The implementation doesn't seem to match the documentation. If node is a > pointer to an endpoint, it should not have any ports child. > > > +} > > +EXPORT_SYMBOL(of_graph_get_local_port); > > + > > int of_graph_get_endpoint_count(const struct device_node *np) > > { > > struct device_node *endpoint; > > diff --git a/include/linux/of_graph.h b/include/linux/of_graph.h > > index 01038a6aade0..1fdeb72c7765 100644 > > --- a/include/linux/of_graph.h > > +++ b/include/linux/of_graph.h > > @@ -54,6 +54,7 @@ struct device_node *of_graph_get_remote_port_parent( > > struct device_node *of_graph_get_remote_port(const struct device_node *node); > > struct device_node *of_graph_get_remote_node(const struct device_node *node, > > u32 port, u32 endpoint); > > +struct device_node *of_graph_get_local_port(const struct device_node *node); > > #else > > > > static inline int of_graph_parse_endpoint(const struct device_node *node, > > @@ -116,6 +117,12 @@ static inline struct device_node *of_graph_get_remote_node( > > return NULL; > > } > > > > +static inline struct device_node *of_graph_get_local_port( > > + const struct device_node *node) > > +{ > > + return NULL; > > +} > > + > > #endif /* CONFIG_OF */ > > > > #endif /* __LINUX_OF_GRAPH_H */ -- Regards, Laurent Pinchart _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel