Skip to contentSkip to conversation

bug in soc_pcm_open

ASoC Matthieu CASTET 4 participants 5 messages Jun 11, 2007 – Jun 12, 2007

lore
Share & tools
lore
#0 lore raw

Hi,

it seems there is a bug in soc_pcm_open. In some case [1] we are in a error path, but we don't set the ret return value.

This cause bug/crash from alsa core.

Thanks

Matthieu

[1]http://hg-mirror.alsa-project.org/alsa-kernel/file/38926de0e79c/soc/soc-core.c if (!runtime->hw.rates) {

      218 		printk(KERN_ERR "asoc: %s <-> %s No matching rates\n",

      219 			codec_dai->name, cpu_dai->name);

      220 		goto machine_err;

      221 	}

      222 	if (!runtime->hw.formats) {

      223 		printk(KERN_ERR "asoc: %s <-> %s No matching formats\n",

      224 			codec_dai->name, cpu_dai->name);

      225 		goto machine_err;

      226 	}

      227 	if (!runtime->hw.channels_min || !runtime->hw.channels_max) {

      228 		printk(KERN_ERR "asoc: %s <-> %s No matching channels\n",

      229 			codec_dai->name, cpu_dai->name);

      230 		goto machine_err;

      231 	}
#1 lore raw

Seems like a problem,
Adding to that

if (machine->ops && machine->ops->shutdown)

		machine->ops->shutdown(substream);

if (platform->pcm_ops->close)

		platform->pcm_ops->close(substream);

if (cpu_dai->ops.shutdown)

		cpu_dai->ops.shutdown(substream);

if it is a error condition then above functions are called twice (also in snd_codec_close())

Nobin Mathew

Quoted 50 lines · Matthieu CASTET

Hi,

it seems there is a bug in soc_pcm_open. In some case [1] we are in a error path, but we don't set the ret return value.

This cause bug/crash from alsa core.

Thanks

Matthieu

[1]http://hg-mirror.alsa-project.org/alsa-kernel/file/38926de0e79c/soc/soc-core.c if (!runtime->hw.rates) {

     218               printk(KERN_ERR "asoc: %s <-> %s No matching rates\n",

     219                       codec_dai->name, cpu_dai->name);

     220               goto machine_err;

     221       }

     222       if (!runtime->hw.formats) {

     223               printk(KERN_ERR "asoc: %s <-> %s No matching formats\n",

     224                       codec_dai->name, cpu_dai->name);

     225               goto machine_err;

     226       }

     227       if (!runtime->hw.channels_min || !runtime->hw.channels_max) {

     228               printk(KERN_ERR "asoc: %s <-> %s No matching channels\n",

     229                       codec_dai->name, cpu_dai->name);

     230               goto machine_err;

     231       }

_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#2 lore raw

Same will cause problems in ALSA also, because nobody is checking whether channel_min/max is zero; it is used in pcm_native.c

http://mailman.alsa-project.org/pipermail/alsa-devel/2007-June/001400.html

Quoted 70 lines · Nobin Mathew

Seems like a problem,
Adding to that

if (machine->ops && machine->ops->shutdown)

                machine->ops->shutdown(substream);

if (platform->pcm_ops->close)

                platform->pcm_ops->close(substream);

if (cpu_dai->ops.shutdown)

                cpu_dai->ops.shutdown(substream);

if it is a error condition then above functions are called twice (also in snd_codec_close())

Nobin Mathew

Quoted 50 lines · Matthieu CASTET

Hi,

it seems there is a bug in soc_pcm_open. In some case [1] we are in a error path, but we don't set the ret return value.

This cause bug/crash from alsa core.

Thanks

Matthieu

[1]http://hg-mirror.alsa-project.org/alsa-kernel/file/38926de0e79c/soc/soc-core.c if (!runtime->hw.rates) {

     218               printk(KERN_ERR "asoc: %s <-> %s No matching rates\n",

     219                       codec_dai->name, cpu_dai->name);

     220               goto machine_err;

     221       }

     222       if (!runtime->hw.formats) {

     223               printk(KERN_ERR "asoc: %s <-> %s No matching formats\n",

     224                       codec_dai->name, cpu_dai->name);

     225               goto machine_err;

     226       }

     227       if (!runtime->hw.channels_min || !runtime->hw.channels_max) {

     228               printk(KERN_ERR "asoc: %s <-> %s No matching channels\n",

     229                       codec_dai->name, cpu_dai->name);

     230               goto machine_err;

     231       }

_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#3 lore raw

At Tue, 12 Jun 2007 11:21:47 +0530,

Quoted 5 lines · Nobin Mathew

Same will cause problems in ALSA also, because nobody is checking whether channel_min/max is zero; it is used in pcm_native.c

http://mailman.alsa-project.org/pipermail/alsa-devel/2007-June/001400.html

Yes, ALSA core layer assumes that the driver shall pass the correct value. Does the patch like below fix the problem?

(BTW, it'd be aprreciated if you can avoid top-citation...)

Takashi

soc/soc-core.c +1 -0
diff -r 640ed49a540d soc/soc-core.c
@@ -213,6 +213,7 @@ static int soc_pcm_open(struct snd_pcm_s
 			codec_dai->capture.rates & cpu_dai->capture.rates;
 	}
 
+	ret = -EINVAL; /* passed to machine_err */
 	snd_pcm_limit_hw_rates(runtime);
 	if (!runtime->hw.rates) {
 		printk(KERN_ERR "asoc: %s <-> %s No matching rates\n",
#4 lore raw
In reply to Nobin Mathew
Quoted 21 lines · Nobin Mathew

Same will cause problems in ALSA also, because nobody is checking whether channel_min/max is zero; it is used in pcm_native.c

http://mailman.alsa-project.org/pipermail/alsa-devel/2007-June/001400.html

Quoted 14 lines · Nobin Mathew

Seems like a problem,
Adding to that

if (machine->ops && machine->ops->shutdown)

                machine->ops->shutdown(substream);

if (platform->pcm_ops->close)

                platform->pcm_ops->close(substream);

if (cpu_dai->ops.shutdown)

                cpu_dai->ops.shutdown(substream);

if it is a error condition then above functions are called twice (also in snd_codec_close())

They should only be called once (in open()) as close() should only be called after the device has successfully opened.

Fwiw, I placed some debug in close just to make sure nothing in the upper layers was calling close when open failed. Everything seems to work as expected.

Liam