Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp2094577ybt; Mon, 15 Jun 2020 18:34:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx12nsr6t8bB/t1lpDA2tUA74KaMP6kET5jcKP6NG9xuGCSL7yvzKF/5oAD9xtrUCEDIsNQ X-Received: by 2002:a50:f983:: with SMTP id q3mr507669edn.259.1592271250567; Mon, 15 Jun 2020 18:34:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592271250; cv=none; d=google.com; s=arc-20160816; b=Q+kMDZueOVpvhRfzcJZvRMXGiGd5az6Z0pHrNOchLjyWAFcWYJF4sK5e54U/eX0Wo6 A38gsIVQG7VNQsYw4+uMqVNquMsNbWCXkDgHQLUBU4lwToLQASF/t6pYsXaQikbDAdDM rDGVGDwys+kaaHypl3W1g1vcqhJ4JHhZblfrdua69pZ6yZWX1WfX6nztOqTHnZmfFcGi /XaV6aAnKNs6euYg+NRlbKHQie4AyaEsMxeX+EIX+FwjV6PNgNMZ9Boykw6AQPg+Lf7l QwJAkj2+Gl/keWWEvd0+oHttcQUZ8Vj1U5rTGQZ60oxobh1f7Zlylko2d62TZIYap4S+ qabw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=8xR5AngTIZatxEVrwr/pgGYdBu7XbfjwANzVkZG9ShA=; b=AAPNlmDniFJFTf2xCf1IpYbjh1VzcSAFHWSd6JOr5mEndbuGgxrs5iy7p9w3IAiJNt BC/iwOtmpZQlHrUOl2aX62hxRZoYKMVyQTciYhVRk3WQpon4Jk65kvH9JbEYEkdMA1fZ 57gXXu/Pu45n4QtMauDfdq3HvJ0MkWK8gETIjEjE3sExAtMWSFYbpc/npKK0O4iVydIR epSSGhw3unwYgH8QXgtcz1FvJUEKxTrqr5yThbZikKOxwllGvzBOCBBeZ7eEQNciBW8M srhfUCBJf95h/EzTFi99vXmYd39A+X7Jk1Vt8fF7ks3AMcZT9DQhYuWKhQk8carkMm1m /9Qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=C+knmco6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bo17si5554625ejb.573.2020.06.15.18.33.45; Mon, 15 Jun 2020 18:34:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=C+knmco6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726863AbgFPBZj (ORCPT + 99 others); Mon, 15 Jun 2020 21:25:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726564AbgFPBZi (ORCPT ); Mon, 15 Jun 2020 21:25:38 -0400 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11F0DC061A0E; Mon, 15 Jun 2020 18:25:38 -0700 (PDT) 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 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: <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-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20200616012111.GE1629@pendragon.ideasonboard.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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