LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] ASoC: rt5682: Properly turn off regulators if wrong device ID
@ 2021-08-10 23:59 Douglas Anderson
  2021-08-11  4:24 ` Stephen Boyd
  2021-08-12 12:06 ` Mark Brown
  0 siblings, 2 replies; 6+ messages in thread
From: Douglas Anderson @ 2021-08-10 23:59 UTC (permalink / raw)
  To: Oder Chiou, Mark Brown
  Cc: Douglas Anderson, Bard Liao, Jaroslav Kysela, Liam Girdwood,
	Stephen Boyd, Takashi Iwai, alsa-devel, linux-kernel

When I booted up on a board that had a slightly different codec
stuffed on it, I got this message at bootup:

  rt5682 9-001a: Device with ID register 6749 is not rt5682

That's normal/expected, but what wasn't normal was the splat that I
got after:

  WARNING: CPU: 7 PID: 176 at drivers/regulator/core.c:2151 _regulator_put+0x150/0x158
  pc : _regulator_put+0x150/0x158
  ...
  Call trace:
   _regulator_put+0x150/0x158
   regulator_bulk_free+0x48/0x70
   devm_regulator_bulk_release+0x20/0x2c
   release_nodes+0x1cc/0x244
   devres_release_all+0x44/0x60
   really_probe+0x17c/0x378
   ...

This is because the error paths don't turn off the regulator. Let's
fix that.

Fixes: 0ddce71c21f0 ("ASoC: rt5682: add rt5682 codec driver")
Fixes: 87b42abae99d ("ASoC: rt5682: Implement remove callback")
Signed-off-by: Douglas Anderson <dianders@chromium.org>
---

 sound/soc/codecs/rt5682-i2c.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/sound/soc/codecs/rt5682-i2c.c b/sound/soc/codecs/rt5682-i2c.c
index 4a56a52adab5..1cc07812b5ac 100644
--- a/sound/soc/codecs/rt5682-i2c.c
+++ b/sound/soc/codecs/rt5682-i2c.c
@@ -117,6 +117,13 @@ static struct snd_soc_dai_driver rt5682_dai[] = {
 	},
 };
 
+static void rt5682_i2c_disable_regulators(void *data)
+{
+	struct rt5682_priv *rt5682 = data;
+
+	regulator_bulk_disable(ARRAY_SIZE(rt5682->supplies), rt5682->supplies);
+}
+
 static int rt5682_i2c_probe(struct i2c_client *i2c,
 		const struct i2c_device_id *id)
 {
@@ -156,6 +163,10 @@ static int rt5682_i2c_probe(struct i2c_client *i2c,
 		dev_err(&i2c->dev, "Failed to request supplies: %d\n", ret);
 		return ret;
 	}
+	ret = devm_add_action_or_reset(&i2c->dev, rt5682_i2c_disable_regulators,
+				       rt5682);
+	if (ret)
+		return ret;
 
 	ret = regulator_bulk_enable(ARRAY_SIZE(rt5682->supplies),
 				    rt5682->supplies);
@@ -285,7 +296,6 @@ static int rt5682_i2c_remove(struct i2c_client *client)
 	struct rt5682_priv *rt5682 = i2c_get_clientdata(client);
 
 	rt5682_i2c_shutdown(client);
-	regulator_bulk_disable(ARRAY_SIZE(rt5682->supplies), rt5682->supplies);
 
 	return 0;
 }
-- 
2.32.0.605.g8dce9f2422-goog


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

* Re: [PATCH] ASoC: rt5682: Properly turn off regulators if wrong device ID
  2021-08-10 23:59 [PATCH] ASoC: rt5682: Properly turn off regulators if wrong device ID Douglas Anderson
