Commit 26c3f154 authored by Charles Keepax's avatar Charles Keepax Committed by Takashi Iwai

ALSA: compress: Prevent bypasses of set_params

Currently, whilst in SNDRV_PCM_STATE_OPEN it is possible to call
snd_compr_stop, snd_compr_drain and snd_compr_partial_drain, which
allow a transition to SNDRV_PCM_STATE_SETUP. The stream should
only be able to move to the setup state once it has received a
SNDRV_COMPRESS_SET_PARAMS ioctl. Fix this issue by not allowing
those ioctls whilst in the open state.
Signed-off-by: default avatarCharles Keepax <ckeepax@opensource.cirrus.com>
Acked-by: default avatarVinod Koul <vkoul@kernel.org>
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 4475f8c4
...@@ -711,9 +711,15 @@ static int snd_compr_stop(struct snd_compr_stream *stream) ...@@ -711,9 +711,15 @@ static int snd_compr_stop(struct snd_compr_stream *stream)
{ {
int retval; int retval;
if (stream->runtime->state == SNDRV_PCM_STATE_PREPARED || switch (stream->runtime->state) {
stream->runtime->state == SNDRV_PCM_STATE_SETUP) case SNDRV_PCM_STATE_OPEN:
case SNDRV_PCM_STATE_SETUP:
case SNDRV_PCM_STATE_PREPARED:
return -EPERM; return -EPERM;
default:
break;
}
retval = stream->ops->trigger(stream, SNDRV_PCM_TRIGGER_STOP); retval = stream->ops->trigger(stream, SNDRV_PCM_TRIGGER_STOP);
if (!retval) { if (!retval) {
snd_compr_drain_notify(stream); snd_compr_drain_notify(stream);
...@@ -801,9 +807,14 @@ static int snd_compr_drain(struct snd_compr_stream *stream) ...@@ -801,9 +807,14 @@ static int snd_compr_drain(struct snd_compr_stream *stream)
{ {
int retval; int retval;
if (stream->runtime->state == SNDRV_PCM_STATE_PREPARED || switch (stream->runtime->state) {
stream->runtime->state == SNDRV_PCM_STATE_SETUP) case SNDRV_PCM_STATE_OPEN:
case SNDRV_PCM_STATE_SETUP:
case SNDRV_PCM_STATE_PREPARED:
return -EPERM; return -EPERM;
default:
break;
}
retval = stream->ops->trigger(stream, SND_COMPR_TRIGGER_DRAIN); retval = stream->ops->trigger(stream, SND_COMPR_TRIGGER_DRAIN);
if (retval) { if (retval) {
...@@ -840,9 +851,16 @@ static int snd_compr_next_track(struct snd_compr_stream *stream) ...@@ -840,9 +851,16 @@ static int snd_compr_next_track(struct snd_compr_stream *stream)
static int snd_compr_partial_drain(struct snd_compr_stream *stream) static int snd_compr_partial_drain(struct snd_compr_stream *stream)
{ {
int retval; int retval;
if (stream->runtime->state == SNDRV_PCM_STATE_PREPARED ||
stream->runtime->state == SNDRV_PCM_STATE_SETUP) switch (stream->runtime->state) {
case SNDRV_PCM_STATE_OPEN:
case SNDRV_PCM_STATE_SETUP:
case SNDRV_PCM_STATE_PREPARED:
return -EPERM; return -EPERM;
default:
break;
}
/* stream can be drained only when next track has been signalled */ /* stream can be drained only when next track has been signalled */
if (stream->next_track == false) if (stream->next_track == false)
return -EPERM; return -EPERM;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment