All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Cc: Linux-ALSA <alsa-devel@alsa-project.org>,
	Mark Brown <broonie@kernel.org>
Subject: Re: [PATCH] ASoC: rsnd: adg: clearly handle clock error / NULL case
Date: Fri, 11 Jun 2021 10:51:51 +0300	[thread overview]
Message-ID: <20210611075151.GC10983@kadam> (raw)
In-Reply-To: <87zgvxs3rj.wl-kuninori.morimoto.gx@renesas.com>

On Fri, Jun 11, 2021 at 08:23:28AM +0900, Kuninori Morimoto wrote:
> 
> From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
> 
> This driver is assuming that all adg->clk[i] is not NULL.
> Because of this prerequisites, for_each_rsnd_clk() is possible to work
> for all clk without checking NULL. In other words, all adg->clk[i]
> should not NULL.
> 
> Some SoC might doesn't have clk_a/b/c/i. devm_clk_get() returns error in
> such case. This driver calls rsnd_adg_null_clk_get() and use null_clk
> instead of NULL in such cases.
> 
> But devm_clk_get() might returns NULL even though such clocks exist, but
> it doesn't mean error (user deliberately chose to disable the feature).
> NULL clk itself is not error from clk point of view, but is error from
> this driver point of view because it is not assuming such case.
> 
> But current code is using IS_ERR() which doesn't care NULL.
> This driver uses IS_ERR_OR_NULL() instead of IS_ERR() for clk check.
> And it uses ERR_CAST() to clarify null_clk error.
> 
> One concern here is that it unconditionally uses null_clk if clk_a/b/c/i
> was error. It is correct if it doesn't exist, but is not correct if it
> returns error even though it exist.
> It needs to check "clock-names" from DT before calling devm_clk_get() to
> handling such case. But let's assume it is overkill so far.
> 
> Link: https://lore.kernel.org/r/YMCmhfQUimHCSH/n@mwanda 
> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
> ---
>  sound/soc/sh/rcar/adg.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/sound/soc/sh/rcar/adg.c b/sound/soc/sh/rcar/adg.c
> index 0ebee1ed06a9..abe9d539709b 100644
> --- a/sound/soc/sh/rcar/adg.c
> +++ b/sound/soc/sh/rcar/adg.c
> @@ -393,7 +393,7 @@ static struct clk *rsnd_adg_create_null_clk(struct rsnd_priv *priv,
>  	clk = clk_register_fixed_rate(dev, name, parent, 0, 0);
>  	if (IS_ERR(clk)) {
>  		dev_err(dev, "create null clk error\n");
> -		return NULL;
> +		return ERR_CAST(clk);
>  	}
>  
>  	return clk;
> @@ -430,9 +430,9 @@ static int rsnd_adg_get_clkin(struct rsnd_priv *priv)
>  	for (i = 0; i < CLKMAX; i++) {
>  		clk = devm_clk_get(dev, clk_name[i]);
>  
> -		if (IS_ERR(clk))
> +		if (IS_ERR_OR_NULL(clk))
>  			clk = rsnd_adg_null_clk_get(priv);
> -		if (IS_ERR(clk))
> +		if (IS_ERR_OR_NULL(clk))

"clk" can't be NULL here, right?  So this should just be:

	if (IS_ERR(clk))

(because when a function returns NULL it shouldn't print an error)

regards,
dan carpenter

  reply	other threads:[~2021-06-11  7:53 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-10 23:23 [PATCH] ASoC: rsnd: adg: clearly handle clock error / NULL case Kuninori Morimoto
2021-06-11  7:51 ` Dan Carpenter [this message]
2021-06-13 22:57   ` Kuninori Morimoto
2021-08-20  4:08 Kuninori Morimoto
2021-08-20 14:39 ` Mark Brown

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=20210611075151.GC10983@kadam \
    --to=dan.carpenter@oracle.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=kuninori.morimoto.gx@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.