@ 2021-08-11  4:24 ` Stephen Boyd
  2021-08-11 14:40   ` Doug Anderson
  2021-08-12 12:06 ` Mark Brown
  1 sibling, 1 reply; 6+ messages in thread
From: Stephen Boyd @ 2021-08-11  4:24 UTC (permalink / raw)
  To: Douglas Anderson, Mark Brown, Oder Chiou
  Cc: Bard Liao, Jaroslav Kysela, Liam Girdwood, Takashi Iwai,
	alsa-devel, linux-kernel

Quoting Douglas Anderson (2021-08-10 16:59:15)
> When I booted up on a board that had a slightly different codec
> stuffed on it, I got this message at bootup:
>
>   rt5682 9-001a: Device with ID register 6749 is not rt5682
>
> That's normal/expected, but what wasn't normal was the splat that I
> got after:
>
>   WARNING: CPU: 7 PID: 176 at drivers/regulator/core.c:2151 _regulator_put+0x150/0x158
>   pc : _regulator_put+0x150/0x158
>   ...
>   Call trace:
>    _regulator_put+0x150/0x158
>    regulator_bulk_free+0x48/0x70
>    devm_regulator_bulk_release+0x20/0x2c
>    release_nodes+0x1cc/0x244
>    devres_release_all+0x44/0x60
>    really_probe+0x17c/0x378
>    ...
>
> This is because the error paths don't turn off the regulator. Let's
> fix that.
>
> Fixes: 0ddce71c21f0 ("ASoC: rt5682: add rt5682 codec driver")
> Fixes: 87b42abae99d ("ASoC: rt5682: Implement remove callback")
> Signed-off-by: Douglas Anderson <dianders@chromium.org>
> ---

Reviewed-by: Stephen Boyd <swboyd@chromium.org>

>
>  sound/soc/codecs/rt5682-i2c.c | 12 +++++++++++-
>  1 file changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/sound/soc/codecs/rt5682-i2c.c b/sound/soc/codecs/rt5682-i2c.c
> index 4a56a52adab5..1cc07812b5ac 100644
> --- a/sound/soc/codecs/rt5682-i2c.c
> +++ b/sound/soc/codecs/rt5682-i2c.c
> @@ -117,6 +117,13 @@ static struct snd_soc_dai_driver rt5682_dai[] = {
>         },
>  };
>
> +static void rt5682_i2c_disable_regulators(void *data)
> +{
> +       struct rt5682_priv *rt5682 = data;
> +
> +       regulator_bulk_disable(ARRAY_SIZE(rt5682->supplies), rt5682->supplies);
> +}
> +
>  static int rt5682_i2c_probe(struct i2c_client *i2c,
>                 const struct i2c_device_id *id)
>  {
> @@ -156,6 +163,10 @@ static int rt5682_i2c_probe(struct i2c_client *i2c,
>                 dev_err(&i2c->dev, "Failed to request supplies: %d\n", ret);
>                 return ret;
>         }

Nit: Add newline here.

> +       ret = devm_add_action_or_reset(&i2c->dev, rt5682_i2c_disable_regulators,
> +                                      rt5682);
> +       if (ret)
> +               return ret;
>
>         ret = regulator_bulk_enable(ARRAY_SIZE(rt5682->supplies),
>                                     rt5682->supplies);
> @@ -285,7 +296,6 @@ static int rt5682_i2c_remove(struct i2c_client *client)
>         struct rt5682_priv *rt5682 = i2c_get_clientdata(client);
>
>         rt5682_i2c_shutdown(client);
> -       regulator_bulk_disable(ARRAY_SIZE(rt5682->supplies), rt5682->supplies);
>
>         return 0;
>  }

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

* Re: [PATCH] ASoC: rt5682: Properly turn off regulators if wrong device ID
  2021-08-11  4:24 ` Stephen Boyd
@ 2021-08-11 14:40   ` Doug Anderson
  2021-08-11 15:03     ` Mark Brown
  0 siblings, 1 reply; 6+ messages in thread
From: Doug Anderson @ 2021-08-11 14:40 UTC (permalink / raw)
  To: Stephen Boyd
  Cc: Mark Brown, Oder Chiou, Bard Liao, Jaroslav Kysela,
	Liam Girdwood, Takashi Iwai, ALSA Development Mailing List, LKML

Hi,

On Tue, Aug 10, 2021 at 9:24 PM Stephen Boyd <swboyd@chromium.org> wrote:
>
> > @@ -156,6 +163,10 @@ static int rt5682_i2c_probe(struct i2c_client *i2c,
> >                 dev_err(&i2c->dev, "Failed to request supplies: %d\n", ret);
> >                 return ret;
> >         }
>
> Nit: Add newline here.

How strongly do you feel about it? I purposely left the newline off to
try to tie the devm_add_action_or_reset() more closely to the
devm_regulator_bulk_get(). I wanted to make it more obvious that the
two of them were "together" and shouldn't be split up. That being
said, it's no skin off my teeth to add a newline if everyone likes it
better. ;-)

> > +       ret = devm_add_action_or_reset(&i2c->dev, rt5682_i2c_disable_regulators,
> > +                                      rt5682);
> > +       if (ret)
> > +               return ret;

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

