OSDN Git Service

ALSA: pcm: Use standard macros for fixing PCM format cast
authorTakashi Iwai <tiwai@suse.de>
Thu, 6 Feb 2020 16:39:42 +0000 (17:39 +0100)
committerTakashi Iwai <tiwai@suse.de>
Mon, 10 Feb 2020 07:27:41 +0000 (08:27 +0100)
Simplify the code with the new macros for PCM format type iterations.
This fixes the sparse warnings nicely:
  sound/core/pcm_native.c:2302:26: warning: restricted snd_pcm_format_t degrades to integer
  sound/core/pcm_native.c:2306:54: warning: incorrect type in argument 1 (different base types)
  sound/core/pcm_native.c:2306:54:    expected restricted snd_pcm_format_t [usertype] format
  sound/core/pcm_native.c:2306:54:    got unsigned int [assigned] k
  ....

No functional changes, just sparse warning fixes.

Link: https://lore.kernel.org/r/20200206163945.6797-6-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/core/oss/pcm_oss.c
sound/core/pcm_native.c

index 13db777..707eb2a 100644 (file)
@@ -884,20 +884,17 @@ static int snd_pcm_oss_change_params_locked(struct snd_pcm_substream *substream)
                sformat = snd_pcm_plug_slave_format(format, sformat_mask);
 
        if ((__force int)sformat < 0 ||
-           !snd_mask_test(sformat_mask, (__force int)sformat)) {
-               for (sformat = (__force snd_pcm_format_t)0;
-                    (__force int)sformat <= (__force int)SNDRV_PCM_FORMAT_LAST;
-                    sformat = (__force snd_pcm_format_t)((__force int)sformat + 1)) {
-                       if (snd_mask_test(sformat_mask, (__force int)sformat) &&
+           !snd_mask_test_format(sformat_mask, sformat)) {
+               pcm_for_each_format(sformat) {
+                       if (snd_mask_test_format(sformat_mask, sformat) &&
                            snd_pcm_oss_format_to(sformat) >= 0)
-                               break;
-               }
-               if ((__force int)sformat > (__force int)SNDRV_PCM_FORMAT_LAST) {
-                       pcm_dbg(substream->pcm, "Cannot find a format!!!\n");
-                       err = -EINVAL;
-                       goto failure;
+                               goto format_found;
                }
+               pcm_dbg(substream->pcm, "Cannot find a format!!!\n");
+               err = -EINVAL;
+               goto failure;
        }
+ format_found:
        err = _snd_pcm_hw_param_set(sparams, SNDRV_PCM_HW_PARAM_FORMAT, (__force int)sformat, 0);
        if (err < 0)
                goto failure;
index 336406b..900f9cf 100644 (file)
@@ -2293,21 +2293,21 @@ static int snd_pcm_hw_rule_mulkdiv(struct snd_pcm_hw_params *params,
 static int snd_pcm_hw_rule_format(struct snd_pcm_hw_params *params,
                                  struct snd_pcm_hw_rule *rule)
 {
-       unsigned int k;
+       snd_pcm_format_t k;
        const struct snd_interval *i =
                                hw_param_interval_c(params, rule->deps[0]);
        struct snd_mask m;
        struct snd_mask *mask = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
        snd_mask_any(&m);
-       for (k = 0; k <= SNDRV_PCM_FORMAT_LAST; ++k) {
+       pcm_for_each_format(k) {
                int bits;
-               if (! snd_mask_test(mask, k))
+               if (!snd_mask_test_format(mask, k))
                        continue;
                bits = snd_pcm_format_physical_width(k);
                if (bits <= 0)
                        continue; /* ignore invalid formats */
                if ((unsigned)bits < i->min || (unsigned)bits > i->max)
-                       snd_mask_reset(&m, k);
+                       snd_mask_reset(&m, (__force unsigned)k);
        }
        return snd_mask_refine(mask, &m);
 }
@@ -2316,14 +2316,15 @@ static int snd_pcm_hw_rule_sample_bits(struct snd_pcm_hw_params *params,
                                       struct snd_pcm_hw_rule *rule)
 {
        struct snd_interval t;
-       unsigned int k;
+       snd_pcm_format_t k;
+
        t.min = UINT_MAX;
        t.max = 0;
        t.openmin = 0;
        t.openmax = 0;
-       for (k = 0; k <= SNDRV_PCM_FORMAT_LAST; ++k) {
+       pcm_for_each_format(k) {
                int bits;
-               if (! snd_mask_test(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT), k))
+               if (!snd_mask_test_format(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT), k))
                        continue;
                bits = snd_pcm_format_physical_width(k);
                if (bits <= 0)