From mboxrd@z Thu Jan 1 00:00:00 1970 From: Takashi Iwai Subject: Re: [PATCH] alsa: add annotations to bitwise type snd_pcm_hw_param_t Date: Thu, 19 Jun 2008 11:21:18 +0200 Message-ID: References: <1213821913.2125.21.camel@brick> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by alsa0.perex.cz (Postfix) with ESMTP id 90DE024595 for ; Thu, 19 Jun 2008 11:21:19 +0200 (CEST) In-Reply-To: <1213821913.2125.21.camel@brick> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: alsa-devel-bounces@alsa-project.org Errors-To: alsa-devel-bounces@alsa-project.org To: Harvey Harrison Cc: alsa-devel@alsa-project.org, Alexander Viro List-Id: alsa-devel@alsa-project.org 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 > --- > 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