alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
* [alsa-devel] [PATCH] ASoC: core: only flush inited work during free
@ 2019-11-28  1:13 Curtis Malainey
  2019-11-28  6:39 ` Takashi Iwai
  2019-12-09 18:59 ` [alsa-devel] Applied "ASoC: core: only flush inited work during free" to the asoc tree Mark Brown
  0 siblings, 2 replies; 7+ messages in thread
From: Curtis Malainey @ 2019-11-28  1:13 UTC (permalink / raw)
  To: alsa-devel; +Cc: Curtis Malainey, Mark Brown, Takashi Iwai, Liam Girdwood

There are many paths to soc_free_pcm_runtime which can both have and
have not yet inited the workqueue yet. When we flush the queue when we
have not yet inited the queue we cause warnings to be printed.

An example is soc_cleanup_card_resources which is called by
snd_soc_bind_card which has multiple failure points before and after
soc_link_init -> soc_new_pcm which is where the queue is inited.

Signed-off-by: Curtis Malainey <cujomalainey@chromium.org>
---
 sound/soc/soc-core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 062653ab03a37..3bf702b874a6d 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -419,7 +419,8 @@ static void soc_free_pcm_runtime(struct snd_soc_pcm_runtime *rtd)
 
 	list_del(&rtd->list);
 
