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.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,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 3F3A9C433E2 for ; Tue, 16 Jun 2020 01:21:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2123C206B7 for ; Tue, 16 Jun 2020 01:21:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="oqBp/vmv" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726695AbgFPBVi (ORCPT ); Mon, 15 Jun 2020 21:21:38 -0400 Received: from perceval.ideasonboard.com ([213.167.242.64]:39142 "EHLO perceval.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726492AbgFPBVh (ORCPT ); Mon, 15 Jun 2020 21:21:37 -0400 Received: from pendragon.ideasonboard.com (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 9A07EF9; Tue, 16 Jun 2020 03:21:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1592270493; bh=aU7Ie58MknMsKT63S1TAPowl2F0d9L67fIBN7nnNeCU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=oqBp/vmvjePb+UU+aL9IUh9VMoMIgzFHAKicc4Y8Rtms2g7h6hai8Qx1MkBekOApM qz9wVCBn79JofxFEQ7hK2q/0lGteR+LCQA4SZ+fXEBzGHsIfMi8OquHLfWGNBsu3TX DfgIr2MEOeyP3Dt+Qtqp4chPxPmKNobuFNKH1B9w= Date: Tue, 16 Jun 2020 04:21:11 +0300 From: Laurent Pinchart To: Dmitry Osipenko Cc: Thierry Reding , Sam Ravnborg , Rob Herring , Frank Rowand , dri-devel@lists.freedesktop.org, linux-tegra@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v7 1/6] of_graph: add of_graph_get_local_port() Message-ID: <20200616012111.GE1629@pendragon.ideasonboard.com> References: <20200614172234.8856-1-digetx@gmail.com> <20200614172234.8856-2-digetx@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20200614172234.8856-2-digetx@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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) > +{ > + 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 */ > -- > 2.26.0 > -- Regards, Laurent Pinchart