Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: Harvey Harrison <harvey.harrison@gmail.com>
Cc: alsa-devel@alsa-project.org, Alexander Viro <viro@ftp.linux.org.uk>
Subject: Re: [PATCH] alsa: add annotations to bitwise type	snd_pcm_hw_param_t
Date: Thu, 19 Jun 2008 11:21:18 +0200	[thread overview]
Message-ID: <s5hve0593w1.wl%tiwai@suse.de> (raw)
In-Reply-To: <1213821913.2125.21.camel@brick>

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@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

  parent reply	other threads:[~2008-06-19  9:21 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-18 20:45 [PATCH] alsa: add annotations to bitwise type snd_pcm_hw_param_t Harvey Harrison
2008-06-19  8:34 ` Jaroslav Kysela
2008-06-19  9:21 ` Takashi Iwai [this message]
2008-06-22  7:50 ` Al Viro

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=s5hve0593w1.wl%tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=harvey.harrison@gmail.com \
    --cc=viro@ftp.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox