Commit f9b0c053 authored by Takashi Iwai's avatar Takashi Iwai

ALSA: pcm: Use a macro for parameter masks to reduce the needed cast

The parameter bit mask needs often explicit cast with __force,
e.g. for the PCM subformat type.  Instead of adding __force at each
place, which is error prone, this patch introduces a new macro and
replaces the all bit shift with it.  This fixes the sparse warnings
like the following:
  sound/core/pcm_native.c:2508:30: warning: restricted snd_pcm_access_t degrades to integer

No functional changes, just sparse warning fixes.

Link: https://lore.kernel.org/r/20200206163945.6797-7-tiwai@suse.deSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent ba71d227
...@@ -228,6 +228,9 @@ int snd_pcm_info_user(struct snd_pcm_substream *substream, ...@@ -228,6 +228,9 @@ int snd_pcm_info_user(struct snd_pcm_substream *substream,
return err; return err;
} }
/* macro for simplified cast */
#define PARAM_MASK_BIT(b) (1U << (__force int)(b))
static bool hw_support_mmap(struct snd_pcm_substream *substream) static bool hw_support_mmap(struct snd_pcm_substream *substream)
{ {
if (!(substream->runtime->hw.info & SNDRV_PCM_INFO_MMAP)) if (!(substream->runtime->hw.info & SNDRV_PCM_INFO_MMAP))
...@@ -257,7 +260,7 @@ static int constrain_mask_params(struct snd_pcm_substream *substream, ...@@ -257,7 +260,7 @@ static int constrain_mask_params(struct snd_pcm_substream *substream,
return -EINVAL; return -EINVAL;
/* This parameter is not requested to change by a caller. */ /* This parameter is not requested to change by a caller. */
if (!(params->rmask & (1 << k))) if (!(params->rmask & PARAM_MASK_BIT(k)))
continue; continue;
if (trace_hw_mask_param_enabled()) if (trace_hw_mask_param_enabled())
...@@ -271,7 +274,7 @@ static int constrain_mask_params(struct snd_pcm_substream *substream, ...@@ -271,7 +274,7 @@ static int constrain_mask_params(struct snd_pcm_substream *substream,
/* Set corresponding flag so that the caller gets it. */ /* Set corresponding flag so that the caller gets it. */
trace_hw_mask_param(substream, k, 0, &old_mask, m); trace_hw_mask_param(substream, k, 0, &old_mask, m);
params->cmask |= 1 << k; params->cmask |= PARAM_MASK_BIT(k);
} }
return 0; return 0;
...@@ -293,7 +296,7 @@ static int constrain_interval_params(struct snd_pcm_substream *substream, ...@@ -293,7 +296,7 @@ static int constrain_interval_params(struct snd_pcm_substream *substream,
return -EINVAL; return -EINVAL;
/* This parameter is not requested to change by a caller. */ /* This parameter is not requested to change by a caller. */
if (!(params->rmask & (1 << k))) if (!(params->rmask & PARAM_MASK_BIT(k)))
continue; continue;
if (trace_hw_interval_param_enabled()) if (trace_hw_interval_param_enabled())
...@@ -307,7 +310,7 @@ static int constrain_interval_params(struct snd_pcm_substream *substream, ...@@ -307,7 +310,7 @@ static int constrain_interval_params(struct snd_pcm_substream *substream,
/* Set corresponding flag so that the caller gets it. */ /* Set corresponding flag so that the caller gets it. */
trace_hw_interval_param(substream, k, 0, &old_interval, i); trace_hw_interval_param(substream, k, 0, &old_interval, i);
params->cmask |= 1 << k; params->cmask |= PARAM_MASK_BIT(k);
} }
return 0; return 0;
...@@ -349,7 +352,7 @@ static int constrain_params_by_rules(struct snd_pcm_substream *substream, ...@@ -349,7 +352,7 @@ static int constrain_params_by_rules(struct snd_pcm_substream *substream,
* have 0 so that the parameters are never changed anymore. * have 0 so that the parameters are never changed anymore.
*/ */
for (k = 0; k <= SNDRV_PCM_HW_PARAM_LAST_INTERVAL; k++) for (k = 0; k <= SNDRV_PCM_HW_PARAM_LAST_INTERVAL; k++)
vstamps[k] = (params->rmask & (1 << k)) ? 1 : 0; vstamps[k] = (params->rmask & PARAM_MASK_BIT(k)) ? 1 : 0;
/* Due to the above design, actual sequence number starts at 2. */ /* Due to the above design, actual sequence number starts at 2. */
stamp = 2; stamp = 2;
...@@ -417,7 +420,7 @@ static int constrain_params_by_rules(struct snd_pcm_substream *substream, ...@@ -417,7 +420,7 @@ static int constrain_params_by_rules(struct snd_pcm_substream *substream,
hw_param_interval(params, r->var)); hw_param_interval(params, r->var));
} }
params->cmask |= (1 << r->var); params->cmask |= PARAM_MASK_BIT(r->var);
vstamps[r->var] = stamp; vstamps[r->var] = stamp;
again = true; again = true;
} }
...@@ -486,9 +489,9 @@ int snd_pcm_hw_refine(struct snd_pcm_substream *substream, ...@@ -486,9 +489,9 @@ int snd_pcm_hw_refine(struct snd_pcm_substream *substream,
params->info = 0; params->info = 0;
params->fifo_size = 0; params->fifo_size = 0;
if (params->rmask & (1 << SNDRV_PCM_HW_PARAM_SAMPLE_BITS)) if (params->rmask & PARAM_MASK_BIT(SNDRV_PCM_HW_PARAM_SAMPLE_BITS))
params->msbits = 0; params->msbits = 0;
if (params->rmask & (1 << SNDRV_PCM_HW_PARAM_RATE)) { if (params->rmask & PARAM_MASK_BIT(SNDRV_PCM_HW_PARAM_RATE)) {
params->rate_num = 0; params->rate_num = 0;
params->rate_den = 0; params->rate_den = 0;
} }
...@@ -2506,16 +2509,16 @@ static int snd_pcm_hw_constraints_complete(struct snd_pcm_substream *substream) ...@@ -2506,16 +2509,16 @@ static int snd_pcm_hw_constraints_complete(struct snd_pcm_substream *substream)
unsigned int mask = 0; unsigned int mask = 0;
if (hw->info & SNDRV_PCM_INFO_INTERLEAVED) if (hw->info & SNDRV_PCM_INFO_INTERLEAVED)
mask |= 1 << SNDRV_PCM_ACCESS_RW_INTERLEAVED; mask |= PARAM_MASK_BIT(SNDRV_PCM_ACCESS_RW_INTERLEAVED);
if (hw->info & SNDRV_PCM_INFO_NONINTERLEAVED) if (hw->info & SNDRV_PCM_INFO_NONINTERLEAVED)
mask |= 1 << SNDRV_PCM_ACCESS_RW_NONINTERLEAVED; mask |= PARAM_MASK_BIT(SNDRV_PCM_ACCESS_RW_NONINTERLEAVED);
if (hw_support_mmap(substream)) { if (hw_support_mmap(substream)) {
if (hw->info & SNDRV_PCM_INFO_INTERLEAVED) if (hw->info & SNDRV_PCM_INFO_INTERLEAVED)
mask |= 1 << SNDRV_PCM_ACCESS_MMAP_INTERLEAVED; mask |= PARAM_MASK_BIT(SNDRV_PCM_ACCESS_MMAP_INTERLEAVED);
if (hw->info & SNDRV_PCM_INFO_NONINTERLEAVED) if (hw->info & SNDRV_PCM_INFO_NONINTERLEAVED)
mask |= 1 << SNDRV_PCM_ACCESS_MMAP_NONINTERLEAVED; mask |= PARAM_MASK_BIT(SNDRV_PCM_ACCESS_MMAP_NONINTERLEAVED);
if (hw->info & SNDRV_PCM_INFO_COMPLEX) if (hw->info & SNDRV_PCM_INFO_COMPLEX)
mask |= 1 << SNDRV_PCM_ACCESS_MMAP_COMPLEX; mask |= PARAM_MASK_BIT(SNDRV_PCM_ACCESS_MMAP_COMPLEX);
} }
err = snd_pcm_hw_constraint_mask(runtime, SNDRV_PCM_HW_PARAM_ACCESS, mask); err = snd_pcm_hw_constraint_mask(runtime, SNDRV_PCM_HW_PARAM_ACCESS, mask);
if (err < 0) if (err < 0)
...@@ -2525,7 +2528,8 @@ static int snd_pcm_hw_constraints_complete(struct snd_pcm_substream *substream) ...@@ -2525,7 +2528,8 @@ static int snd_pcm_hw_constraints_complete(struct snd_pcm_substream *substream)
if (err < 0) if (err < 0)
return err; return err;
err = snd_pcm_hw_constraint_mask(runtime, SNDRV_PCM_HW_PARAM_SUBFORMAT, 1 << SNDRV_PCM_SUBFORMAT_STD); err = snd_pcm_hw_constraint_mask(runtime, SNDRV_PCM_HW_PARAM_SUBFORMAT,
PARAM_MASK_BIT(SNDRV_PCM_SUBFORMAT_STD));
if (err < 0) if (err < 0)
return err; return err;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment