diff mbox series

[8/9] pcm: fix undefined bit shift in bad_pcm_state

Message ID 20201226213547.175071-9-alexhenrie24@gmail.com (mailing list archive)
State New, archived
Headers show
Series scan-build fixes | expand

Commit Message

Alex Henrie Dec. 26, 2020, 9:35 p.m. UTC
Signed-off-by: Alex Henrie <alexhenrie24@gmail.com>
---
 include/pcm.h       | 4 +++-
 src/pcm/pcm.c       | 2 ++
 src/pcm/pcm_local.h | 2 +-
 3 files changed, 6 insertions(+), 2 deletions(-)

Comments

Takashi Iwai Dec. 27, 2020, 8:34 a.m. UTC | #1
On Sat, 26 Dec 2020 22:35:46 +0100,
Alex Henrie wrote:
> 
> Signed-off-by: Alex Henrie <alexhenrie24@gmail.com>
> ---
>  include/pcm.h       | 4 +++-
>  src/pcm/pcm.c       | 2 ++
>  src/pcm/pcm_local.h | 2 +-
>  3 files changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/include/pcm.h b/include/pcm.h
> index e300b951..c6c5d8f8 100644
> --- a/include/pcm.h
> +++ b/include/pcm.h
> @@ -307,7 +307,9 @@ typedef enum _snd_pcm_state {
>  	SND_PCM_STATE_SUSPENDED,
>  	/** Hardware is disconnected */
>  	SND_PCM_STATE_DISCONNECTED,
> -	SND_PCM_STATE_LAST = SND_PCM_STATE_DISCONNECTED,
> +	/** State cannot be queried */
> +	SND_PCM_STATE_UNKNOWN,
> +	SND_PCM_STATE_LAST = SND_PCM_STATE_UNKNOWN,
>  	/** Private - used internally in the library - do not use*/
>  	SND_PCM_STATE_PRIVATE1 = 1024
>  } snd_pcm_state_t;

We can't add a random new state here.  If any, such a thing has to be
defined locally, but this would also break ABI.  So, I don't think
adding a new state is the right fix.

> diff --git a/src/pcm/pcm.c b/src/pcm/pcm.c
> index 24030b31..5fafc2a0 100644
> --- a/src/pcm/pcm.c
> +++ b/src/pcm/pcm.c
> @@ -680,6 +680,8 @@ static int pcm_state_to_error(snd_pcm_state_t state)
>  		return -ESTRPIPE;
>  	case SND_PCM_STATE_DISCONNECTED:
>  		return -ENODEV;
> +	case SND_PCM_STATE_UNKNOWN:
> +		return -ENOSYS;
>  	default:
>  		return 0;
>  	}
> diff --git a/src/pcm/pcm_local.h b/src/pcm/pcm_local.h
> index fe77e50d..04f89623 100644
> --- a/src/pcm/pcm_local.h
> +++ b/src/pcm/pcm_local.h
> @@ -444,7 +444,7 @@ static inline int __snd_pcm_start(snd_pcm_t *pcm)
>  static inline snd_pcm_state_t __snd_pcm_state(snd_pcm_t *pcm)
>  {
>  	if (!pcm->fast_ops->state)
> -		return -ENOSYS;
> +		return SND_PCM_STATE_UNKNOWN;
>  	return pcm->fast_ops->state(pcm->fast_op_arg);

We need either to handle a special error value in all places calling
__snd_pcm_state() or to just return SND_PCM_STATE_XRUN or such instead
here, IMO.


thanks,

Takashi
Jaroslav Kysela Dec. 27, 2020, 12:36 p.m. UTC | #2
Dne 27. 12. 20 v 9:34 Takashi Iwai napsal(a):
> We need either to handle a special error value in all places calling
> __snd_pcm_state() or to just return SND_PCM_STATE_XRUN or such instead
> here, IMO.

I think that SND_PCM_STATE_OPEN is more appropriate here. If the state
callback is not defined, the state management is screwed anyway. The other
functions will return an error (because they depend on the state management),
so it's safe. I applied this change to repo.

					Jaroslav
Alex Henrie Dec. 28, 2020, 1:45 a.m. UTC | #3
On Sun, Dec 27, 2020 at 5:36 AM Jaroslav Kysela <perex@perex.cz> wrote:
>
> Dne 27. 12. 20 v 9:34 Takashi Iwai napsal(a):
> > We need either to handle a special error value in all places calling
> > __snd_pcm_state() or to just return SND_PCM_STATE_XRUN or such instead
> > here, IMO.
>
> I think that SND_PCM_STATE_OPEN is more appropriate here. If the state
> callback is not defined, the state management is screwed anyway. The other
> functions will return an error (because they depend on the state management),
> so it's safe. I applied this change to repo.

Thank you for fixing this properly!

-Alex
diff mbox series

Patch

diff --git a/include/pcm.h b/include/pcm.h
index e300b951..c6c5d8f8 100644
--- a/include/pcm.h
+++ b/include/pcm.h
@@ -307,7 +307,9 @@  typedef enum _snd_pcm_state {
 	SND_PCM_STATE_SUSPENDED,
 	/** Hardware is disconnected */
 	SND_PCM_STATE_DISCONNECTED,
-	SND_PCM_STATE_LAST = SND_PCM_STATE_DISCONNECTED,
+	/** State cannot be queried */
+	SND_PCM_STATE_UNKNOWN,
+	SND_PCM_STATE_LAST = SND_PCM_STATE_UNKNOWN,
 	/** Private - used internally in the library - do not use*/
 	SND_PCM_STATE_PRIVATE1 = 1024
 } snd_pcm_state_t;
diff --git a/src/pcm/pcm.c b/src/pcm/pcm.c
index 24030b31..5fafc2a0 100644
--- a/src/pcm/pcm.c
+++ b/src/pcm/pcm.c
@@ -680,6 +680,8 @@  static int pcm_state_to_error(snd_pcm_state_t state)
 		return -ESTRPIPE;
 	case SND_PCM_STATE_DISCONNECTED:
 		return -ENODEV;
+	case SND_PCM_STATE_UNKNOWN:
+		return -ENOSYS;
 	default:
 		return 0;
 	}
diff --git a/src/pcm/pcm_local.h b/src/pcm/pcm_local.h
index fe77e50d..04f89623 100644
--- a/src/pcm/pcm_local.h
+++ b/src/pcm/pcm_local.h
@@ -444,7 +444,7 @@  static inline int __snd_pcm_start(snd_pcm_t *pcm)
 static inline snd_pcm_state_t __snd_pcm_state(snd_pcm_t *pcm)
 {
 	if (!pcm->fast_ops->state)
-		return -ENOSYS;
+		return SND_PCM_STATE_UNKNOWN;
 	return pcm->fast_ops->state(pcm->fast_op_arg);
 }