Skip to contentSkip to conversation

Propagate errors out from compressed streams

PATCH Superseded Charles Keepax 4 participants 14 messages Apr 6, 2016 – Apr 8, 2016

Subsystems (4)

v2 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v2 cover Propagate errors out from compressed streams

If the DSP suffers an unrecoverable error, the driver likely knows about this, however the framework may not get informed because errors returned from pointer requests are ignored within the framework.

Things work out fine if user-space is doing a read as reads return error status back to user-space so the user can find out that things have gone bad. However, if user-space is doing an avail request there is no path for the error to come back up to user-space. The pointer request returns zero available data, so a read never happens and we basically just end up sitting waiting for data on a stream that we know full well has died.

This patch set attempts to address this and ensure that errors are fully propagated to user-space and we don't ever end up wait for data that will never come.

Changes since v1:
- Based on a recommendation from Vinod, rather than handling errors from pointer requests, add a new call that allows us to inform the compress core that the stream has gone bad. Then return errors from the avail and poll callbacks if the stream is bad.

Thanks,
Charles

Charles Keepax (6):
ASoC: compress: Pass error out of soc_compr_pointer
ALSA: compress: Add function to indicate the stream has gone bad
ALSA: compress: Replace complex if statement with switch
ASoC: wm_adsp: Factor out fetching of stream errors from the DSP
ASoC: wm_adsp: Improve DSP error handling
ASoC: wm_adsp: Use new snd_compr_stop_xrun to signal stream failure

 include/sound/compress_driver.h |  3 ++
 sound/core/compress_offload.c   | 67 ++++++++++++++++++++++++++++++++++++++---
 sound/soc/codecs/wm_adsp.c      | 43 +++++++++++++++++++-------
 sound/soc/soc-compress.c        |  5 +--
 4 files changed, 101 insertions(+), 17 deletions(-)
Signature · 1 line
2.1.4
#1 lore raw

PATCH v2 1/6 ASoC: compress: Pass error out of soc_compr_pointer

Both soc_compr_pointer and the platform driver pointer callback return ints but current soc_compr_pointer always returns 0. Update this so we return the actual value from the platform driver callback. This doesn't fix any issues simply makes the code more consistent.

---
 sound/soc/soc-compress.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
