Commit 74c34ca1cc12884703c70d34ed333517d978c2e7

Authored by Eldad Zack
Committed by Takashi Iwai
1 parent 754813473c

ALSA: pcm_format_to_bits strong-typed conversion

Add a function to handle conversion from snd_pcm_format_t
to bitwise with proper typing.

Change such conversions to use this function and silence sparse
warnings.

Signed-off-by: Eldad Zack <eldad@fogrefinery.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>

Showing 8 changed files with 18 additions and 11 deletions Side-by-side Diff

... ... @@ -1133,5 +1133,11 @@
1133 1133 unsigned long private_value,
1134 1134 struct snd_pcm_chmap **info_ret);
1135 1135  
  1136 +/* Strong-typed conversion of pcm_format to bitwise */
  1137 +static inline u64 pcm_format_to_bits(snd_pcm_format_t pcm_format)
  1138 +{
  1139 + return 1ULL << (__force int) pcm_format;
  1140 +}
  1141 +
1136 1142 #endif /* __SOUND_PCM_H */
sound/aoa/soundbus/i2sbus/pcm.c
... ... @@ -179,7 +179,7 @@
179 179 */
180 180 if (other->active) {
181 181 /* FIXME: is this guaranteed by the alsa api? */
182   - hw->formats &= (1ULL << i2sdev->format);
  182 + hw->formats &= pcm_format_to_bits(i2sdev->format);
183 183 /* see above, restrict rates to the one we already have */
184 184 hw->rate_min = i2sdev->rate;
185 185 hw->rate_max = i2sdev->rate;
... ... @@ -182,7 +182,7 @@
182 182 runtime->hw.rate_max = chip->cur_rate;
183 183 }
184 184 if (chip->cur_format)
185   - runtime->hw.formats = (1ULL << chip->cur_format);
  185 + runtime->hw.formats = pcm_format_to_bits(chip->cur_format);
186 186 mutex_unlock(&opened_mutex);
187 187 chip->playback_substream = substream;
188 188 return 0;
... ... @@ -201,7 +201,7 @@
201 201 runtime->hw.rate_max = chip->cur_rate;
202 202 }
203 203 if (chip->cur_format)
204   - runtime->hw.formats = (1ULL << chip->cur_format);
  204 + runtime->hw.formats = pcm_format_to_bits(chip->cur_format);
205 205 mutex_unlock(&opened_mutex);
206 206 chip->capture_substream = substream;
207 207 return 0;
sound/drivers/aloop.c
... ... @@ -325,7 +325,7 @@
325 325 struct loopback_pcm *dpcm = runtime->private_data;
326 326 struct loopback_cable *cable = dpcm->cable;
327 327  
328   - cable->hw.formats = (1ULL << runtime->format);
  328 + cable->hw.formats = pcm_format_to_bits(runtime->format);
329 329 cable->hw.rate_min = runtime->rate;
330 330 cable->hw.rate_max = runtime->rate;
331 331 cable->hw.channels_min = runtime->channels;
sound/pci/asihpi/asihpi.c
... ... @@ -966,7 +966,7 @@
966 966 if (!err)
967 967 err = hpi_outstream_query_format(h_stream, &hpi_format);
968 968 if (!err && (hpi_to_alsa_formats[format] != -1))
969   - formats |= (1ULL << hpi_to_alsa_formats[format]);
  969 + formats |= pcm_format_to_bits(hpi_to_alsa_formats[format]);
970 970 }
971 971 return formats;
972 972 }
... ... @@ -1142,7 +1142,7 @@
1142 1142 if (!err)
1143 1143 err = hpi_instream_query_format(h_stream, &hpi_format);
1144 1144 if (!err)
1145   - formats |= (1ULL << hpi_to_alsa_formats[format]);
  1145 + formats |= pcm_format_to_bits(hpi_to_alsa_formats[format]);
1146 1146 }
1147 1147 return formats;
1148 1148 }
... ... @@ -365,7 +365,8 @@
365 365 {
366 366 struct usb_interface_descriptor *altsd = get_iface_desc(iface);
367 367 int protocol = altsd->bInterfaceProtocol;
368   - int pcm_format, ret;
  368 + snd_pcm_format_t pcm_format;
  369 + int ret;
369 370  
370 371 if (fmt->bFormatType == UAC_FORMAT_TYPE_III) {
371 372 /* FIXME: the format type is really IECxxx
... ... @@ -384,7 +385,7 @@
384 385 default:
385 386 pcm_format = SNDRV_PCM_FORMAT_S16_LE;
386 387 }
387   - fp->formats = 1uLL << pcm_format;
  388 + fp->formats = pcm_format_to_bits(pcm_format);
388 389 } else {
389 390 fp->formats = parse_audio_format_i_type(chip, fp, format,
390 391 fmt, protocol);
... ... @@ -100,7 +100,7 @@
100 100 int cur_attr = 0, attr;
101 101  
102 102 list_for_each_entry(fp, &subs->fmt_list, list) {
103   - if (!(fp->formats & (1uLL << subs->pcm_format)))
  103 + if (!(fp->formats & pcm_format_to_bits(subs->pcm_format)))
104 104 continue;
105 105 if (fp->channels != subs->channels)
106 106 continue;
... ... @@ -478,7 +478,7 @@
478 478 return 0;
479 479 }
480 480  
481   - if (!(fp->formats & (1ULL << pcm_format))) {
  481 + if (!(fp->formats & pcm_format_to_bits(pcm_format))) {
482 482 snd_printdd("%s: (fmt @%p) no match for format %d\n", __func__,
483 483 fp, pcm_format);
484 484 return 0;
... ... @@ -85,7 +85,7 @@
85 85 snd_iprintf(buffer, " Altset %d\n", fp->altsetting);
86 86 snd_iprintf(buffer, " Format:");
87 87 for (fmt = 0; fmt <= SNDRV_PCM_FORMAT_LAST; ++fmt)
88   - if (fp->formats & (1uLL << fmt))
  88 + if (fp->formats & pcm_format_to_bits(fmt))
89 89 snd_iprintf(buffer, " %s",
90 90 snd_pcm_format_name(fmt));
91 91 snd_iprintf(buffer, "\n");