Commit cc64c390 authored by Kuninori Morimoto's avatar Kuninori Morimoto Committed by Mark Brown

ASoC: rsnd: adg: clearly handle clock error / NULL case

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@mwandaReported-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: default avatarKuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Link: https://lore.kernel.org/r/87v940wyf9.wl-kuninori.morimoto.gx@renesas.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent 28889de6
...@@ -391,9 +391,9 @@ static struct clk *rsnd_adg_create_null_clk(struct rsnd_priv *priv, ...@@ -391,9 +391,9 @@ static struct clk *rsnd_adg_create_null_clk(struct rsnd_priv *priv,
struct clk *clk; struct clk *clk;
clk = clk_register_fixed_rate(dev, name, parent, 0, 0); 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"); dev_err(dev, "create null clk error\n");
return NULL; return ERR_CAST(clk);
} }
return clk; return clk;
...@@ -430,9 +430,9 @@ static int rsnd_adg_get_clkin(struct rsnd_priv *priv) ...@@ -430,9 +430,9 @@ static int rsnd_adg_get_clkin(struct rsnd_priv *priv)
for (i = 0; i < CLKMAX; i++) { for (i = 0; i < CLKMAX; i++) {
clk = devm_clk_get(dev, clk_name[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); clk = rsnd_adg_null_clk_get(priv);
if (IS_ERR(clk)) if (IS_ERR_OR_NULL(clk))
goto err; goto err;
adg->clk[i] = clk; adg->clk[i] = clk;
...@@ -582,7 +582,7 @@ static int rsnd_adg_get_clkout(struct rsnd_priv *priv) ...@@ -582,7 +582,7 @@ static int rsnd_adg_get_clkout(struct rsnd_priv *priv)
if (!count) { if (!count) {
clk = clk_register_fixed_rate(dev, clkout_name[CLKOUT], clk = clk_register_fixed_rate(dev, clkout_name[CLKOUT],
parent_clk_name, 0, req_rate[0]); parent_clk_name, 0, req_rate[0]);
if (IS_ERR(clk)) if (IS_ERR_OR_NULL(clk))
goto err; goto err;
adg->clkout[CLKOUT] = clk; adg->clkout[CLKOUT] = clk;
...@@ -596,7 +596,7 @@ static int rsnd_adg_get_clkout(struct rsnd_priv *priv) ...@@ -596,7 +596,7 @@ static int rsnd_adg_get_clkout(struct rsnd_priv *priv)
clk = clk_register_fixed_rate(dev, clkout_name[i], clk = clk_register_fixed_rate(dev, clkout_name[i],
parent_clk_name, 0, parent_clk_name, 0,
req_rate[0]); req_rate[0]);
if (IS_ERR(clk)) if (IS_ERR_OR_NULL(clk))
goto err; goto err;
adg->clkout[i] = clk; adg->clkout[i] = clk;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment