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

Takashi Iwai tiwai at suse.de
Sun Dec 27 09:34:12 CET 2020


On Sat, 26 Dec 2020 22:35:46 +0100,
Alex Henrie wrote:
> 
> Signed-off-by: Alex Henrie <alexhenrie24 at 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


More information about the Alsa-devel mailing list