sound/soc/soc-compress.c +3 -2
index 875733c..d2df46c 100644
@@ -530,14 +530,15 @@ static int soc_compr_pointer(struct snd_compr_stream *cstream,
 {
 	struct snd_soc_pcm_runtime *rtd = cstream->private_data;
 	struct snd_soc_platform *platform = rtd->platform;
+	int ret = 0;
 
 	mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
 
 	if (platform->driver->compr_ops && platform->driver->compr_ops->pointer)
-		 platform->driver->compr_ops->pointer(cstream, tstamp);
+		ret = platform->driver->compr_ops->pointer(cstream, tstamp);
 
 	mutex_unlock(&rtd->pcm_mutex);
-	return 0;
+	return ret;
 }
 
 static int soc_compr_copy(struct snd_compr_stream *cstream,
Signature · 1 line
2.1.4
#2 lore raw

PATCH v2 2/6 ALSA: compress: Add function to indicate the stream has gone bad

In reply to Charles Keepax

Currently, the avail IOCTL doesn't pass any error status, which means typically on error it simply shows no data available. This can lead to situations where user-space is waiting indefinitely for data that will never come as the DSP has suffered an unrecoverable error.

Add snd_compr_stop_xrun which end drivers can call to indicate the stream has suffered an unrecoverable error and stop it. The avail and poll IOCTLs are then updated to report if the stream is in an error state to user-space. Allowing the error to propagate out. Processing of the actual snd_compr_stop needs to be deferred to a worker thread as the end driver may detect the errors during an existing operation callback.

---
 include/sound/compress_driver.h |  3 +++
 sound/core/compress_offload.c   | 58 ++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 60 insertions(+), 1 deletion(-)
include/sound/compress_driver.h +3 -0
index c0abcdc..968fe2e 100644
@@ -78,6 +78,7 @@ struct snd_compr_stream {
 	struct snd_compr_ops *ops;
 	struct snd_compr_runtime *runtime;
 	struct snd_compr *device;
+	struct delayed_work xrun_work;
 	enum snd_compr_direction direction;
 	bool metadata_set;
 	bool next_track;
@@ -187,4 +188,6 @@ static inline void snd_compr_drain_notify(struct snd_compr_stream *stream)
 	wake_up(&stream->runtime->sleep);
 }
 
+int snd_compr_stop_xrun(struct snd_compr_stream *stream);
+
 #endif
sound/core/compress_offload.c +57 -1

103 lines not on this page · raw message

Signature · 1 line
2.1.4
#3 lore raw

Re: [PATCH v2 2/6] ALSA: compress: Add function to indicate the stream has gone bad

sound/core/compress_offload.c static int snd_compr_stop(struct snd_compr_stream *stream)

Quoted 9 lines · Charles Keepax
sound/core/compress_offload.c +8 -1
+int snd_compr_stop_xrun(struct snd_compr_stream *stream)
+{
+	if (stream->runtime->state == SNDRV_PCM_STATE_XRUN)
+		return 0;
+
+	stream->runtime->state = SNDRV_PCM_STATE_XRUN;
+
+	queue_delayed_work(system_power_efficient_wq, &stream
->xrun_work, 0);

why do we want to do this in workqueue and not stop the compress stream immediately.

Also if we do this, then why should pointer return error?

Signature · 1 line
~Vinod
#4 lore raw

Re: [PATCH v2 2/6] ALSA: compress: Add function to indicate the stream has gone bad

Quoted 14 lines · Vinod

sound/core/compress_offload.c static int snd_compr_stop(struct snd_compr_stream *stream)

Quoted 9 lines · Charles Keepax
sound/core/compress_offload.c +8 -1
+int snd_compr_stop_xrun(struct snd_compr_stream *stream)
+{
+	if (stream->runtime->state == SNDRV_PCM_STATE_XRUN)
+		return 0;
+
+	stream->runtime->state = SNDRV_PCM_STATE_XRUN;
+
+	queue_delayed_work(system_power_efficient_wq, &stream
->xrun_work, 0);

why do we want to do this in workqueue and not stop the compress stream immediately.

We need to defer this to a work queue because it is very likely we will detect the errors whilst already in a callback in the driver. For example we notice the stream is bad whilst processing a read or a pointer callback in the driver. Because this call by definition goes right back to the top of the stack rather than unwinding the stack nicely as returning an error would do, we need to be careful of all the locks that are likely to be held in between.

snd_compr_ioctl - takes stream->device->lock snd_compr_tstamp
soc_compr_pointer - takes rtd->pcm_mutex wm_adsp_compr_pointer - takes dsp->pwr_lock snd_compr_stop_xrun
snd_compr_stop
soc_compr_trigger - Deadlock as we take rtd->pcm_mutex again

Quoted 2 lines

Also if we do this, then why should pointer return error?

The first patch in the chain could indeed be changed to have pointer calls not return an error status. But I feel that would be making the code worse. Ok the situation I am most interested here indicates a failure of the stream, but its a very small leap to imagine situations where pointer fails temporarily and the stream is still good.

Thanks,
Charles

#5 lore raw

Re: [PATCH v2 2/6] ALSA: compress: Add function to indicate the stream has gone bad

Quoted 26 lines · Charles Keepax
Quoted 15 lines · Vinod

sound/core/compress_offload.c static int snd_compr_stop(struct snd_compr_stream *stream)

Quoted 9 lines · Charles Keepax
sound/core/compress_offload.c +8 -1
+int snd_compr_stop_xrun(struct snd_compr_stream *stream)
+{
+	if (stream->runtime->state == SNDRV_PCM_STATE_XRUN)
+		return 0;
+
+	stream->runtime->state = SNDRV_PCM_STATE_XRUN;
+
+	queue_delayed_work(system_power_efficient_wq, &stream
->xrun_work, 0);

why do we want to do this in workqueue and not stop the compress stream
immediately.

We need to defer this to a work queue because it is very likely we will detect the errors whilst already in a callback in the driver. For example we notice the stream is bad whilst processing a read or a pointer callback in the driver. Because this call by definition goes right back to the top of the stack rather than unwinding the stack nicely as returning an error would do, we need to be careful of all the locks that are likely to be held in between.

Quoted 7 lines

snd_compr_ioctl - takes stream->device->lock snd_compr_tstamp
soc_compr_pointer - takes rtd->pcm_mutex wm_adsp_compr_pointer - takes dsp->pwr_lock snd_compr_stop_xrun
snd_compr_stop
soc_compr_trigger - Deadlock as we take rtd->pcm_mutex again

This is what I suspected as well :D so this should be fine. I will take a detailed look at the changes once am back home.

Also should this be made a generic stop rather than xrun. Perhaps the reason can be specified as an argument.

Btw Takashi you okay with this approach?

Quoted 10 lines
Quoted 3 lines

Also if we do this, then why should pointer return error?

The first patch in the chain could indeed be changed to have pointer calls not return an error status. But I feel that would be making the code worse. Ok the situation I am most interested here indicates a failure of the stream, but its a very small leap to imagine situations where pointer fails temporarily and the stream is still good.

The point here is that we are anyway propagating error by invoking the new API so why return error here.
Btw can you please explain how this makes code worse?

I think on PCM we don't do that.

Signature · 1 line
~Vinod
#6 lore raw

Re: [PATCH v2 2/6] ALSA: compress: Add function to indicate the stream has gone bad

Quoted 36 lines · Vinod Koul
Quoted 26 lines · Charles Keepax
Quoted 15 lines · Vinod

sound/core/compress_offload.c static int snd_compr_stop(struct snd_compr_stream *stream)

Quoted 9 lines · Charles Keepax
sound/core/compress_offload.c +8 -1
+int snd_compr_stop_xrun(struct snd_compr_stream *stream)
+{
+	if (stream->runtime->state == SNDRV_PCM_STATE_XRUN)
+		return 0;
+
+	stream->runtime->state = SNDRV_PCM_STATE_XRUN;
+
+	queue_delayed_work(system_power_efficient_wq, &stream
->xrun_work, 0);

why do we want to do this in workqueue and not stop the compress stream
immediately.

We need to defer this to a work queue because it is very likely we will detect the errors whilst already in a callback in the driver. For example we notice the stream is bad whilst processing a read or a pointer callback in the driver. Because this call by definition goes right back to the top of the stack rather than unwinding the stack nicely as returning an error would do, we need to be careful of all the locks that are likely to be held in between.

Quoted 7 lines

snd_compr_ioctl - takes stream->device->lock snd_compr_tstamp
soc_compr_pointer - takes rtd->pcm_mutex wm_adsp_compr_pointer - takes dsp->pwr_lock snd_compr_stop_xrun
snd_compr_stop
soc_compr_trigger - Deadlock as we take rtd->pcm_mutex again

Quoted 7 lines

This is what I suspected as well :D so this should be fine. I will take a detailed look at the changes once am back home.

Also should this be made a generic stop rather than xrun. Perhaps the reason can be specified as an argument.

Btw Takashi you okay with this approach?

Yes, it looks good to me.

Quoted 9 lines
Quoted 8 lines
Quoted 1 line

Also if we do this, then why should pointer return error?

The first patch in the chain could indeed be changed to have pointer calls not return an error status. But I feel that would be making the code worse. Ok the situation I am most interested here indicates a failure of the stream, but its a very small leap to imagine situations where pointer fails temporarily and the stream is still good.

Quoted 5 lines

The point here is that we are anyway propagating error by invoking the new API so why return error here.
Btw can you please explain how this makes code worse?

I think on PCM we don't do that.

PCM stops the stream from the lock context, so there is no leap.

thanks,

Takashi

#7 lore raw

Re: [PATCH v2 2/6] ALSA: compress: Add function to indicate the stream has gone bad

In reply to Koul, Vinod
Quoted 12 lines · Vinod
Quoted 10 lines · Charles Keepax
Quoted 2 lines · Vinod

On Wed, 2016-04-06 at 11:21 +0100, Charles Keepax wrote:
Also if we do this, then why should pointer return error?

The first patch in the chain could indeed be changed to have pointer calls not return an error status. But I feel that would be making the code worse. Ok the situation I am most interested here indicates a failure of the stream, but its a very small leap to imagine situations where pointer fails temporarily and the stream is still good.

Quoted 3 lines

The point here is that we are anyway propagating error by invoking the new API so why return error here.
Btw can you please explain how this makes code worse?

So if I make pointer return void, the two possible error paths are either return zero available data or call xrun. Xrun will stop the stream so I only want to do that if I think the stream is dead. But that likely leaves various catagories of errors I don't want to do that for. Returning zero on the other hand hides the error so no one will ever know an error occurs (well except by inspecting the kernel log). It feels to me like someone is going to hit a case where they need to do that at some point. So removing the return type seems wrong, but at the moment you have two functions that return ints but don't propogate their values though which just looks odd in the code.

Thanks,
Charles

#8 lore raw

PATCH v2 3/6 ALSA: compress: Replace complex if statement with switch

In reply to Charles Keepax

A switch statement looks a bit cleaner than an if statement spread over 3 lines, as such update this to a switch.

---
 sound/core/compress_offload.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
sound/core/compress_offload.c +6 -3
index 0b93121..65d94d6 100644
@@ -303,9 +303,12 @@ static ssize_t snd_compr_write(struct file *f, const char __user *buf,
 	stream = &data->stream;
 	mutex_lock(&stream->device->lock);
 	/* write is allowed when stream is running or has been steup */
-	if (stream->runtime->state != SNDRV_PCM_STATE_SETUP &&
-	    stream->runtime->state != SNDRV_PCM_STATE_PREPARED &&
-			stream->runtime->state != SNDRV_PCM_STATE_RUNNING) {
+	switch (stream->runtime->state) {
+	case SNDRV_PCM_STATE_SETUP:
+	case SNDRV_PCM_STATE_PREPARED:
+	case SNDRV_PCM_STATE_RUNNING:
+		break;
+	default:
 		mutex_unlock(&stream->device->lock);
 		return -EBADFD;
 	}
Signature · 1 line
2.1.4
#9 lore raw

PATCH v2 4/6 ASoC: wm_adsp: Factor out fetching of stream errors from the DSP

In reply to Charles Keepax

Factor out the reading of the DSP error flag into its own function to support further improvements to the code.

---
 sound/soc/codecs/wm_adsp.c | 28 +++++++++++++++++++---------
 1 file changed, 19 insertions(+), 9 deletions(-)
sound/soc/codecs/wm_adsp.c +19 -9
index 953c427..f70c609 100644
@@ -2816,6 +2816,23 @@ static int wm_adsp_buffer_update_avail(struct wm_adsp_compr_buf *buf)
 	return 0;
 }
 
+static int wm_adsp_buffer_get_error(struct wm_adsp_compr_buf *buf)
+{
+	int ret;
+
+	ret = wm_adsp_buffer_read(buf, HOST_BUFFER_FIELD(error), &buf->error);
+	if (ret < 0) {
+		adsp_err(buf->dsp, "Failed to check buffer error: %d\n", ret);
+		return ret;
+	}
+	if (buf->error != 0) {
+		adsp_err(buf->dsp, "Buffer error occurred: %d\n", buf->error);
+		return -EIO;
+	}
+
+	return 0;
+}
+
 int wm_adsp_compr_handle_irq(struct wm_adsp *dsp)
 {
 	struct wm_adsp_compr_buf *buf;
@@ -2834,16 +2851,9 @@ int wm_adsp_compr_handle_irq(struct wm_adsp *dsp)
 
 	adsp_dbg(dsp, "Handling buffer IRQ\n");
 
-	ret = wm_adsp_buffer_read(buf, HOST_BUFFER_FIELD(error), &buf->error);
-	if (ret < 0) {
-		adsp_err(dsp, "Failed to check buffer error: %d\n", ret);
-		goto out;
-	}
-	if (buf->error != 0) {
-		adsp_err(dsp, "Buffer error occurred: %d\n", buf->error);
-		ret = -EIO;
+	ret = wm_adsp_buffer_get_error(buf);
+	if (ret < 0)
 		goto out;
-	}
 
 	ret = wm_adsp_buffer_read(buf, HOST_BUFFER_FIELD(irq_count),
 				  &buf->irq_count);
Signature · 1 line
2.1.4
maintainer
#10 lore raw

Applied "ASoC: wm_adsp: Factor out fetching of stream errors from the DSP" to the asoc tree

The patch

ASoC: wm_adsp: Factor out fetching of stream errors from the DSP

has been applied to the asoc tree at

git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark

Quoted 1 line

From 9771b18a0b374b6e6ecfa84c8b59d5ef79e969b1 Mon Sep 17 00:00:00 2001

From: Charles Keepax <[email protected]>
Date: Wed, 6 Apr 2016 11:21:53 +0100
Subject: [PATCH] ASoC: wm_adsp: Factor out fetching of stream errors from the
DSP

Factor out the reading of the DSP error flag into its own function to support further improvements to the code.

---
 sound/soc/codecs/wm_adsp.c | 28 +++++++++++++++++++---------
 1 file changed, 19 insertions(+), 9 deletions(-)
sound/soc/codecs/wm_adsp.c +19 -9
index 953c4278b75e..f70c60914042 100644
@@ -2816,6 +2816,23 @@ static int wm_adsp_buffer_update_avail(struct wm_adsp_compr_buf *buf)
 	return 0;
 }
 
+static int wm_adsp_buffer_get_error(struct wm_adsp_compr_buf *buf)
+{
+	int ret;
+
+	ret = wm_adsp_buffer_read(buf, HOST_BUFFER_FIELD(error), &buf->error);
+	if (ret < 0) {
+		adsp_err(buf->dsp, "Failed to check buffer error: %d\n", ret);
+		return ret;
+	}
+	if (buf->error != 0) {
+		adsp_err(buf->dsp, "Buffer error occurred: %d\n", buf->error);
+		return -EIO;
+	}
+
+	return 0;
+}
+
 int wm_adsp_compr_handle_irq(struct wm_adsp *dsp)
 {
 	struct wm_adsp_compr_buf *buf;
@@ -2834,16 +2851,9 @@ int wm_adsp_compr_handle_irq(struct wm_adsp *dsp)
 
 	adsp_dbg(dsp, "Handling buffer IRQ\n");
 
-	ret = wm_adsp_buffer_read(buf, HOST_BUFFER_FIELD(error), &buf->error);
-	if (ret < 0) {
-		adsp_err(dsp, "Failed to check buffer error: %d\n", ret);
-		goto out;
-	}
-	if (buf->error != 0) {
-		adsp_err(dsp, "Buffer error occurred: %d\n", buf->error);
-		ret = -EIO;
+	ret = wm_adsp_buffer_get_error(buf);
+	if (ret < 0)
 		goto out;
-	}
 
 	ret = wm_adsp_buffer_read(buf, HOST_BUFFER_FIELD(irq_count),
 				  &buf->irq_count);
Signature · 1 line
2.8.0.rc3
#11 lore raw

PATCH v2 5/6 ASoC: wm_adsp: Improve DSP error handling

In reply to Charles Keepax

If we encounter an error on the DSP side whilst user-space is waiting on the poll we should call snd_compr_fragment_elapsed, although data is not actually available we want to wake user-space such that the error can be propagated out quickly. Additionally some versions of the DSP firmware are not super consistent about actually generating an IRQ if they encounter an error, as such we will check the DSP error status every time we run out of available data as well, to ensure we catch it.

---
 sound/soc/codecs/wm_adsp.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
sound/soc/codecs/wm_adsp.c +6 -1
index f70c609..3ac2e1f 100644
@@ -2853,7 +2853,7 @@ int wm_adsp_compr_handle_irq(struct wm_adsp *dsp)
 
 	ret = wm_adsp_buffer_get_error(buf);
 	if (ret < 0)
-		goto out;
+		goto out_notify; /* Wake poll to report error */
 
 	ret = wm_adsp_buffer_read(buf, HOST_BUFFER_FIELD(irq_count),
 				  &buf->irq_count);
@@ -2868,6 +2868,7 @@ int wm_adsp_compr_handle_irq(struct wm_adsp *dsp)
 		goto out;
 	}
 
+out_notify:
 	if (compr && compr->stream)
 		snd_compr_fragment_elapsed(compr->stream);
 
@@ -2928,6 +2929,10 @@ int wm_adsp_compr_pointer(struct snd_compr_stream *stream,
 		 * DSP to inform us once a whole fragment is available.
 		 */
 		if (buf->avail < wm_adsp_compr_frag_words(compr)) {
+			ret = wm_adsp_buffer_get_error(buf);
+			if (ret < 0)
+				goto out;
+
 			ret = wm_adsp_buffer_reenable_irq(buf);
 			if (ret < 0) {
 				adsp_err(dsp,
Signature · 1 line
2.1.4
maintainer
#12 lore raw

Applied "ASoC: wm_adsp: Improve DSP error handling" to the asoc tree

The patch

ASoC: wm_adsp: Improve DSP error handling

has been applied to the asoc tree at

git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark

Quoted 1 line

From 5847609edb3c80be07e897e449a9bb579a0fe9d8 Mon Sep 17 00:00:00 2001

From: Charles Keepax <[email protected]>
Date: Wed, 6 Apr 2016 11:21:54 +0100
Subject: [PATCH] ASoC: wm_adsp: Improve DSP error handling

If we encounter an error on the DSP side whilst user-space is waiting on the poll we should call snd_compr_fragment_elapsed, although data is not actually available we want to wake user-space such that the error can be propagated out quickly. Additionally some versions of the DSP firmware are not super consistent about actually generating an IRQ if they encounter an error, as such we will check the DSP error status every time we run out of available data as well, to ensure we catch it.

---
 sound/soc/codecs/wm_adsp.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
sound/soc/codecs/wm_adsp.c +6 -1
index f70c60914042..3ac2e1f06ad3 100644
@@ -2853,7 +2853,7 @@ int wm_adsp_compr_handle_irq(struct wm_adsp *dsp)
 
 	ret = wm_adsp_buffer_get_error(buf);
 	if (ret < 0)
-		goto out;
+		goto out_notify; /* Wake poll to report error */
 
 	ret = wm_adsp_buffer_read(buf, HOST_BUFFER_FIELD(irq_count),
 				  &buf->irq_count);
@@ -2868,6 +2868,7 @@ int wm_adsp_compr_handle_irq(struct wm_adsp *dsp)
 		goto out;
 	}
 
+out_notify:
 	if (compr && compr->stream)
 		snd_compr_fragment_elapsed(compr->stream);
 
@@ -2928,6 +2929,10 @@ int wm_adsp_compr_pointer(struct snd_compr_stream *stream,
 		 * DSP to inform us once a whole fragment is available.
 		 */
 		if (buf->avail < wm_adsp_compr_frag_words(compr)) {
+			ret = wm_adsp_buffer_get_error(buf);
+			if (ret < 0)
+				goto out;
+
 			ret = wm_adsp_buffer_reenable_irq(buf);
 			if (ret < 0) {
 				adsp_err(dsp,
Signature · 1 line
2.8.0.rc3
#13 lore raw

PATCH v2 6/6 ASoC: wm_adsp: Use new snd_compr_stop_xrun to signal stream failure

In reply to Charles Keepax

If we encounter a fatal error on the compressed stream call the new snd_compr_stop_xrun to shutdown the stream and allow the core to inform user-space that the stream is no longer valid.

---
 sound/soc/codecs/wm_adsp.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
sound/soc/codecs/wm_adsp.c +8 -2
index 3ac2e1f..4e06776 100644
@@ -2913,6 +2913,7 @@ int wm_adsp_compr_pointer(struct snd_compr_stream *stream,
 	}
 
 	if (compr->buf->error) {
+		snd_compr_stop_xrun(stream);
 		ret = -EIO;
 		goto out;
 	}
@@ -2930,8 +2931,11 @@ int wm_adsp_compr_pointer(struct snd_compr_stream *stream,
 		 */
 		if (buf->avail < wm_adsp_compr_frag_words(compr)) {
 			ret = wm_adsp_buffer_get_error(buf);
-			if (ret < 0)
+			if (ret < 0) {
+				if (compr->buf->error)
+					snd_compr_stop_xrun(stream);
 				goto out;
+			}
 
 			ret = wm_adsp_buffer_reenable_irq(buf);
 			if (ret < 0) {
@@ -3029,8 +3033,10 @@ static int wm_adsp_compr_read(struct wm_adsp_compr *compr,
 	if (!compr->buf)
 		return -ENXIO;
 
-	if (compr->buf->error)
+	if (compr->buf->error) {
+		snd_compr_stop_xrun(compr->stream);
 		return -EIO;
+	}
 
 	count /= WM_ADSP_DATA_WORD_SIZE;
 
Signature · 1 line
2.1.4