Skip to contentSkip to conversation

ALSA: compress: fix the states to check for allowing read

PATCH In review Vinod Koul 4 participants 9 messages Apr 28, 2013 – Apr 29, 2013

Subsystems (2)
lore
Share & tools
lore

Vinod Koul

author
#0 lore raw

PATCH 1/1 ALSA: compress: fix the states to check for allowing read

for reading compressed data, we need to allow when we are paused, draining or stopped.

Cc Charles Keepax <[email protected]>
Cc Richard Fitzgerald <[email protected]>
---
 sound/core/compress_offload.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)
sound/core/compress_offload.c +8 -2
index a0bc47f..5389b9a 100644
@@ -311,8 +311,14 @@ static ssize_t snd_compr_read(struct file *f, char __user *buf,
 	stream = &data->stream;
 	mutex_lock(&stream->device->lock);
 
-	/* read is allowed when stream is running */
-	if (stream->runtime->state != SNDRV_PCM_STATE_RUNNING) {
+	/* read is allowed when stream is running, paused, draining and setup
+	 * (yes setup is state which we transistion to after stop, so if user
+	 * wants to read data after stop we allow that
+	 */
+	if (stream->runtime->state != SNDRV_PCM_STATE_RUNNING ||
+			stream->runtime->state != SNDRV_PCM_STATE_DRAINING ||
+			stream->runtime->state != SNDRV_PCM_STATE_PAUSED ||
+			stream->runtime->state != SNDRV_PCM_STATE_SETUP) {
 		retval = -EBADFD;
 		goto out;
 	}
Signature · 1 line
1.7.0.4
#1 lore raw

At Sun, 28 Apr 2013 13:35:22 +0530,

Quoted 21 lines · Vinod Koul

for reading compressed data, we need to allow when we are paused, draining or stopped.

Cc Charles Keepax <[email protected]>
Cc Richard Fitzgerald <[email protected]>
---
 sound/core/compress_offload.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)
sound/core/compress_offload.c +0 -1
index a0bc47f..5389b9a 100644
@@ -311,8 +311,14 @@ static ssize_t snd_compr_read(struct file *f, char __user *buf,
 	stream = &data->stream;
 	mutex_lock(&stream->device->lock);
 
-	/* read is allowed when stream is running */

sound/core/compress_offload.c static ssize_t snd_compr_read(struct file *f, char __user *buf, · line 322

Quoted 10 lines
sound/core/compress_offload.c +8 -1
-	if (stream->runtime->state != SNDRV_PCM_STATE_RUNNING) {
+	/* read is allowed when stream is running, paused, draining and setup
+	 * (yes setup is state which we transistion to after stop, so if user
+	 * wants to read data after stop we allow that
+	 */
+	if (stream->runtime->state != SNDRV_PCM_STATE_RUNNING ||
+			stream->runtime->state != SNDRV_PCM_STATE_DRAINING ||
+			stream->runtime->state != SNDRV_PCM_STATE_PAUSED ||
+			stream->runtime->state != SNDRV_PCM_STATE_SETUP) {
 		retval = -EBADFD;

Aren't they "&&"?

Maybe better to use switch for avoiding such a trivial error...

Takashi

author
#2 lore raw
Quoted 22 lines · Takashi Iwai

At Sun, 28 Apr 2013 13:35:22 +0530,

Quoted 20 lines · Vinod Koul

for reading compressed data, we need to allow when we are paused, draining or stopped.

Cc Charles Keepax <[email protected]>
Cc Richard Fitzgerald <[email protected]>
---
 sound/core/compress_offload.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)
sound/core/compress_offload.c +0 -0
index a0bc47f..5389b9a 100644
@@ -311,8 +311,14 @@ static ssize_t snd_compr_read(struct file *f, char __user *buf,
 	stream = &data->stream;
 	mutex_lock(&stream->device->lock);
 
Quoted 13 lines

sound/core/compress_offload.c static ssize_t snd_compr_read(struct file *f, char __user *buf, · line 322

Quoted 11 lines
sound/core/compress_offload.c +8 -2
-	/* read is allowed when stream is running */
-	if (stream->runtime->state != SNDRV_PCM_STATE_RUNNING) {
+	/* read is allowed when stream is running, paused, draining and setup
+	 * (yes setup is state which we transistion to after stop, so if user
+	 * wants to read data after stop we allow that
+	 */
+	if (stream->runtime->state != SNDRV_PCM_STATE_RUNNING ||
+			stream->runtime->state != SNDRV_PCM_STATE_DRAINING ||
+			stream->runtime->state != SNDRV_PCM_STATE_PAUSED ||
+			stream->runtime->state != SNDRV_PCM_STATE_SETUP) {
 		retval = -EBADFD;

Aren't they "&&"?

Yup :(

Quoted 2 lines

Maybe better to use switch for avoiding such a trivial error...

I started with switch and then didnt want to code for all the PCM_STATES... but yes that makes more sense, i will send that right away.
Is it okay if this get in for 3.10...

--
~Vinod

#3 lore raw

At Mon, 29 Apr 2013 14:15:31 +0530,

Quoted 37 lines · Vinod Koul
Quoted 22 lines · Takashi Iwai

At Sun, 28 Apr 2013 13:35:22 +0530,

Quoted 20 lines · Vinod Koul

for reading compressed data, we need to allow when we are paused, draining or stopped.

Cc Charles Keepax <[email protected]>
Cc Richard Fitzgerald <[email protected]>
---
 sound/core/compress_offload.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)
sound/core/compress_offload.c +0 -0
index a0bc47f..5389b9a 100644
@@ -311,8 +311,14 @@ static ssize_t snd_compr_read(struct file *f, char __user *buf,
 	stream = &data->stream;
 	mutex_lock(&stream->device->lock);
 
Quoted 13 lines

sound/core/compress_offload.c static ssize_t snd_compr_read(struct file *f, char __user *buf, · line 322

Quoted 11 lines
sound/core/compress_offload.c +8 -2
-	/* read is allowed when stream is running */
-	if (stream->runtime->state != SNDRV_PCM_STATE_RUNNING) {
+	/* read is allowed when stream is running, paused, draining and setup
+	 * (yes setup is state which we transistion to after stop, so if user
+	 * wants to read data after stop we allow that
+	 */
+	if (stream->runtime->state != SNDRV_PCM_STATE_RUNNING ||
+			stream->runtime->state != SNDRV_PCM_STATE_DRAINING ||
+			stream->runtime->state != SNDRV_PCM_STATE_PAUSED ||
+			stream->runtime->state != SNDRV_PCM_STATE_SETUP) {
 		retval = -EBADFD;

Aren't they "&&"?

Quoted 5 lines

Yup :(

Quoted 2 lines

Maybe better to use switch for avoiding such a trivial error...

I started with switch and then didnt want to code for all the PCM_STATES... but yes that makes more sense, i will send that right away.

You can code like

	switch (stream->runtime->state) {
	case SNDRV_PCM_STATE_RUNNING:
	case SNDRV_PCM_STATE_DRAINING:
	case SNDRV_PCM_STATE_PAUSED:
	case SNDRV_PCM_STATE_SETUP:
		break; /* OK */
	default:
		retval = -EBADFD;
		break;
	}
Quoted 1 line

Is it okay if this get in for 3.10...

Yes. It's just a damn simple fix.

thanks,

Takashi

#4 lore raw
Quoted 58 lines · Takashi Iwai

At Mon, 29 Apr 2013 14:15:31 +0530,

Quoted 37 lines · Vinod Koul
Quoted 22 lines · Takashi Iwai

At Sun, 28 Apr 2013 13:35:22 +0530,

Quoted 20 lines · Vinod Koul

for reading compressed data, we need to allow when we are paused, draining or stopped.

Cc Charles Keepax <[email protected]>
Cc Richard Fitzgerald <[email protected]>
---
 sound/core/compress_offload.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)
sound/core/compress_offload.c +0 -0
index a0bc47f..5389b9a 100644
@@ -311,8 +311,14 @@ static ssize_t snd_compr_read(struct file *f, char __user *buf,
 	stream = &data->stream;
 	mutex_lock(&stream->device->lock);
 
Quoted 13 lines

sound/core/compress_offload.c static ssize_t snd_compr_read(struct file *f, char __user *buf, · line 322

Quoted 11 lines
sound/core/compress_offload.c +8 -2
-	/* read is allowed when stream is running */
-	if (stream->runtime->state != SNDRV_PCM_STATE_RUNNING) {
+	/* read is allowed when stream is running, paused, draining and setup
+	 * (yes setup is state which we transistion to after stop, so if user
+	 * wants to read data after stop we allow that
+	 */
+	if (stream->runtime->state != SNDRV_PCM_STATE_RUNNING ||
+			stream->runtime->state != SNDRV_PCM_STATE_DRAINING ||
+			stream->runtime->state != SNDRV_PCM_STATE_PAUSED ||
+			stream->runtime->state != SNDRV_PCM_STATE_SETUP) {
 		retval = -EBADFD;

Aren't they "&&"?

Quoted 5 lines

Yup :(

Quoted 2 lines

Maybe better to use switch for avoiding such a trivial error...

I started with switch and then didnt want to code for all the PCM_STATES... but yes that makes more sense, i will send that right away.

You can code like

	switch (stream->runtime->state) {
	case SNDRV_PCM_STATE_RUNNING:
	case SNDRV_PCM_STATE_DRAINING:
	case SNDRV_PCM_STATE_PAUSED:
	case SNDRV_PCM_STATE_SETUP:
		break; /* OK */
	default:
		retval = -EBADFD;
		break;
	}
Quoted 8 lines
Quoted 1 line

Is it okay if this get in for 3.10...

Yes. It's just a damn simple fix.

thanks,

Takashi

Ok with me too.
(You beat me to it with this fix)

author
#5 lore raw
Quoted 2 lines · Richard Fitzgerald

Ok with me too.
(You beat me to it with this fix)

Blame it on merge window :) Wanted to ensure 3.10 compress record is fine

--
~Vinod

author
#6 lore raw
In reply to Takashi Iwai
Quoted 4 lines · Takashi Iwai
Quoted 2 lines

I started with switch and then didnt want to code for all the PCM_STATES... but yes that makes more sense, i will send that right away.

You can code like

Quoted 10 lines
	switch (stream->runtime->state) {
	case SNDRV_PCM_STATE_RUNNING:
	case SNDRV_PCM_STATE_DRAINING:
	case SNDRV_PCM_STATE_PAUSED:
	case SNDRV_PCM_STATE_SETUP:
		break; /* OK */
	default:
		retval = -EBADFD;
		break;
	}

Yup, and i did exactly opposite, let me know if you want like this :)

--
~Vinod

Reviewed-by on v1 1/1
#7 lore raw
In reply to Vinod Koul
Quoted 2 lines · Vinod Koul

for reading compressed data, we need to allow when we are paused, draining or stopped.

sound/core/compress_offload.c static ssize_t snd_compr_read(struct file *f, char __user *buf, · line 317

Quoted 4 lines
sound/core/compress_offload.c +4 -0
+	/* read is allowed when stream is running, paused, draining and setup
+	 * (yes setup is state which we transistion to after stop, so if user
+	 * wants to read data after stop we allow that
+	 */

but I think there's a ) missing in here!

author
#8 lore raw
Quoted 4 lines · Mark Brown
Quoted 2 lines · Vinod Koul

for reading compressed data, we need to allow when we are paused, draining or stopped.

Quoted 8 lines

sound/core/compress_offload.c static ssize_t snd_compr_read(struct file *f, char __user *buf, · line 317

Quoted 4 lines
sound/core/compress_offload.c +4 -0
+	/* read is allowed when stream is running, paused, draining and setup
+	 * (yes setup is state which we transistion to after stop, so if user
+	 * wants to read data after stop we allow that
+	 */

but I think there's a ) missing in here!

Yup :( I guess since Takshi applied it he can fixup it at end of para, and I will owe him a beer next time we meet :)

--
~Vinod