Skip to contentSkip to conversation

ALSA: compress_core: Ensure device is stopped when stream closed

PATCH In review Richard Fitzgerald 3 participants 6 messages Apr 26, 2013 – Apr 29, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ALSA: compress_core: Ensure device is stopped when stream closed

If the stream state is running or paused when device file is closed snd_compr_free() will send a SNDRV_PCM_TRIGGER_STOP to the stream.

---
 sound/core/compress_offload.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
sound/core/compress_offload.c +5 -0
index 91e6bcb..a81c5e4 100644
@@ -132,6 +132,11 @@ static int snd_compr_open(struct inode *inode, struct file *f)
 static int snd_compr_free(struct inode *inode, struct file *f)
 {
 	struct snd_compr_file *data = f->private_data;
+
+	if ((data->stream.runtime->state == SNDRV_PCM_STATE_RUNNING) ||
+	    (data->stream.runtime->state == SNDRV_PCM_STATE_PAUSED))
+		data->stream.ops->trigger(&data->stream, SNDRV_PCM_TRIGGER_STOP);
+
 	data->stream.ops->free(&data->stream);
 	kfree(data->stream.runtime->buffer);
 	kfree(data->stream.runtime);
Signature · 1 line
1.7.2.5
#1 lore raw

sound/core/compress_offload.c static int snd_compr_open(struct inode *inode, struct file *f) · line 139

Quoted 4 lines · Richard Fitzgerald
sound/core/compress_offload.c +4 -0
+	if ((data->stream.runtime->state == SNDRV_PCM_STATE_RUNNING) ||
+	    (data->stream.runtime->state == SNDRV_PCM_STATE_PAUSED))
+		data->stream.ops->trigger(&data->stream, SNDRV_PCM_TRIGGER_STOP);
+

A switch statement would be more idiomatic for this sort of thing.

#2 lore raw
Quoted 7 lines

sound/core/compress_offload.c static int snd_compr_open(struct inode *inode, struct file *f) · line 139

Quoted 4 lines
sound/core/compress_offload.c +4 -0
+     if ((data->stream.runtime->state == SNDRV_PCM_STATE_RUNNING) ||
+         (data->stream.runtime->state == SNDRV_PCM_STATE_PAUSED))
+             data->stream.ops->trigger(&data->stream, SNDRV_PCM_TRIGGER_STOP);
+

A switch statement would be more idiomatic for this sort of thing.

This follows the general style used in other functions in the source file. I'm happy to upload a version that uses a switch instead if that's preferred.

#3 lore raw
Quoted 11 lines · Richard Fitzgerald
Quoted 7 lines

sound/core/compress_offload.c static int snd_compr_open(struct inode *inode, struct file *f) · line 139

Quoted 4 lines
sound/core/compress_offload.c +4 -0
+     if ((data->stream.runtime->state == SNDRV_PCM_STATE_RUNNING) ||
+         (data->stream.runtime->state == SNDRV_PCM_STATE_PAUSED))
+             data->stream.ops->trigger(&data->stream, SNDRV_PCM_TRIGGER_STOP);
+

A switch statement would be more idiomatic for this sort of thing.

This follows the general style used in other functions in the source file. I'm happy to upload a version that uses a switch instead if that's preferred.

Well, it doesn't quite follow the same style as the code generally does:

        if (stream->runtime->state == SNDRV_PCM_STATE_PAUSED ||
                        stream->runtime->state == SNDRV_PCM_STATE_OPEN) {

with fewer () and different indentation to what you have above... being consistent with the rest of the file is best, though it would be nice to update the file to do this sort of thing with switches.

#4 lore raw
In reply to Richard Fitzgerald
Quoted 14 lines · Richard Fitzgerald

If the stream state is running or paused when device file is closed snd_compr_free() will send a SNDRV_PCM_TRIGGER_STOP to the stream.

---
 sound/core/compress_offload.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
sound/core/compress_offload.c +0 -0
index 91e6bcb..a81c5e4 100644

sound/core/compress_offload.c static int snd_compr_open(struct inode *inode, struct file *f) · line 138

Quoted 7 lines
sound/core/compress_offload.c +4 -0
@@ -132,6 +132,11 @@ static int snd_compr_open(struct inode *inode, struct file *f)
 static int snd_compr_free(struct inode *inode, struct file *f)
 {
 	struct snd_compr_file *data = f->private_data;
+
+	if ((data->stream.runtime->state == SNDRV_PCM_STATE_RUNNING) ||
+	    (data->stream.runtime->state == SNDRV_PCM_STATE_PAUSED))
+		data->stream.ops->trigger(&data->stream, SNDRV_PCM_TRIGGER_STOP);

two things:
1. I like Mark's idea the switch will make it look better :)
2. why do you want to do explicit stop when you are freeing. Esp the Paused cases doesnt make sense. Shouldnt the DSP be able to handle this transistion?

--
~Vinod

Quoted 7 lines
sound/core/compress_offload.c +1 -0
+
 	data->stream.ops->free(&data->stream);
 	kfree(data->stream.runtime->buffer);
 	kfree(data->stream.runtime);
Signature · 1 line
1.7.2.5
#5 lore raw
Quoted 10 lines · Vinod Koul
Quoted 9 lines · Richard Fitzgerald

If the stream state is running or paused when device file is closed snd_compr_free() will send a SNDRV_PCM_TRIGGER_STOP to the stream.

---
 sound/core/compress_offload.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
Quoted 16 lines

sound/core/compress_offload.c static int snd_compr_open(struct inode *inode, struct file *f) · line 138

Quoted 12 lines
sound/core/compress_offload.c +4 -0
index 91e6bcb..a81c5e4 100644
@@ -132,6 +132,11 @@ static int snd_compr_open(struct inode *inode, struct file *f)
 static int snd_compr_free(struct inode *inode, struct file *f)
 {
 	struct snd_compr_file *data = f->private_data;
+
+	if ((data->stream.runtime->state == SNDRV_PCM_STATE_RUNNING) ||
+	    (data->stream.runtime->state == SNDRV_PCM_STATE_PAUSED))
+		data->stream.ops->trigger(&data->stream, SNDRV_PCM_TRIGGER_STOP);

two things:
1. I like Mark's idea the switch will make it look better :)
2. why do you want to do explicit stop when you are freeing. Esp the Paused cases doesnt make sense. Shouldnt the DSP be able to handle this transistion?

Userspace process might be killed, or crash, or just be bugged and we need to protect against that. Nicer if the framework handles this instead of pushing the problem down to every codec driver.