All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] pcm: rate - check rate type for using snd_pcm_rate_slave_frames
@ 2022-11-07  4:05 Shengjiu Wang
  2022-11-09  8:39 ` Jaroslav Kysela
  0 siblings, 1 reply; 3+ messages in thread
From: Shengjiu Wang @ 2022-11-07  4:05 UTC (permalink / raw)
  To: lgirdwood, broonie, perex, tiwai, alsa-devel; +Cc: shengjiu.wang

With plughw device and mmap case, the plug pcm fast_ops pointer is same
as slave pcm fast_ops, but ops pointer is different, which cause
the "bus error" in snd_pcm_rate_slave_frames.

The test command is
arecord -Dplughw:x -r12000 -c2 -fS16_LE -M temp.wav

This patch is to add pcm type check as commit:
d21e0e01 pcm: plugin - fix avail_min calculation on rate plugin

Fixes: d9dbb57b ("pcm: rate - rewrite the may_wait_for_avail_min callback for the rate plugin")
Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com>
---
 src/pcm/pcm_rate.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/pcm/pcm_rate.c b/src/pcm/pcm_rate.c
index e8815e8b..dc502202 100644
--- a/src/pcm/pcm_rate.c
+++ b/src/pcm/pcm_rate.c
@@ -1304,8 +1304,11 @@ static snd_pcm_uframes_t snd_pcm_rate_slave_frames(snd_pcm_t *pcm, snd_pcm_ufram
 static int snd_pcm_rate_may_wait_for_avail_min(snd_pcm_t *pcm,
 					       snd_pcm_uframes_t avail)
 {
-	return snd_pcm_plugin_may_wait_for_avail_min_conv(pcm, avail,
-							  snd_pcm_rate_slave_frames);
+	if (snd_pcm_type(pcm) == SND_PCM_TYPE_RATE)
+		return snd_pcm_plugin_may_wait_for_avail_min_conv(pcm, avail,
+								  snd_pcm_rate_slave_frames);
+	else
+		return snd_pcm_plugin_may_wait_for_avail_min_conv(pcm, avail, NULL);
 }
 
 static const snd_pcm_fast_ops_t snd_pcm_rate_fast_ops = {
-- 
2.34.1


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

* Re: [PATCH] pcm: rate - check rate type for using snd_pcm_rate_slave_frames
  2022-11-07  4:05 [PATCH] pcm: rate - check rate type for using snd_pcm_rate_slave_frames Shengjiu Wang
@ 2022-11-09  8:39 ` Jaroslav Kysela
  2022-11-09 10:20   ` Shengjiu Wang
  0 siblings, 1 reply; 3+ messages in thread
From: Jaroslav Kysela @ 2022-11-09  8:39 UTC (permalink / raw)
  To: Shengjiu Wang, lgirdwood, broonie, tiwai, alsa-devel; +Cc: shengjiu.wang

On 07. 11. 22 5:05, Shengjiu Wang wrote:
> With plughw device and mmap case, the plug pcm fast_ops pointer is same
> as slave pcm fast_ops, but ops pointer is different, which cause
> the "bus error" in snd_pcm_rate_slave_frames.
> 
> The test command is
> arecord -Dplughw:x -r12000 -c2 -fS16_LE -M temp.wav
> 
> This patch is to add pcm type check as commit:
> d21e0e01 pcm: plugin - fix avail_min calculation on rate plugin
> 
> Fixes: d9dbb57b ("pcm: rate - rewrite the may_wait_for_avail_min callback for the rate plugin")
> Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com>
> ---
>   src/pcm/pcm_rate.c | 7 +++++--
>   1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/src/pcm/pcm_rate.c b/src/pcm/pcm_rate.c
> index e8815e8b..dc502202 100644
> --- a/src/pcm/pcm_rate.c
> +++ b/src/pcm/pcm_rate.c
> @@ -1304,8 +1304,11 @@ static snd_pcm_uframes_t snd_pcm_rate_slave_frames(snd_pcm_t *pcm, snd_pcm_ufram
>   static int snd_pcm_rate_may_wait_for_avail_min(snd_pcm_t *pcm,
>   					       snd_pcm_uframes_t avail)
>   {
> -	return snd_pcm_plugin_may_wait_for_avail_min_conv(pcm, avail,
> -							  snd_pcm_rate_slave_frames);
> +	if (snd_pcm_type(pcm) == SND_PCM_TYPE_RATE)
> +		return snd_pcm_plugin_may_wait_for_avail_min_conv(pcm, avail,
> +								  snd_pcm_rate_slave_frames);
> +	else
> +		return snd_pcm_plugin_may_wait_for_avail_min_conv(pcm, avail, NULL);
>   }
>   
>   static const snd_pcm_fast_ops_t snd_pcm_rate_fast_ops = {

It's not a correct fix. The snd_pcm_t pointer passed to all fast ops functions should be in sync with the callback implementation.

I tried to fix this issue in commits:

https://github.com/alsa-project/alsa-lib/commit/aa4f56c3c952269c36464cc0da9db5a1381648fa
https://github.com/alsa-project/alsa-lib/commit/39060852d810461dc8cd1464cfb2ffe84da42d56

Let me know, if this update does work for you. Thank you for your report.

					Jaroslav

-- 
Jaroslav Kysela <perex@perex.cz>
Linux Sound Maintainer; ALSA Project; Red Hat, Inc.

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

* Re: [PATCH] pcm: rate - check rate type for using snd_pcm_rate_slave_frames
  2022-11-09  8:39 ` Jaroslav Kysela
