[PATCH] pcm: rate - check rate type for using snd_pcm_rate_slave_frames
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 = {
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/aa4f56c3c952269c36464cc0da9d... https://github.com/alsa-project/alsa-lib/commit/39060852d810461dc8cd1464cfb2...
Let me know, if this update does work for you. Thank you for your report.
Jaroslav
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/aa4f56c3c952269c36464cc0da9d...
https://github.com/alsa-project/alsa-lib/commit/39060852d810461dc8cd1464cfb2...
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.
participants (3)
-
Jaroslav Kysela
-
Shengjiu Wang
-
Shengjiu Wang