From patchwork Thu Aug 30 18:52:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rob Herring \(Arm\)" X-Patchwork-Id: 145565 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp243981ljw; Thu, 30 Aug 2018 11:52:21 -0700 (PDT) X-Google-Smtp-Source: ANB0VdY1N6/kRCUaOKZsHm/NGaVd8WS80TO0Msv7EZ8rcsKuC+Wh4ZXpMmPJGWM8wOIb6TSxO4WN X-Received: by 2002:a63:3dc6:: with SMTP id k189-v6mr5181052pga.191.1535655140913; Thu, 30 Aug 2018 11:52:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535655140; cv=none; d=google.com; s=arc-20160816; b=A6OcPdKZDaNUfqKnfvy0PcE1Gmg95L2jj1haeOcASx7H40BGJPkAIP7nneyKGK/bD1 0AlqH1VF4EoxkbRKtEc2CO5eazX/gmBbYrRyHj4p+8lru7nzJ/6j9Qtiww0YfEIBE9by MUT2hENgVt2wBWEHTrKd8S0LyfEF18phix1KlQR/h719dQAFkcnWXq+qbiI1V0TRGZAA KXkSpWDnL7AMTCyxHvXHVl0iZslLzYdZgDLg9eqFdfHzeUtuueQTSdCCWzzj7JGJYzQH 87wusrKfWY7jpS4NSFLuHRnl37P/V2N376JMGeRYdE78eLNPjzX+SIE49r78Cm//sSO5 CNxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=bU8Ge6+nlZXLJgwhVZ43Qgco2niBTNtZy9BzLIh7PwY=; b=r2DDEZPnypqY87qHjB3gkG8Y5YLhbAnD77zZ+QTN/B4MthuLmD25n6pT7FQV8y4wPf cB3FDw54t6X+uwl8iutEzdJszGX66XSe4GneJMzUf8cO+/tEhNKUCR6qmSP2fstZ+5cG ox6oKdzYz0gtx3XCvSCFwWWflQat64cbAzCED+hAH//oPE6WuRDeVuBoraLdxsU/cCBt 65Q6QvEEl43spUQoHl5zrNIQ06W509FLfldEfBlQzRcNovRmdIAfFb8VLz57jeGvDR5E v7ecff9G7nisMuEfzV2HcMeUn0G4UzAnQLKjtUMki0cw31wW8t5MpAWElcHGQ8WGJx8y ef7A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c17-v6si7611462pgg.628.2018.08.30.11.52.20; Thu, 30 Aug 2018 11:52:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726122AbeH3Wzw (ORCPT + 6 others); Thu, 30 Aug 2018 18:55:52 -0400 Received: from mail-oi0-f66.google.com ([209.85.218.66]:35694 "EHLO mail-oi0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725836AbeH3Wzw (ORCPT ); Thu, 30 Aug 2018 18:55:52 -0400 Received: by mail-oi0-f66.google.com with SMTP id m11-v6so17336554oic.2; Thu, 30 Aug 2018 11:52:18 -0700 (PDT) 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; bh=bU8Ge6+nlZXLJgwhVZ43Qgco2niBTNtZy9BzLIh7PwY=; b=IIgUtZOgXBcxrj56mJJCGn71Ia4HOCN6lFQr52HD+z0dakTqMb8TEYApT8LoJynSd7 Hm6I5Z7PhMievqlhiD8HDhASokMeRUR2H0wMBXLROiHcyDWzphO4fVBurXKFZGrKkmgC e/m0uyHs1Zo0X6EXXfLPG6gbtrLK7uaP8D49v8cXDEs3+vFtPnmUJKMzuE6UcNQT91Qb GjRMcKt0YY/LbZLMEaD3p9dEQIMsQIDVqhFdQvRCBVxha5wnES45OwH+kPlFBVQK1UNB yvlNQqXlaopSGNeDWHklfo2JFdGtjMbUAGQ+ak9EPGqEi2BLxekBWjG9hj5TR1chH4+9 qxvA== X-Gm-Message-State: APzg51DjbpSLmo/xSJUH5RQs9yiPdU+IH9jjqf/eXQrEhdd80aPWDrhM K6vBZ95J4t9H8VTg+ed2g7Z0ZIQ= X-Received: by 2002:aca:d7c1:: with SMTP id o184-v6mr3916517oig.347.1535655138096; Thu, 30 Aug 2018 11:52:18 -0700 (PDT) Received: from xps15.herring.priv (24-155-109-49.dyn.grandenetworks.net. [24.155.109.49]) by smtp.googlemail.com with ESMTPSA id k85-v6sm11763317oiy.2.2018.08.30.11.52.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Aug 2018 11:52:17 -0700 (PDT) From: Rob Herring To: devicetree@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Frank Rowand Subject: [PATCH] of: add node name compare helper functions Date: Thu, 30 Aug 2018 13:52:16 -0500 Message-Id: <20180830185216.20054-1-robh@kernel.org> X-Mailer: git-send-email 2.17.1 Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org 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 --- drivers/of/base.c | 22 ++++++++++++++++++++++ include/linux/of.h | 13 +++++++++++++ 2 files changed, 35 insertions(+) -- 2.17.1 diff --git a/drivers/of/base.c b/drivers/of/base.c index 466e3c8582f0..185bfe077d0a 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) { u32 cells; diff --git a/include/linux/of.h b/include/linux/of.h index 4d25e4f952d9..a40f63a36afa 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -256,6 +256,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 : ""; @@ -561,6 +564,16 @@ static inline struct device_node *to_of_node(const 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 "";