* Re: [PATCH] ASoC: rt5682: Properly turn off regulators if wrong device ID
  2021-08-11 14:40   ` Doug Anderson
@ 2021-08-11 15:03     ` Mark Brown
  2021-08-11 15:19       ` Doug Anderson
  0 siblings, 1 reply; 6+ messages in thread
From: Mark Brown @ 2021-08-11 15:03 UTC (permalink / raw)
  To: Doug Anderson
  Cc: Stephen Boyd, Oder Chiou, Bard Liao, Jaroslav Kysela,
	Liam Girdwood, Takashi Iwai, ALSA Development Mailing List, LKML

[-- Attachment #1: Type: text/plain, Size: 601 bytes --]

On Wed, Aug 11, 2021 at 07:40:59AM -0700, Doug Anderson wrote:
> On Tue, Aug 10, 2021 at 9:24 PM Stephen Boyd <swboyd@chromium.org> wrote:

> > Nit: Add newline here.

> How strongly do you feel about it? I purposely left the newline off to
> try to tie the devm_add_action_or_reset() more closely to the
> devm_regulator_bulk_get(). I wanted to make it more obvious that the
> two of them were "together" and shouldn't be split up. That being
> said, it's no skin off my teeth to add a newline if everyone likes it
> better. ;-)

TBH the newline looks off before I've got as far as reading the code.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH] ASoC: rt5682: Properly turn off regulators if wrong device ID
  2021-08-11 15:03     ` Mark Brown
@ 2021-08-11 15:19       ` Doug Anderson
  0 siblings, 0 replies; 6+ messages in thread
From: Doug Anderson @ 2021-08-11 15:19 UTC (permalink / raw)
  To: Mark Brown
  Cc: Stephen Boyd, Oder Chiou, Bard Liao, Jaroslav Kysela,
	Liam Girdwood, Takashi Iwai, ALSA Development Mailing List, LKML

Hi,

On Wed, Aug 11, 2021 at 8:04 AM Mark Brown <broonie@kernel.org> wrote:
>
> On Wed, Aug 11, 2021 at 07:40:59AM -0700, Doug Anderson wrote:
> > On Tue, Aug 10, 2021 at 9:24 PM Stephen Boyd <swboyd@chromium.org> wrote:
>
> > > Nit: Add newline here.
>
> > How strongly do you feel about it? I purposely left the newline off to
> > try to tie the devm_add_action_or_reset() more closely to the
> > devm_regulator_bulk_get(). I wanted to make it more obvious that the
> > two of them were "together" and shouldn't be split up. That being
> > said, it's no skin off my teeth to add a newline if everyone likes it
> > better. ;-)
>
> TBH the newline looks off before I've got as far as reading the code.

Fair 'nuff. v2 is posted with the blank line.

https://lore.kernel.org/r/20210811081751.v2.1.I4a1d9aa5d99e05aeee15c2768db600158d76cab8@changeid/

-Doug

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

* Re: [PATCH] ASoC: rt5682: Properly turn off regulators if wrong device ID
  2021-08-10 23:59 [PATCH] ASoC: rt5682: Properly turn off regulators if wrong device ID Douglas Anderson
  2021-08-11  4:24 ` Stephen Boyd
@ 2021-08-12 12:06 ` Mark Brown
  1 sibling, 0 replies; 6+ messages in thread
From: Mark Brown @ 2021-08-12 12:06 UTC (permalink / raw)
  To: Oder Chiou, Douglas Anderson
  Cc: Mark Brown, alsa-devel, Stephen Boyd, Jaroslav Kysela,
	Takashi Iwai, Liam Girdwood, Bard Liao, linux-kernel

On Tue, 10 Aug 2021 16:59:15 -0700, Douglas Anderson wrote:
> When I booted up on a board that had a slightly different codec
> stuffed on it, I got this message at bootup:
> 
>   rt5682 9-001a: Device with ID register 6749 is not rt5682
> 
> That's normal/expected, but what wasn't normal was the splat that I
> got after:
> 
> [...]

Applied to

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

Thanks!

[1/1] ASoC: rt5682: Properly turn off regulators if wrong device ID
      commit: 772d44526e203c062171786e514373f129616278

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] 6+ messages in thread

end of thread, other threads:[~2021-08-12 12:07 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-10 23:59 [PATCH] ASoC: rt5682: Properly turn off regulators if wrong device ID Douglas Anderson
2021-08-11  4:24 ` Stephen Boyd
2021-08-11 14:40   ` Doug Anderson
2021-08-11 15:03     ` Mark Brown
2021-08-11 15:19       ` Doug Anderson
2021-08-12 12:06 ` Mark Brown

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