All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ASoC: rsnd: adg: clearly handle clock error / NULL case
@ 2021-08-20  4:08 Kuninori Morimoto
  2021-08-20 14:39 ` Mark Brown
  0 siblings, 1 reply; 5+ messages in thread
From: Kuninori Morimoto @ 2021-08-20  4:08 UTC (permalink / raw)
  To: Mark Brown; +Cc: Linux-ALSA


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 | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/sound/soc/sh/rcar/adg.c b/sound/soc/sh/rcar/adg.c
index 0ebee1ed06a9..5f1e72edfee0 100644
--- a/sound/soc/sh/rcar/adg.c
+++ b/sound/soc/sh/rcar/adg.c
@@ -391,9 +391,9 @@ static struct clk *rsnd_adg_create_null_clk(struct rsnd_priv *priv,
 	struct clk *clk;
 
 	clk = clk_register_fixed_rate(dev, name, parent, 0, 0);
-	if (IS_ERR(clk)) {
+	if (IS_ERR_OR_NULL(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))
 			goto err;
 
 		adg->clk[i] = clk;
@@ -582,7 +582,7 @@ static int rsnd_adg_get_clkout(struct rsnd_priv *priv)
 	if (!count) {
 		clk = clk_register_fixed_rate(dev, clkout_name[CLKOUT],
 					      parent_clk_name, 0, req_rate[0]);
-		if (IS_ERR(clk))
+		if (IS_ERR_OR_NULL(clk))
 			goto err;
 
 		adg->clkout[CLKOUT] = clk;
@@ -596,7 +596,7 @@ static int rsnd_adg_get_clkout(struct rsnd_priv *priv)
 			clk = clk_register_fixed_rate(dev, clkout_name[i],
 						      parent_clk_name, 0,
 						      req_rate[0]);
-			if (IS_ERR(clk))
+			if (IS_ERR_OR_NULL(clk))
 				goto err;
 
 			adg->clkout[i] = clk;
-- 
2.25.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] ASoC: rsnd: adg: clearly handle clock error / NULL case
  2021-08-20  4:08 [PATCH] ASoC: rsnd: adg: clearly handle clock error / NULL case Kuninori Morimoto
@ 2021-08-20 14:39 ` Mark Brown
  0 siblings, 0 replies; 5+ messages in thread
From: Mark Brown @ 2021-08-20 14:39 UTC (permalink / raw)
  To: Kuninori Morimoto; +Cc: Linux-ALSA, Mark Brown

On 20 Aug 2021 13:08:26 +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.
> 
> [...]

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/1] ASoC: rsnd: adg: clearly handle clock error / NULL case
      commit: cc64c390b215b404524725a94857d6fb58d9a62a

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] ASoC: rsnd: adg: clearly handle clock error / NULL case
  2021-06-11  7:51 ` Dan Carpenter
@ 2021-06-13 22:57   ` Kuninori Morimoto
  0 siblings, 0 replies; 5+ messages in thread
From: Kuninori Morimoto @ 2021-06-13 22:57 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: Linux-ALSA, Mark Brown


Hi Dan

Thank you for your feedback

> > @@ -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))

clk_register_fixed_rate() might return NULL ?
I'm not sure detail.
It is indicating that "error / NULL are both error on this driver".

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

It is "from clk framework point of view" right ?
This driver doesn't assume "NULL clk" for any case.

Thank you for your help !!

Best regards
---
Kuninori Morimoto

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] ASoC: rsnd: adg: clearly handle clock error / NULL case
  2021-06-10 23:23 Kuninori Morimoto
@ 2021-06-11  7:51 ` Dan Carpenter
  2021-06-13 22:57   ` Kuninori Morimoto
  0 siblings, 1 reply; 5+ messages in thread
From: Dan Carpenter @ 2021-06-11  7:51 UTC (permalink / raw)
  To: Kuninori Morimoto; +Cc: Linux-ALSA, Mark Brown

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] ASoC: rsnd: adg: clearly handle clock error / NULL case
@ 2021-06-10 23:23 Kuninori Morimoto
  2021-06-11  7:51 ` Dan Carpenter
  0 siblings, 1 reply; 5+ messages in thread
From: Kuninori Morimoto @ 2021-06-10 23:23 UTC (permalink / raw)
  To: Mark Brown, Dan Carpenter; +Cc: Linux-ALSA


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))
 			goto err;
 
 		adg->clk[i] = clk;
-- 
2.25.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-08-20 14:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-20  4:08 [PATCH] ASoC: rsnd: adg: clearly handle clock error / NULL case Kuninori Morimoto
2021-08-20 14:39 ` Mark Brown
  -- strict thread matches above, loose matches on Subject: below --
2021-06-10 23:23 Kuninori Morimoto
2021-06-11  7:51 ` Dan Carpenter
2021-06-13 22:57   ` Kuninori Morimoto

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.