ALSA: usb: Use BIT() for bit values
Instead of the explicit "1 << x", use BIT() macro for one bit values. This will improve the readability and also avoids the possible bad value for 31bit shift. Link: https://patch.msgid.link/20240715123646.26679-1-tiwai@suse.de Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
parent
2f38cf730c
commit
e54dc34318
@ -82,13 +82,13 @@ static u64 parse_audio_format_i_type(struct snd_usb_audio *chip,
|
|||||||
fp->fmt_bits = sample_width;
|
fp->fmt_bits = sample_width;
|
||||||
|
|
||||||
if ((pcm_formats == 0) &&
|
if ((pcm_formats == 0) &&
|
||||||
(format == 0 || format == (1 << UAC_FORMAT_TYPE_I_UNDEFINED))) {
|
(format == 0 || format == BIT(UAC_FORMAT_TYPE_I_UNDEFINED))) {
|
||||||
/* some devices don't define this correctly... */
|
/* some devices don't define this correctly... */
|
||||||
usb_audio_info(chip, "%u:%d : format type 0 is detected, processed as PCM\n",
|
usb_audio_info(chip, "%u:%d : format type 0 is detected, processed as PCM\n",
|
||||||
fp->iface, fp->altsetting);
|
fp->iface, fp->altsetting);
|
||||||
format = 1 << UAC_FORMAT_TYPE_I_PCM;
|
format = BIT(UAC_FORMAT_TYPE_I_PCM);
|
||||||
}
|
}
|
||||||
if (format & (1 << UAC_FORMAT_TYPE_I_PCM)) {
|
if (format & BIT(UAC_FORMAT_TYPE_I_PCM)) {
|
||||||
if (((chip->usb_id == USB_ID(0x0582, 0x0016)) ||
|
if (((chip->usb_id == USB_ID(0x0582, 0x0016)) ||
|
||||||
/* Edirol SD-90 */
|
/* Edirol SD-90 */
|
||||||
(chip->usb_id == USB_ID(0x0582, 0x000c))) &&
|
(chip->usb_id == USB_ID(0x0582, 0x000c))) &&
|
||||||
@ -128,7 +128,7 @@ static u64 parse_audio_format_i_type(struct snd_usb_audio *chip,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (format & (1 << UAC_FORMAT_TYPE_I_PCM8)) {
|
if (format & BIT(UAC_FORMAT_TYPE_I_PCM8)) {
|
||||||
/* Dallas DS4201 workaround: it advertises U8 format, but really
|
/* Dallas DS4201 workaround: it advertises U8 format, but really
|
||||||
supports S8. */
|
supports S8. */
|
||||||
if (chip->usb_id == USB_ID(0x04fa, 0x4201))
|
if (chip->usb_id == USB_ID(0x04fa, 0x4201))
|
||||||
@ -136,15 +136,12 @@ static u64 parse_audio_format_i_type(struct snd_usb_audio *chip,
|
|||||||
else
|
else
|
||||||
pcm_formats |= SNDRV_PCM_FMTBIT_U8;
|
pcm_formats |= SNDRV_PCM_FMTBIT_U8;
|
||||||
}
|
}
|
||||||
if (format & (1 << UAC_FORMAT_TYPE_I_IEEE_FLOAT)) {
|
if (format & BIT(UAC_FORMAT_TYPE_I_IEEE_FLOAT))
|
||||||
pcm_formats |= SNDRV_PCM_FMTBIT_FLOAT_LE;
|
pcm_formats |= SNDRV_PCM_FMTBIT_FLOAT_LE;
|
||||||
}
|
if (format & BIT(UAC_FORMAT_TYPE_I_ALAW))
|
||||||
if (format & (1 << UAC_FORMAT_TYPE_I_ALAW)) {
|
|
||||||
pcm_formats |= SNDRV_PCM_FMTBIT_A_LAW;
|
pcm_formats |= SNDRV_PCM_FMTBIT_A_LAW;
|
||||||
}
|
if (format & BIT(UAC_FORMAT_TYPE_I_MULAW))
|
||||||
if (format & (1 << UAC_FORMAT_TYPE_I_MULAW)) {
|
|
||||||
pcm_formats |= SNDRV_PCM_FMTBIT_MU_LAW;
|
pcm_formats |= SNDRV_PCM_FMTBIT_MU_LAW;
|
||||||
}
|
|
||||||
if (format & ~0x3f) {
|
if (format & ~0x3f) {
|
||||||
usb_audio_info(chip,
|
usb_audio_info(chip,
|
||||||
"%u:%d : unsupported format bits %#llx\n",
|
"%u:%d : unsupported format bits %#llx\n",
|
||||||
|
@ -433,7 +433,7 @@ int snd_usb_get_cur_mix_value(struct usb_mixer_elem_info *cval,
|
|||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (cval->cached & (1 << channel)) {
|
if (cval->cached & BIT(channel)) {
|
||||||
*value = cval->cache_val[index];
|
*value = cval->cache_val[index];
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -445,7 +445,7 @@ int snd_usb_get_cur_mix_value(struct usb_mixer_elem_info *cval,
|
|||||||
cval->control, channel, err);
|
cval->control, channel, err);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
cval->cached |= 1 << channel;
|
cval->cached |= BIT(channel);
|
||||||
cval->cache_val[index] = *value;
|
cval->cache_val[index] = *value;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -522,7 +522,7 @@ int snd_usb_set_cur_mix_value(struct usb_mixer_elem_info *cval, int channel,
|
|||||||
int err;
|
int err;
|
||||||
unsigned int read_only = (channel == 0) ?
|
unsigned int read_only = (channel == 0) ?
|
||||||
cval->master_readonly :
|
cval->master_readonly :
|
||||||
cval->ch_readonly & (1 << (channel - 1));
|
cval->ch_readonly & BIT(channel - 1);
|
||||||
|
|
||||||
if (read_only) {
|
if (read_only) {
|
||||||
usb_audio_dbg(cval->head.mixer->chip,
|
usb_audio_dbg(cval->head.mixer->chip,
|
||||||
@ -536,7 +536,7 @@ int snd_usb_set_cur_mix_value(struct usb_mixer_elem_info *cval, int channel,
|
|||||||
value);
|
value);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
return err;
|
return err;
|
||||||
cval->cached |= 1 << channel;
|
cval->cached |= BIT(channel);
|
||||||
cval->cache_val[index] = value;
|
cval->cache_val[index] = value;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1253,7 +1253,7 @@ static int get_min_max_with_quirks(struct usb_mixer_elem_info *cval,
|
|||||||
int minchn = 0;
|
int minchn = 0;
|
||||||
if (cval->cmask) {
|
if (cval->cmask) {
|
||||||
for (i = 0; i < MAX_CHANNELS; i++)
|
for (i = 0; i < MAX_CHANNELS; i++)
|
||||||
if (cval->cmask & (1 << i)) {
|
if (cval->cmask & BIT(i)) {
|
||||||
minchn = i + 1;
|
minchn = i + 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1358,7 +1358,7 @@ no_res_check:
|
|||||||
} else {
|
} else {
|
||||||
idx = 0;
|
idx = 0;
|
||||||
for (i = 0; i < MAX_CHANNELS; i++) {
|
for (i = 0; i < MAX_CHANNELS; i++) {
|
||||||
if (cval->cmask & (1 << i)) {
|
if (cval->cmask & BIT(i)) {
|
||||||
init_cur_mix_raw(cval, i + 1, idx);
|
init_cur_mix_raw(cval, i + 1, idx);
|
||||||
idx++;
|
idx++;
|
||||||
}
|
}
|
||||||
@ -1416,7 +1416,7 @@ static int mixer_ctl_feature_get(struct snd_kcontrol *kcontrol,
|
|||||||
if (cval->cmask) {
|
if (cval->cmask) {
|
||||||
cnt = 0;
|
cnt = 0;
|
||||||
for (c = 0; c < MAX_CHANNELS; c++) {
|
for (c = 0; c < MAX_CHANNELS; c++) {
|
||||||
if (!(cval->cmask & (1 << c)))
|
if (!(cval->cmask & BIT(c)))
|
||||||
continue;
|
continue;
|
||||||
err = snd_usb_get_cur_mix_value(cval, c + 1, cnt, &val);
|
err = snd_usb_get_cur_mix_value(cval, c + 1, cnt, &val);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
@ -1448,7 +1448,7 @@ static int mixer_ctl_feature_put(struct snd_kcontrol *kcontrol,
|
|||||||
if (cval->cmask) {
|
if (cval->cmask) {
|
||||||
cnt = 0;
|
cnt = 0;
|
||||||
for (c = 0; c < MAX_CHANNELS; c++) {
|
for (c = 0; c < MAX_CHANNELS; c++) {
|
||||||
if (!(cval->cmask & (1 << c)))
|
if (!(cval->cmask & BIT(c)))
|
||||||
continue;
|
continue;
|
||||||
err = snd_usb_get_cur_mix_value(cval, c + 1, cnt, &oval);
|
err = snd_usb_get_cur_mix_value(cval, c + 1, cnt, &oval);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
@ -1700,7 +1700,7 @@ static void __build_feature_ctl(struct usb_mixer_interface *mixer,
|
|||||||
} else {
|
} else {
|
||||||
int i, c = 0;
|
int i, c = 0;
|
||||||
for (i = 0; i < 16; i++)
|
for (i = 0; i < 16; i++)
|
||||||
if (ctl_mask & (1 << i))
|
if (ctl_mask & BIT(i))
|
||||||
c++;
|
c++;
|
||||||
cval->channels = c;
|
cval->channels = c;
|
||||||
cval->ch_readonly = readonly_mask;
|
cval->ch_readonly = readonly_mask;
|
||||||
@ -2060,8 +2060,8 @@ static int parse_audio_feature_unit(struct mixer_build *state, int unitid,
|
|||||||
|
|
||||||
mask = snd_usb_combine_bytes(bmaControls +
|
mask = snd_usb_combine_bytes(bmaControls +
|
||||||
csize * (j+1), csize);
|
csize * (j+1), csize);
|
||||||
if (mask & (1 << i))
|
if (mask & BIT(i))
|
||||||
ch_bits |= (1 << j);
|
ch_bits |= BIT(j);
|
||||||
}
|
}
|
||||||
/* audio class v1 controls are never read-only */
|
/* audio class v1 controls are never read-only */
|
||||||
|
|
||||||
@ -2072,7 +2072,7 @@ static int parse_audio_feature_unit(struct mixer_build *state, int unitid,
|
|||||||
if (ch_bits & 1)
|
if (ch_bits & 1)
|
||||||
build_feature_ctl(state, _ftr, ch_bits, control,
|
build_feature_ctl(state, _ftr, ch_bits, control,
|
||||||
&iterm, unitid, 0);
|
&iterm, unitid, 0);
|
||||||
if (master_bits & (1 << i))
|
if (master_bits & BIT(i))
|
||||||
build_feature_ctl(state, _ftr, 0, control,
|
build_feature_ctl(state, _ftr, 0, control,
|
||||||
&iterm, unitid, 0);
|
&iterm, unitid, 0);
|
||||||
}
|
}
|
||||||
@ -2088,9 +2088,9 @@ static int parse_audio_feature_unit(struct mixer_build *state, int unitid,
|
|||||||
mask = snd_usb_combine_bytes(bmaControls +
|
mask = snd_usb_combine_bytes(bmaControls +
|
||||||
csize * (j+1), csize);
|
csize * (j+1), csize);
|
||||||
if (uac_v2v3_control_is_readable(mask, control)) {
|
if (uac_v2v3_control_is_readable(mask, control)) {
|
||||||
ch_bits |= (1 << j);
|
ch_bits |= BIT(j);
|
||||||
if (!uac_v2v3_control_is_writeable(mask, control))
|
if (!uac_v2v3_control_is_writeable(mask, control))
|
||||||
ch_read_only |= (1 << j);
|
ch_read_only |= BIT(j);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2181,7 +2181,7 @@ static void build_mixer_unit_ctl(struct mixer_build *state,
|
|||||||
__u8 *c = uac_mixer_unit_bmControls(desc, state->mixer->protocol);
|
__u8 *c = uac_mixer_unit_bmControls(desc, state->mixer->protocol);
|
||||||
|
|
||||||
if (check_matrix_bitmap(c, in_ch, i, num_outs)) {
|
if (check_matrix_bitmap(c, in_ch, i, num_outs)) {
|
||||||
cval->cmask |= (1 << i);
|
cval->cmask |= BIT(i);
|
||||||
cval->channels++;
|
cval->channels++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2504,7 +2504,7 @@ static int build_audio_procunit(struct mixer_build *state, int unitid,
|
|||||||
|
|
||||||
if (state->mixer->protocol == UAC_VERSION_1) {
|
if (state->mixer->protocol == UAC_VERSION_1) {
|
||||||
if (!(controls[valinfo->control / 8] &
|
if (!(controls[valinfo->control / 8] &
|
||||||
(1 << ((valinfo->control % 8) - 1))))
|
BIT((valinfo->control % 8) - 1)))
|
||||||
continue;
|
continue;
|
||||||
} else { /* UAC_VERSION_2/3 */
|
} else { /* UAC_VERSION_2/3 */
|
||||||
if (!uac_v2v3_control_is_readable(controls[valinfo->control / 8],
|
if (!uac_v2v3_control_is_readable(controls[valinfo->control / 8],
|
||||||
@ -3448,7 +3448,7 @@ static void snd_usb_mixer_interrupt_v2(struct usb_mixer_interface *mixer,
|
|||||||
case UAC2_CS_CUR:
|
case UAC2_CS_CUR:
|
||||||
/* invalidate cache, so the value is read from the device */
|
/* invalidate cache, so the value is read from the device */
|
||||||
if (channel)
|
if (channel)
|
||||||
info->cached &= ~(1 << channel);
|
info->cached &= ~BIT(channel);
|
||||||
else /* master channel */
|
else /* master channel */
|
||||||
info->cached = 0;
|
info->cached = 0;
|
||||||
|
|
||||||
@ -3684,9 +3684,9 @@ static int restore_mixer_value(struct usb_mixer_elem_list *list)
|
|||||||
if (cval->cmask) {
|
if (cval->cmask) {
|
||||||
idx = 0;
|
idx = 0;
|
||||||
for (c = 0; c < MAX_CHANNELS; c++) {
|
for (c = 0; c < MAX_CHANNELS; c++) {
|
||||||
if (!(cval->cmask & (1 << c)))
|
if (!(cval->cmask & BIT(c)))
|
||||||
continue;
|
continue;
|
||||||
if (cval->cached & (1 << (c + 1))) {
|
if (cval->cached & BIT(c + 1)) {
|
||||||
err = snd_usb_set_cur_mix_value(cval, c + 1, idx,
|
err = snd_usb_set_cur_mix_value(cval, c + 1, idx,
|
||||||
cval->cache_val[idx]);
|
cval->cache_val[idx]);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
|
@ -1139,7 +1139,7 @@ static int snd_ftu_create_volume_ctls(struct usb_mixer_interface *mixer)
|
|||||||
for (out = 0; out < 8; out++) {
|
for (out = 0; out < 8; out++) {
|
||||||
control = out + 1;
|
control = out + 1;
|
||||||
for (in = 0; in < 8; in++) {
|
for (in = 0; in < 8; in++) {
|
||||||
cmask = 1 << in;
|
cmask = BIT(in);
|
||||||
snprintf(name, sizeof(name),
|
snprintf(name, sizeof(name),
|
||||||
"AIn%d - Out%d Capture Volume",
|
"AIn%d - Out%d Capture Volume",
|
||||||
in + 1, out + 1);
|
in + 1, out + 1);
|
||||||
@ -1150,7 +1150,7 @@ static int snd_ftu_create_volume_ctls(struct usb_mixer_interface *mixer)
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
for (in = 8; in < 16; in++) {
|
for (in = 8; in < 16; in++) {
|
||||||
cmask = 1 << in;
|
cmask = BIT(in);
|
||||||
snprintf(name, sizeof(name),
|
snprintf(name, sizeof(name),
|
||||||
"DIn%d - Out%d Playback Volume",
|
"DIn%d - Out%d Playback Volume",
|
||||||
in - 7, out + 1);
|
in - 7, out + 1);
|
||||||
@ -1215,7 +1215,7 @@ static int snd_ftu_create_effect_return_ctls(struct usb_mixer_interface *mixer)
|
|||||||
const unsigned int control = 7;
|
const unsigned int control = 7;
|
||||||
|
|
||||||
for (ch = 0; ch < 4; ++ch) {
|
for (ch = 0; ch < 4; ++ch) {
|
||||||
cmask = 1 << ch;
|
cmask = BIT(ch);
|
||||||
snprintf(name, sizeof(name),
|
snprintf(name, sizeof(name),
|
||||||
"Effect Return %d Volume", ch + 1);
|
"Effect Return %d Volume", ch + 1);
|
||||||
err = snd_create_std_mono_ctl(mixer, id, control,
|
err = snd_create_std_mono_ctl(mixer, id, control,
|
||||||
@ -1239,7 +1239,7 @@ static int snd_ftu_create_effect_send_ctls(struct usb_mixer_interface *mixer)
|
|||||||
const unsigned int control = 9;
|
const unsigned int control = 9;
|
||||||
|
|
||||||
for (ch = 0; ch < 8; ++ch) {
|
for (ch = 0; ch < 8; ++ch) {
|
||||||
cmask = 1 << ch;
|
cmask = BIT(ch);
|
||||||
snprintf(name, sizeof(name),
|
snprintf(name, sizeof(name),
|
||||||
"Effect Send AIn%d Volume", ch + 1);
|
"Effect Send AIn%d Volume", ch + 1);
|
||||||
err = snd_create_std_mono_ctl(mixer, id, control, cmask,
|
err = snd_create_std_mono_ctl(mixer, id, control, cmask,
|
||||||
@ -1249,7 +1249,7 @@ static int snd_ftu_create_effect_send_ctls(struct usb_mixer_interface *mixer)
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
for (ch = 8; ch < 16; ++ch) {
|
for (ch = 8; ch < 16; ++ch) {
|
||||||
cmask = 1 << ch;
|
cmask = BIT(ch);
|
||||||
snprintf(name, sizeof(name),
|
snprintf(name, sizeof(name),
|
||||||
"Effect Send DIn%d Volume", ch - 7);
|
"Effect Send DIn%d Volume", ch - 7);
|
||||||
err = snd_create_std_mono_ctl(mixer, id, control, cmask,
|
err = snd_create_std_mono_ctl(mixer, id, control, cmask,
|
||||||
@ -1352,7 +1352,7 @@ static int snd_c400_create_vol_ctls(struct usb_mixer_interface *mixer)
|
|||||||
chan - num_outs + 1, out + 1);
|
chan - num_outs + 1, out + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
cmask = (out == 0) ? 0 : 1 << (out - 1);
|
cmask = (out == 0) ? 0 : BIT(out - 1);
|
||||||
offset = chan * num_outs;
|
offset = chan * num_outs;
|
||||||
err = snd_create_std_mono_ctl_offset(mixer, id, control,
|
err = snd_create_std_mono_ctl_offset(mixer, id, control,
|
||||||
cmask, val_type, offset, name,
|
cmask, val_type, offset, name,
|
||||||
@ -1438,7 +1438,7 @@ static int snd_c400_create_effect_vol_ctls(struct usb_mixer_interface *mixer)
|
|||||||
chan - num_outs + 1);
|
chan - num_outs + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
cmask = (chan == 0) ? 0 : 1 << (chan - 1);
|
cmask = (chan == 0) ? 0 : BIT(chan - 1);
|
||||||
err = snd_create_std_mono_ctl(mixer, id, control,
|
err = snd_create_std_mono_ctl(mixer, id, control,
|
||||||
cmask, val_type, name,
|
cmask, val_type, name,
|
||||||
&snd_usb_mixer_vol_tlv);
|
&snd_usb_mixer_vol_tlv);
|
||||||
@ -1480,7 +1480,7 @@ static int snd_c400_create_effect_ret_vol_ctls(struct usb_mixer_interface *mixer
|
|||||||
chan + 1);
|
chan + 1);
|
||||||
|
|
||||||
cmask = (chan == 0) ? 0 :
|
cmask = (chan == 0) ? 0 :
|
||||||
1 << (chan + (chan % 2) * num_outs - 1);
|
BIT(chan + (chan % 2) * num_outs - 1);
|
||||||
err = snd_create_std_mono_ctl_offset(mixer, id, control,
|
err = snd_create_std_mono_ctl_offset(mixer, id, control,
|
||||||
cmask, val_type, offset, name,
|
cmask, val_type, offset, name,
|
||||||
&snd_usb_mixer_vol_tlv);
|
&snd_usb_mixer_vol_tlv);
|
||||||
@ -2568,12 +2568,12 @@ static int snd_bbfpro_ctl_update(struct usb_mixer_interface *mixer, u8 reg,
|
|||||||
usb_idx = 3;
|
usb_idx = 3;
|
||||||
usb_val = value ? 3 : 0;
|
usb_val = value ? 3 : 0;
|
||||||
} else {
|
} else {
|
||||||
usb_idx = 1 << index;
|
usb_idx = BIT(index);
|
||||||
usb_val = value ? usb_idx : 0;
|
usb_val = value ? usb_idx : 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
usb_req = SND_BBFPRO_USBREQ_CTL_REG2;
|
usb_req = SND_BBFPRO_USBREQ_CTL_REG2;
|
||||||
usb_idx = 1 << index;
|
usb_idx = BIT(index);
|
||||||
usb_val = value ? usb_idx : 0;
|
usb_val = value ? usb_idx : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user