From patchwork Tue Jul 28 10:43:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Biju Das X-Patchwork-Id: 11688995 X-Patchwork-Delegate: iwamatsu@nigauri.org Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9989114DD for ; Tue, 28 Jul 2020 11:52:28 +0000 (UTC) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6F4A72070B for ; Tue, 28 Jul 2020 11:52:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=lists.cip-project.org header.i=@lists.cip-project.org header.b="bzAfl/xM" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6F4A72070B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=bp.renesas.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=bounce+64572+5037+4520428+8129116@lists.cip-project.org X-Received: by 127.0.0.2 with SMTP id HvvMYY4521763xNup822HxAu; Tue, 28 Jul 2020 04:52:28 -0700 X-Received: from relmlie5.idc.renesas.com (relmlie5.idc.renesas.com [210.160.252.171]) by mx.groups.io with SMTP id smtpd.web10.9634.1595933018234767330 for ; Tue, 28 Jul 2020 03:43:38 -0700 X-IronPort-AV: E=Sophos;i="5.75,406,1589209200"; d="scan'208";a="53245244" X-Received: from unknown (HELO relmlir5.idc.renesas.com) ([10.200.68.151]) by relmlie5.idc.renesas.com with ESMTP; 28 Jul 2020 19:43:37 +0900 X-Received: from localhost.localdomain (unknown [172.29.51.253]) by relmlir5.idc.renesas.com (Postfix) with ESMTP id E639140041B6; Tue, 28 Jul 2020 19:43:35 +0900 (JST) From: Biju Das To: cip-dev@lists.cip-project.org, Nobuhiro Iwamatsu , Pavel Machek Cc: Chris Paterson , Biju Das , Prabhakar Mahadev Lad Subject: [cip-dev] [PATCH 4.4.y-cip 2/9] of: add node name compare helper functions Date: Tue, 28 Jul 2020 11:43:23 +0100 Message-Id: <20200728104330.6182-3-biju.das.jz@bp.renesas.com> In-Reply-To: <20200728104330.6182-1-biju.das.jz@bp.renesas.com> References: <20200728104330.6182-1-biju.das.jz@bp.renesas.com> Precedence: Bulk List-Unsubscribe: Sender: cip-dev@lists.cip-project.org List-Id: Mailing-List: list cip-dev@lists.cip-project.org; contact cip-dev+owner@lists.cip-project.org Delivered-To: mailing list cip-dev@lists.cip-project.org Reply-To: cip-dev@lists.cip-project.org X-Gm-Message-State: AQwOa8Ddjxnm1hOp8Tnj8LrUx4520428AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=lists.cip-project.org; q=dns/txt; s=20140610; t=1595937148; bh=XAQynf/4wfzeakTNC0xYQNXqpXWXfUcKHNDbU1JkP8I=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=bzAfl/xMRyN29UgX6mh8fTu/ibQxHs8vK65UljjMJXVwLFqi4UTRnDSjamzMDgwJZDU 9Wy1+98AHIutua7GMnyYlBghYXAdhV5NZtxsuL7bV/Tw1evHh+3ib9N7+e9pazmFB1kTb fRlj89uxt7v2jVaqFQsOt2reOvr8CBQeUFU= From: Rob Herring commit f42b0e18f2e5cf34f73ef1b6327b49040b307a33 upstream. In preparation to remove device_node.name pointer, add helper functions for node name comparisons which are a common pattern throughout the kernel. Cc: Frank Rowand Signed-off-by: Rob Herring Signed-off-by: Biju Das --- drivers/of/base.c | 22 ++++++++++++++++++++++ include/linux/of.h | 13 +++++++++++++ 2 files changed, 35 insertions(+) diff --git a/drivers/of/base.c b/drivers/of/base.c index 164eb1306661..b02f4b272e5b 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -54,6 +54,28 @@ DEFINE_MUTEX(of_mutex); */ DEFINE_RAW_SPINLOCK(devtree_lock); +bool of_node_name_eq(const struct device_node *np, const char *name) +{ + const char *node_name; + size_t len; + + if (!np) + return false; + + node_name = kbasename(np->full_name); + len = strchrnul(node_name, '@') - node_name; + + return (strlen(name) == len) && (strncmp(node_name, name, len) == 0); +} + +bool of_node_name_prefix(const struct device_node *np, const char *prefix) +{ + if (!np) + return false; + + return strncmp(kbasename(np->full_name), prefix, strlen(prefix)) == 0; +} + int of_n_addr_cells(struct device_node *np) { const __be32 *ip; diff --git a/include/linux/of.h b/include/linux/of.h index a09b9fb8e67d..1bef273a1909 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -231,6 +231,9 @@ static inline unsigned long of_read_ulong(const __be32 *cell, int size) #define OF_IS_DYNAMIC(x) test_bit(OF_DYNAMIC, &x->_flags) #define OF_MARK_DYNAMIC(x) set_bit(OF_DYNAMIC, &x->_flags) +extern bool of_node_name_eq(const struct device_node *np, const char *name); +extern bool of_node_name_prefix(const struct device_node *np, const char *prefix); + static inline const char *of_node_full_name(const struct device_node *np) { return np ? np->full_name : ""; @@ -397,6 +400,16 @@ static inline struct device_node *to_of_node(struct fwnode_handle *fwnode) return NULL; } +static inline bool of_node_name_eq(const struct device_node *np, const char *name) +{ + return false; +} + +static inline bool of_node_name_prefix(const struct device_node *np, const char *prefix) +{ + return false; +} + static inline const char* of_node_full_name(const struct device_node *np) { return "";