devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Frank Rowand <frowand.list@gmail.com>
To: Rob Herring <robh@kernel.org>, devicetree@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] of: add node name compare helper functions
Date: Tue, 4 Sep 2018 20:20:22 -0700	[thread overview]
Message-ID: <ef6c5e8c-4a73-4035-0dc3-bda9b35fa8cc@gmail.com> (raw)
In-Reply-To: <20180830185216.20054-1-robh@kernel.org>

On 08/30/18 11:52, Rob Herring wrote:
> 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 <frowand.list@gmail.com>
> Signed-off-by: Rob Herring <robh@kernel.org>
> ---
>  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 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)

        of_node_name_prefix_eq() would be more clear and consistent.

of_node_name_prefix() sounds like it would return the prefix of *np.


> +{
> +	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 : "<no-node>";
> @@ -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 "<no-node>";
> 

      reply	other threads:[~2018-09-05  3:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-30 18:52 [PATCH] of: add node name compare helper functions Rob Herring
2018-09-05  3:20 ` Frank Rowand [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ef6c5e8c-4a73-4035-0dc3-bda9b35fa8cc@gmail.com \
    --to=frowand.list@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robh@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).