@ 2022-11-09 10:20   ` Shengjiu Wang
  0 siblings, 0 replies; 3+ messages in thread
From: Shengjiu Wang @ 2022-11-09 10:20 UTC (permalink / raw)
  To: Jaroslav Kysela; +Cc: Shengjiu Wang, broonie, lgirdwood, alsa-devel, tiwai

On Wed, Nov 9, 2022 at 4:39 PM Jaroslav Kysela <perex@perex.cz> wrote:

> On 07. 11. 22 5:05, Shengjiu Wang wrote:
> > With plughw device and mmap case, the plug pcm fast_ops pointer is same
> > as slave pcm fast_ops, but ops pointer is different, which cause
> > the "bus error" in snd_pcm_rate_slave_frames.
> >
> > The test command is
> > arecord -Dplughw:x -r12000 -c2 -fS16_LE -M temp.wav
> >
> > This patch is to add pcm type check as commit:
> > d21e0e01 pcm: plugin - fix avail_min calculation on rate plugin
> >
> > Fixes: d9dbb57b ("pcm: rate - rewrite the may_wait_for_avail_min
> callback for the rate plugin")
> > Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com>
> > ---
> >   src/pcm/pcm_rate.c | 7 +++++--
> >   1 file changed, 5 insertions(+), 2 deletions(-)
> >
> > diff --git a/src/pcm/pcm_rate.c b/src/pcm/pcm_rate.c
> > index e8815e8b..dc502202 100644
> > --- a/src/pcm/pcm_rate.c
> > +++ b/src/pcm/pcm_rate.c
> > @@ -1304,8 +1304,11 @@ static snd_pcm_uframes_t
> snd_pcm_rate_slave_frames(snd_pcm_t *pcm, snd_pcm_ufram
> >   static int snd_pcm_rate_may_wait_for_avail_min(snd_pcm_t *pcm,
> >                                              snd_pcm_uframes_t avail)
> >   {
> > -     return snd_pcm_plugin_may_wait_for_avail_min_conv(pcm, avail,
> > -
>  snd_pcm_rate_slave_frames);
> > +     if (snd_pcm_type(pcm) == SND_PCM_TYPE_RATE)
> > +             return snd_pcm_plugin_may_wait_for_avail_min_conv(pcm,
> avail,
> > +
>  snd_pcm_rate_slave_frames);
> > +     else
> > +             return snd_pcm_plugin_may_wait_for_avail_min_conv(pcm,
> avail, NULL);
> >   }
> >
> >   static const snd_pcm_fast_ops_t snd_pcm_rate_fast_ops = {
>
> It's not a correct fix. The snd_pcm_t pointer passed to all fast ops
> functions should be in sync with the callback implementation.
>
> I tried to fix this issue in commits:
>
>
> https://github.com/alsa-project/alsa-lib/commit/aa4f56c3c952269c36464cc0da9db5a1381648fa
>
> https://github.com/alsa-project/alsa-lib/commit/39060852d810461dc8cd1464cfb2ffe84da42d56
>
> Let me know, if this update does work for you. Thank you for your report.
>
> Thanks for the fix.  The crash is fixed. We will do more tests.

best regards
wang shengjiu


>                                         Jaroslav
>
> --
> Jaroslav Kysela <perex@perex.cz>
> Linux Sound Maintainer; ALSA Project; Red Hat, Inc.
>

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

end of thread, other threads:[~2022-11-09 10:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-07  4:05 [PATCH] pcm: rate - check rate type for using snd_pcm_rate_slave_frames Shengjiu Wang
2022-11-09  8:39 ` Jaroslav Kysela
2022-11-09 10:20   ` Shengjiu Wang

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.