[alsa-devel] [PATCH] alsa: add annotations to bitwise type snd_pcm_hw_param_t

Takashi Iwai tiwai at suse.de
Thu Jun 19 11:21:18 CEST 2008


At Wed, 18 Jun 2008 13:45:13 -0700,
Harvey Harrison wrote:
> 
> Fully half of all alsa sparse warnings are from snd_pcm_hw_param_t degrading
> to integer type, this goes a long way towards eliminating them.

Oh what a cast hell...

> Signed-off-by: Harvey Harrison <harvey.harrison at gmail.com>
> ---
>  include/sound/asound.h |   12 ++++++++----
>  include/sound/pcm.h    |   32 ++++++++++++++++----------------
>  2 files changed, 24 insertions(+), 20 deletions(-)
> 
> diff --git a/include/sound/asound.h b/include/sound/asound.h
> index 3eaf155..0309da2 100644
> --- a/include/sound/asound.h
> +++ b/include/sound/asound.h
> @@ -302,6 +302,8 @@ typedef int __bitwise snd_pcm_hw_param_t;
>  #define	SNDRV_PCM_HW_PARAM_SUBFORMAT	((__force snd_pcm_hw_param_t) 2) /* Subformat */
>  #define	SNDRV_PCM_HW_PARAM_FIRST_MASK	SNDRV_PCM_HW_PARAM_ACCESS
>  #define	SNDRV_PCM_HW_PARAM_LAST_MASK	SNDRV_PCM_HW_PARAM_SUBFORMAT
> +#define SNDRV_PCM_HW_PARAM_MASK_INDEX(var)	\
> +	((__force int)(var) - (__force int)SNDRV_PCM_HW_PARAM_FIRST_MASK)
>  
>  #define	SNDRV_PCM_HW_PARAM_SAMPLE_BITS	((__force snd_pcm_hw_param_t) 8) /* Bits per sample */
>  #define	SNDRV_PCM_HW_PARAM_FRAME_BITS	((__force snd_pcm_hw_param_t) 9) /* Bits per frame */
> @@ -317,6 +319,8 @@ typedef int __bitwise snd_pcm_hw_param_t;
>  #define	SNDRV_PCM_HW_PARAM_TICK_TIME	((__force snd_pcm_hw_param_t) 19) /* Approx tick duration in us */
>  #define	SNDRV_PCM_HW_PARAM_FIRST_INTERVAL	SNDRV_PCM_HW_PARAM_SAMPLE_BITS
>  #define	SNDRV_PCM_HW_PARAM_LAST_INTERVAL	SNDRV_PCM_HW_PARAM_TICK_TIME
> +#define SNDRV_PCM_HW_PARAM_INTERVAL_INDEX(var)	\
> +	((__force int)(var) - (__force int)SNDRV_PCM_HW_PARAM_FIRST_INTERVAL)
>  
>  #define SNDRV_PCM_HW_PARAMS_NORESAMPLE		(1<<0)	/* avoid rate resampling */
>  
> @@ -336,11 +340,11 @@ struct snd_mask {
>  
>  struct snd_pcm_hw_params {
>  	unsigned int flags;
> -	struct snd_mask masks[SNDRV_PCM_HW_PARAM_LAST_MASK - 
> -			       SNDRV_PCM_HW_PARAM_FIRST_MASK + 1];
> +	struct snd_mask masks[
> +		SNDRV_PCM_HW_PARAM_MASK_INDEX(SNDRV_PCM_HW_PARAM_LAST_MASK) + 1];

Maybe better to define this as SNDRV_PCM_HW_PARAM_MASKS or so
beforehand?  (Ditto for SNDRV_PCM_HW_PARAM_INTERVALS.)
Then, the below would be a bit simpler.

> @@ -761,40 +761,40 @@ static inline void snd_pcm_trigger_done(struct snd_pcm_substream *substream,
>  	substream->runtime->trigger_master = master;
>  }
>  
> -static inline int hw_is_mask(int var)
> +static inline int hw_is_mask(snd_pcm_hw_param_t var)
>  {
> -	return var >= SNDRV_PCM_HW_PARAM_FIRST_MASK &&
> -		var <= SNDRV_PCM_HW_PARAM_LAST_MASK;
> +	return (__force int)var >= (__force int)SNDRV_PCM_HW_PARAM_FIRST_MASK &&
> +		(__force int)var <= (__force int)SNDRV_PCM_HW_PARAM_LAST_MASK;

static inline int hw_is_mask(snd_pcm_hw_param_t var)
{
	unsigned int idx = SNDRV_PCM_HW_PARAM_MASK_INDEX(var);
	return idx < SNDRV_PCM_HW_PARAM_MASKS;
}


Or, we should git rid of __bitwise for snd_pcm_hw_param_t instead of
cast.  The bitwise check doesn't help debugging much for this type in
the end.


thanks,

Takashi


More information about the Alsa-devel mailing list