-	flush_delayed_work(&rtd->delayed_work);
+	if (delayed_work_pending(&rtd->delayed_work))
+		flush_delayed_work(&rtd->delayed_work);
 	snd_soc_pcm_component_free(rtd);
 
 	/*
-- 
2.24.0.393.g34dc348eaf-goog

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

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

* Re: [alsa-devel] [PATCH] ASoC: core: only flush inited work during free
  2019-11-28  1:13 [alsa-devel] [PATCH] ASoC: core: only flush inited work during free Curtis Malainey
@ 2019-11-28  6:39 ` Takashi Iwai
  2019-11-28 13:49   ` Mark Brown
  2019-12-09 18:59 ` [alsa-devel] Applied "ASoC: core: only flush inited work during free" to the asoc tree Mark Brown
  1 sibling, 1 reply; 7+ messages in thread
From: Takashi Iwai @ 2019-11-28  6:39 UTC (permalink / raw)
  To: Curtis Malainey; +Cc: alsa-devel, Mark Brown, Takashi Iwai, Liam Girdwood

On Thu, 28 Nov 2019 02:13:58 +0100,
Curtis Malainey wrote:
> 
> There are many paths to soc_free_pcm_runtime which can both have and
> have not yet inited the workqueue yet. When we flush the queue when we
> have not yet inited the queue we cause warnings to be printed.
> 
> An example is soc_cleanup_card_resources which is called by
> snd_soc_bind_card which has multiple failure points before and after
> soc_link_init -> soc_new_pcm which is where the queue is inited.
> 
> Signed-off-by: Curtis Malainey <cujomalainey@chromium.org>

This patch itself isn't wrong, but there is a generic problem in the
current code in general.  Many fields in snd_soc_pcm_runtime object,
not only delayed_work, are initialized too late where
soc_free_pcm_runtime() may be called beforehand.  For example,
rtd->component_list is initialized after the error path of
rtd->codec_dais kmalloc, although soc_free_pcm_runtime() has a loop
over the link.

That said, at least the things like the linked list head and the work
struct must be initialized right after the allocation before any use
of the object.

For this delayed_work, the situation is a bit complex, though.
Usually the work is set up to point to a fixed function, but in the
case of ASoC, it seems serving for different purposes depending on the
component type.  I guess the cleaner way would be a redirect call
like:

static void rtd_delayed_work(struct work_struct *work)
{
	struct snd_soc_pcm_runtime *rtd =
		container_of(work, struct snd_soc_pcm_runtime, delayed_work.work);
	if (rtd->delayed_work_fn)
		rtd->delayed_work_fn(rtd);
}

static struct snd_soc_pcm_runtime *soc_new_pcm_runtime()
{
	....
	INIT_DELAYED_WORK(&rtd->delayed_work, rtd_delayed_work);
	....
}


thanks,

Takashi
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

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

* Re: [alsa-devel] [PATCH] ASoC: core: only flush inited work during free
  2019-11-28  6:39 ` Takashi Iwai
@ 2019-11-28 13:49   ` Mark Brown
  2019-11-28 16:23     ` Curtis Malainey
  0 siblings, 1 reply; 7+ messages in thread
From: Mark Brown @ 2019-11-28 13:49 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: Liam Girdwood, Curtis Malainey, alsa-devel, Takashi Iwai


[-- Attachment #1.1: Type: text/plain, Size: 387 bytes --]

On Thu, Nov 28, 2019 at 07:39:30AM +0100, Takashi Iwai wrote:

> For this delayed_work, the situation is a bit complex, though.
> Usually the work is set up to point to a fixed function, but in the
> case of ASoC, it seems serving for different purposes depending on the
> component type.  I guess the cleaner way would be a redirect call
> like:

Yes, or just separate fields for each.

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

[-- Attachment #2: Type: text/plain, Size: 161 bytes --]

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

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

* Re: [alsa-devel] [PATCH] ASoC: core: only flush inited work during free
  2019-11-28 13:49   ` Mark Brown
@ 2019-11-28 16:23     ` Curtis Malainey
  2019-11-28 17:28       ` Mark Brown
  0 siblings, 1 reply; 7+ messages in thread
From: Curtis Malainey @ 2019-11-28 16:23 UTC (permalink / raw)
  To: Mark Brown
  Cc: Takashi Iwai, Liam Girdwood, Curtis Malainey, ALSA development,
	Takashi Iwai

On Thu, Nov 28, 2019 at 5:49 AM Mark Brown <broonie@kernel.org> wrote:
>
> On Thu, Nov 28, 2019 at 07:39:30AM +0100, Takashi Iwai wrote:
>
> > For this delayed_work, the situation is a bit complex, though.
> > Usually the work is set up to point to a fixed function, but in the
> > case of ASoC, it seems serving for different purposes depending on the
> > component type.  I guess the cleaner way would be a redirect call
> > like:
>
> Yes, or just separate fields for each.
Sounds good, I will refactor this change and send a new version next
week as US is on holiday rest of this week.
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

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

* Re: [alsa-devel] [PATCH] ASoC: core: only flush inited work during free
  2019-11-28 16:23     ` Curtis Malainey
@ 2019-11-28 17:28       ` Mark Brown
  2019-12-02 22:50         ` Curtis Malainey
  0 siblings, 1 reply; 7+ messages in thread
From: Mark Brown @ 2019-11-28 17:28 UTC (permalink / raw)
  To: Curtis Malainey
  Cc: Takashi Iwai, Liam Girdwood, Curtis Malainey, ALSA development,
	Takashi Iwai


[-- Attachment #1.1: Type: text/plain, Size: 804 bytes --]

On Thu, Nov 28, 2019 at 08:23:21AM -0800, Curtis Malainey wrote:
> On Thu, Nov 28, 2019 at 5:49 AM Mark Brown <broonie@kernel.org> wrote:

> > > For this delayed_work, the situation is a bit complex, though.
> > > Usually the work is set up to point to a fixed function, but in the
> > > case of ASoC, it seems serving for different purposes depending on the
> > > component type.  I guess the cleaner way would be a redirect call
> > > like:

> > Yes, or just separate fields for each.


> Sounds good, I will refactor this change and send a new version next
> week as US is on holiday rest of this week.

I applied the change as-is already since like Takashi says it is an
improvement in itself but obviously doing something more complete and
thorough on top of it would be great if you have the time!

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

[-- Attachment #2: Type: text/plain, Size: 161 bytes --]

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

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

* Re: [alsa-devel] [PATCH] ASoC: core: only flush inited work during free
  2019-11-28 17:28       ` Mark Brown
@ 2019-12-02 22:50         ` Curtis Malainey
  0 siblings, 0 replies; 7+ messages in thread
From: Curtis Malainey @ 2019-12-02 22:50 UTC (permalink / raw)
  To: Mark Brown
  Cc: Takashi Iwai, Liam Girdwood, Curtis Malainey, ALSA development,
	Takashi Iwai

I sent a patch with the proxy function fix in it. I did not include a
revert for this patch as I didn't see it on any of your branches. Let
me know if I missed it and I can send you a revert as well.

Curtis

On Thu, Nov 28, 2019 at 9:28 AM Mark Brown <broonie@kernel.org> wrote:
>
> On Thu, Nov 28, 2019 at 08:23:21AM -0800, Curtis Malainey wrote:
> > On Thu, Nov 28, 2019 at 5:49 AM Mark Brown <broonie@kernel.org> wrote:
>
> > > > For this delayed_work, the situation is a bit complex, though.
> > > > Usually the work is set up to point to a fixed function, but in the
> > > > case of ASoC, it seems serving for different purposes depending on the
> > > > component type.  I guess the cleaner way would be a redirect call
> > > > like:
>
> > > Yes, or just separate fields for each.
>
>
> > Sounds good, I will refactor this change and send a new version next
> > week as US is on holiday rest of this week.
>
> I applied the change as-is already since like Takashi says it is an
> improvement in itself but obviously doing something more complete and
> thorough on top of it would be great if you have the time!
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

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

* [alsa-devel] Applied "ASoC: core: only flush inited work during free" to the asoc tree
  2019-11-28  1:13 [alsa-devel] [PATCH] ASoC: core: only flush inited work during free Curtis Malainey
  2019-11-28  6:39 ` Takashi Iwai
@ 2019-12-09 18:59 ` Mark Brown
  1 sibling, 0 replies; 7+ messages in thread
From: Mark Brown @ 2019-12-09 18:59 UTC (permalink / raw)
  To: Curtis Malainey; +Cc: alsa-devel, Mark Brown, Takashi Iwai, Liam Girdwood

The patch

   ASoC: core: only flush inited work during free

has been applied to the asoc tree at

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

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

From 9c9b65203492927cc4ae419e9601e837ecbd889e Mon Sep 17 00:00:00 2001
From: Curtis Malainey <cujomalainey@chromium.org>
Date: Wed, 27 Nov 2019 17:13:58 -0800
Subject: [PATCH] ASoC: core: only flush inited work during free

There are many paths to soc_free_pcm_runtime which can both have and
have not yet inited the workqueue yet. When we flush the queue when we
have not yet inited the queue we cause warnings to be printed.

An example is soc_cleanup_card_resources which is called by
snd_soc_bind_card which has multiple failure points before and after
soc_link_init -> soc_new_pcm which is where the queue is inited.

Signed-off-by: Curtis Malainey <cujomalainey@chromium.org>
Link: https://lore.kernel.org/r/20191128011358.39234-1-cujomalainey@chromium.org
Signed-off-by: Mark Brown <broonie@kernel.org>
---
 sound/soc/soc-core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 0e2e628302f1..1c84ff1a5bf9 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -419,7 +419,8 @@ static void soc_free_pcm_runtime(struct snd_soc_pcm_runtime *rtd)
 
 	list_del(&rtd->list);
 
-	flush_delayed_work(&rtd->delayed_work);
+	if (delayed_work_pending(&rtd->delayed_work))
+		flush_delayed_work(&rtd->delayed_work);
 	snd_soc_pcm_component_free(rtd);
 
 	/*
-- 
2.20.1

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

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

end of thread, other threads:[~2019-12-09 19:26 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-28  1:13 [alsa-devel] [PATCH] ASoC: core: only flush inited work during free Curtis Malainey
2019-11-28  6:39 ` Takashi Iwai
2019-11-28 13:49   ` Mark Brown
2019-11-28 16:23     ` Curtis Malainey
2019-11-28 17:28       ` Mark Brown
2019-12-02 22:50         ` Curtis Malainey
2019-12-09 18:59 ` [alsa-devel] Applied "ASoC: core: only flush inited work during free" to the asoc tree 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).