[-,IOPLUG,1/1] pcm: ioplug: update prepare and draining state correctly
diff mbox

Message ID 1521195646-21615-1-git-send-email-twischer@de.adit-jv.com
State New
Headers show

Commit Message

Timo Wischer March 16, 2018, 10:20 a.m. UTC
From: Timo Wischer <twischer@de.adit-jv.com>

PREPARED should only be set when it is done and it was successfully.

DRAINING should be signalled when starting to drain. There is no need to
check if draining was successfully because it will change to drop (SETUP)
in any case.

Signed-off-by: Timo Wischer <twischer@de.adit-jv.com>

Comments

Takashi Iwai March 16, 2018, 10:30 a.m. UTC | #1
On Fri, 16 Mar 2018 11:20:46 +0100,
<twischer@de.adit-jv.com> wrote:
> 
> From: Timo Wischer <twischer@de.adit-jv.com>
> 
> PREPARED should only be set when it is done and it was successfully.
> 
> DRAINING should be signalled when starting to drain. There is no need to
> check if draining was successfully because it will change to drop (SETUP)
> in any case.
> 
> Signed-off-by: Timo Wischer <twischer@de.adit-jv.com>
> 
> diff --git a/ChangeLog b/ChangeLog
> index 22df356..3dff7fb 100644
> --- a/ChangeLog
> +++ b/ChangeLog
> @@ -1,3 +1,4 @@
> +* Set IO plug state to PREPARED after calling the IO plugin prepare callback
>  * update to libtool 1.3.3
>  
>  0.1.3 -> 0.2.0

No, no, this wasn't what I meant.  This ChangeLog file is actually
dead, remaining only for historical reason.

In the previous patch, you didn't mention the exact change you've made
in the patch description.  That is, the behavior were silently
modified.  This must not be done, it fools the users.

So, if you want to change something, especially if it's about the
behavior change, it has to be clearly documented in the patch
description and/or in the code itself.


In anyway, no need for resend: I dropped the ChangeLog file change but
applied the rest.


thanks,

Takashi

Patch
diff mbox

diff --git a/ChangeLog b/ChangeLog
index 22df356..3dff7fb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,4 @@ 
+* Set IO plug state to PREPARED after calling the IO plugin prepare callback
 * update to libtool 1.3.3
 
 0.1.3 -> 0.2.0
diff --git a/src/pcm/pcm_ioplug.c b/src/pcm/pcm_ioplug.c
index af223a1..8c0ed48 100644
--- a/src/pcm/pcm_ioplug.c
+++ b/src/pcm/pcm_ioplug.c
@@ -146,13 +146,16 @@  static int snd_pcm_ioplug_prepare(snd_pcm_t *pcm)
 	ioplug_priv_t *io = pcm->private_data;
 	int err = 0;
 
-	io->data->state = SND_PCM_STATE_PREPARED;
 	snd_pcm_ioplug_reset(pcm);
 	if (io->data->callback->prepare) {
 		snd_pcm_unlock(pcm); /* to avoid deadlock */
 		err = io->data->callback->prepare(io->data);
 		snd_pcm_lock(pcm);
 	}
+	if (err < 0)
+		return err;
+
+	io->data->state = SND_PCM_STATE_PREPARED;
 	return err;
 }
 
@@ -493,6 +496,8 @@  static int snd_pcm_ioplug_drain(snd_pcm_t *pcm)
 
 	if (io->data->state == SND_PCM_STATE_OPEN)
 		return -EBADFD;
+
+	io->data->state = SND_PCM_STATE_DRAINING;
 	if (io->data->callback->drain)
 		io->data->callback->drain(io->data);
 	snd_pcm_lock(pcm);