Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1102579ybt; Sun, 14 Jun 2020 10:25:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzHwDKAJZzA1Bcr5wNFeISUb87OJlXAR0aN94Y5f0jCL+2Gq5RAeMQtY6Ek+fv4NFbsG/1s X-Received: by 2002:a50:9fc2:: with SMTP id c60mr21301643edf.319.1592155541945; Sun, 14 Jun 2020 10:25:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592155541; cv=none; d=google.com; s=arc-20160816; b=fcSPUhUzptHW26TmxLiFdNcfaGQLVY4iDFd4lxGe7LPVaPCKzExpRCy5r6fx+r1QS0 VQNCNB6w7R2+/gsUUukLlgehdhZxl/apQYzoP6IF/W5xwnmuAHdeB8UtXp2cKk5ZPDPx vD3ZbqGGwQaOkEZj0cbWtqnOKRNBaPAxw2ivfKbFOUkYyMvoTS2fj8S5T9m+c3GT0otr Eq0NFsXYBiGnNsoS1Yx2yed6jThzKld/yvsrNXyCZQigC0UgeR3iLEhC+EneZQ+fUcIF wc5ITee1fZAOB6YzQfYfS+zbMMAiamnEO6/vP/zFN1rq+xjegxKj55AC+zUvfU7ZvaN0 ptXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=AU8aHNXSJicC/3mJ6DI0lDrv2zkNv1iB0kltJtsuQAw=; b=cCmn/5UUKaKf4SaRaKfvGLPcx07DAyZZCh5JOG6WYxeK495n+++iHEX0MX8Za0rqNY WwYdEVpXgTdn6OxOTxiVxgLUU/RZ5UikumzumEpFlNbUahF43jNCrjnHcp6JDhO5wHms xuV9TGMh6z2ZwgooGU11wv0OVAhqJqOHOe2MDAU8QOfKObc+5RoDhTPG3/wiDDZ07YRK cCs6Gr9OyRKjf7x83zPGj8aWfFDIsJMLiaS33lz1yAlz50O7o7oyBMSX95jJjHGR4ckb 4j6C4Rx30b5lYGwqhgT/wxC3RrOy3pRVdXvNBshyupPA+aMl3JR2eXxcUOGFYTf96a8j wEzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=EuuwpiMk; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i21si7498662edv.162.2020.06.14.10.25.19; Sun, 14 Jun 2020 10:25:41 -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 header.i=@gmail.com header.s=20161025 header.b=EuuwpiMk; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727807AbgFNRXa (ORCPT + 99 others); Sun, 14 Jun 2020 13:23:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727121AbgFNRXX (ORCPT ); Sun, 14 Jun 2020 13:23:23 -0400 Received: from mail-lf1-x144.google.com (mail-lf1-x144.google.com [IPv6:2a00:1450:4864:20::144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D43EBC03E969; Sun, 14 Jun 2020 10:23:22 -0700 (PDT) Received: by mail-lf1-x144.google.com with SMTP id w15so8133555lfe.11; Sun, 14 Jun 2020 10:23:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AU8aHNXSJicC/3mJ6DI0lDrv2zkNv1iB0kltJtsuQAw=; b=EuuwpiMkbbMKMls8xVM/R+dW4jTSovpLjRK+sPtMRrFMpHoHw/kpM0xivjB5l+3Wu3 XcUOjOxZDNoxCm9oFseCYWGMQ4vKztSVSKaiiekr0ZHPjmq71USjRbt3J8TPe3Km7Gqj 86xW1PapknQ65as28VSKdVfcrouIaRfG8tcHkG1XO8H0q1TQP2ev6QgYkXmf6yzttsN1 3+Qt1QJ4OnQcEEPRzCq/I/qpa7toX5wmOqFyYeMQJA8iqB8HECwkI+b4byv4eW8aSFdx DUVNa2qUVBn5Ue4ihyiX2OKpG5BslNmisbchP8GEm4WR8NFbkSb1bIk8yMxj4seYeMQ+ BnOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AU8aHNXSJicC/3mJ6DI0lDrv2zkNv1iB0kltJtsuQAw=; b=eeBSXGKi3DXR/LZf/FiX1GakNu6yNfWK13KXlMNYSgXGJlX3wx6BGj7+egKmpdOo4B zy6HfjhZr5yqUxVCcr8VA55rm5O5Ip+kTn3vIMcibJz3k2f0NuVxJ2p8N13SQ/ZSAzzU auyIIV3tFY1KR/WxUBrUyskPqCKtikPOOAiFraWoF+Z/DNNyh5oHKN/+Gni8LmNaNmP8 5Yxz+GUzr4Ixb10sCMm0l9nCY6LvxoPl1wM6fDP1NvLAe3cDiB8TgVSRhHOERTfsd3F8 Fyo5JDZdk/lu7zd5dal9zaojMqpTs6hZAkB207Bi/tfC7ikkXjF8mAO5CztyNMe17OXY SAAQ== X-Gm-Message-State: AOAM531OAz+w++6CWcD2fL5qXrQ7j2imWHGJEKoKL9PJHsRbj53VV0eD Ay8HmFuRQyLQIx1TDxeaotU= X-Received: by 2002:a19:356:: with SMTP id 83mr11724834lfd.179.1592155399430; Sun, 14 Jun 2020 10:23:19 -0700 (PDT) Received: from localhost.localdomain (79-139-237-54.dynamic.spd-mgts.ru. [79.139.237.54]) by smtp.gmail.com with ESMTPSA id m14sm55144lfp.18.2020.06.14.10.23.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Jun 2020 10:23:18 -0700 (PDT) From: Dmitry Osipenko To: Thierry Reding , Sam Ravnborg , Laurent Pinchart , Rob Herring , Frank Rowand Cc: dri-devel@lists.freedesktop.org, linux-tegra@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v7 1/6] of_graph: add of_graph_get_local_port() Date: Sun, 14 Jun 2020 20:22:29 +0300 Message-Id: <20200614172234.8856-2-digetx@gmail.com> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200614172234.8856-1-digetx@gmail.com> References: <20200614172234.8856-1-digetx@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; +} +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