devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Rob Herring <robh@kernel.org>
To: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Cc: Frank Rowand <frowand.list@gmail.com>,
	Geert Uytterhoeven <geert+renesas@glider.be>,
	Michael Turquette <mturquette@baylibre.com>,
	Stephen Boyd <sboyd@kernel.org>,
	devicetree@vger.kernel.org, linux-clk@vger.kernel.org,
	linux-renesas-soc@vger.kernel.org,
	Aymeric Aillet <aymeric.aillet@iot.bzh>,
	Yusuke Goda <yusuke.goda.sx@renesas.com>
Subject: Re: [PATCH 1/4] of: add __of_device_is_status() and makes more generic status check
Date: Thu, 16 Nov 2023 13:17:14 -0600	[thread overview]
Message-ID: <20231116191714.GA2821275-robh@kernel.org> (raw)
In-Reply-To: <871qcttd8v.wl-kuninori.morimoto.gx@renesas.com>

On Tue, Nov 14, 2023 at 12:00:49AM +0000, Kuninori Morimoto wrote:
> Linux Kernel has __of_device_is_available() / __of_device_is_fail(),
> these are checking if the status was "okay" / "ok" / "fail" / "fail-".
> 
> Add more generic __of_device_is_status() function for these.
> 
> Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
> Tested-by: Yusuke Goda <yusuke.goda.sx@renesas.com>
> ---
>  drivers/of/base.c | 53 ++++++++++++++++++++++++++++-------------------
>  1 file changed, 32 insertions(+), 21 deletions(-)
> 
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index 8d93cb6ea9cd..d67cb650dcd6 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -415,15 +415,8 @@ int of_machine_is_compatible(const char *compat)
>  }
>  EXPORT_SYMBOL(of_machine_is_compatible);
>  
> -/**
> - *  __of_device_is_available - check if a device is available for use
> - *
> - *  @device: Node to check for availability, with locks already held
> - *
> - *  Return: True if the status property is absent or set to "okay" or "ok",
> - *  false otherwise
> - */
> -static bool __of_device_is_available(const struct device_node *device)
> +static bool __of_device_is_status(const struct device_node *device,
> +				  const char * const*strings, bool default_ret)
>  {
>  	const char *status;
>  	int statlen;
> @@ -433,16 +426,41 @@ static bool __of_device_is_available(const struct device_node *device)
>  
>  	status = __of_get_property(device, "status", &statlen);
>  	if (status == NULL)
> -		return true;
> +		return default_ret;
>  
>  	if (statlen > 0) {
> -		if (!strcmp(status, "okay") || !strcmp(status, "ok"))
> -			return true;
> +		while (*strings) {
> +			unsigned int len = strlen(*strings);
> +
> +			if ((*strings)[len - 1] == '-') {
> +				if (!strncmp(status, *strings, len))
> +					return true;
> +			} else {
> +				if (!strcmp(status, *strings))
> +					return true;
> +			}
> +			strings++;
> +		}
>  	}
>  
>  	return false;
>  }
>  
> +/**
> + *  __of_device_is_available - check if a device is available for use
> + *
> + *  @device: Node to check for availability, with locks already held
> + *
> + *  Return: True if the status property is absent or set to "okay" or "ok",
> + *  false otherwise
> + */
> +static bool __of_device_is_available(const struct device_node *device)
> +{
> +	static const char * const ok[] = {"okay", "ok", NULL};
> +
> +	return __of_device_is_status(device, ok, true);

Available is special compared to any other status check. Rather than 
passing a value to return, I would make this:

return __of_device_is_status(device, ok) || !__of_get_property(device, "status", NULL);

Rob

  reply	other threads:[~2023-11-16 19:17 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-13 23:59 [PATCH 0/4] drivers: clk: renesas: enable all clocks which is assinged to non Linux system Kuninori Morimoto
2023-11-14  0:00 ` [PATCH 1/4] of: add __of_device_is_status() and makes more generic status check Kuninori Morimoto
2023-11-16 19:17   ` Rob Herring [this message]
2023-11-14  0:00 ` [PATCH 2/4] of: add __of_get_next_status_child() and makes more generic of_get_next Kuninori Morimoto
2023-11-14  0:01 ` [PATCH 3/4] of: add for_each_reserved_child_of_node() Kuninori Morimoto
2023-11-14  0:01 ` [PATCH 4/4] drivers: clk: renesas: enable all clocks which is assinged to non Linux system Kuninori Morimoto
2023-11-14 13:10   ` kernel test robot
2023-11-16  1:04     ` Kuninori Morimoto
2023-11-16 19:23   ` Rob Herring
2023-11-16 21:08     ` Geert Uytterhoeven
2023-11-27 21:32       ` Stephen Boyd
2023-11-27 23:48         ` Kuninori Morimoto
2023-12-01 22:39           ` Stephen Boyd
2023-12-04  0:26             ` Kuninori Morimoto

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=20231116191714.GA2821275-robh@kernel.org \
    --to=robh@kernel.org \
    --cc=aymeric.aillet@iot.bzh \
    --cc=devicetree@vger.kernel.org \
    --cc=frowand.list@gmail.com \
    --cc=geert+renesas@glider.be \
    --cc=kuninori.morimoto.gx@renesas.com \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=mturquette@baylibre.com \
    --cc=sboyd@kernel.org \
    --cc=yusuke.goda.sx@renesas.com \
    /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).