Skip to content

Commit e54dc34

Browse files
committed
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/[email protected] Signed-off-by: Takashi Iwai <[email protected]>
1 parent 2f38cf7 commit e54dc34

File tree

3 files changed

+36
-39
lines changed

3 files changed

+36
-39
lines changed

sound/usb/format.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,13 @@ static u64 parse_audio_format_i_type(struct snd_usb_audio *chip,
8282
fp->fmt_bits = sample_width;
8383

8484
if ((pcm_formats == 0) &&
85-
(format == 0 || format == (1 << UAC_FORMAT_TYPE_I_UNDEFINED))) {
85+
(format == 0 || format == BIT(UAC_FORMAT_TYPE_I_UNDEFINED))) {
8686
/* some devices don't define this correctly... */
8787
usb_audio_info(chip, "%u:%d : format type 0 is detected, processed as PCM\n",
8888
fp->iface, fp->altsetting);
89-
format = 1 << UAC_FORMAT_TYPE_I_PCM;
89+
format = BIT(UAC_FORMAT_TYPE_I_PCM);
9090
}
91-
if (format & (1 << UAC_FORMAT_TYPE_I_PCM)) {
91+
if (format & BIT(UAC_FORMAT_TYPE_I_PCM)) {
9292
if (((chip->usb_id == USB_ID(0x0582, 0x0016)) ||
9393
/* Edirol SD-90 */
9494
(chip->usb_id == USB_ID(0x0582, 0x000c))) &&
@@ -128,23 +128,20 @@ static u64 parse_audio_format_i_type(struct snd_usb_audio *chip,
128128
break;
129129
}
130130
}
131-
if (format & (1 << UAC_FORMAT_TYPE_I_PCM8)) {
131+
if (format & BIT(UAC_FORMAT_TYPE_I_PCM8)) {
132132
/* Dallas DS4201 workaround: it advertises U8 format, but really
133133
supports S8. */
134134
if (chip->usb_id == USB_ID(0x04fa, 0x4201))
135135
pcm_formats |= SNDRV_PCM_FMTBIT_S8;
136136
else
137137
pcm_formats |= SNDRV_PCM_FMTBIT_U8;
138138
}
139-
if (format & (1 << UAC_FORMAT_TYPE_I_IEEE_FLOAT)) {
139+
if (format & BIT(UAC_FORMAT_TYPE_I_IEEE_FLOAT))
140140
pcm_formats |= SNDRV_PCM_FMTBIT_FLOAT_LE;
141-
}
142-
if (format & (1 << UAC_FORMAT_TYPE_I_ALAW)) {
141+
if (format & BIT(UAC_FORMAT_TYPE_I_ALAW))
143142
pcm_formats |= SNDRV_PCM_FMTBIT_A_LAW;
144-
}
145-
if (format & (1 << UAC_FORMAT_TYPE_I_MULAW)) {
143+
if (format & BIT(UAC_FORMAT_TYPE_I_MULAW))
146144
pcm_formats |= SNDRV_PCM_FMTBIT_MU_LAW;
147-
}
148145
if (format & ~0x3f) {
149146
usb_audio_info(chip,
150147
"%u:%d : unsupported format bits %#llx\n",

sound/usb/mixer.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ int snd_usb_get_cur_mix_value(struct usb_mixer_elem_info *cval,
433433
{
434434
int err;
435435

436-
if (cval->cached & (1 << channel)) {
436+
if (cval->cached & BIT(channel)) {
437437
*value = cval->cache_val[index];
438438
return 0;
439439
}
@@ -445,7 +445,7 @@ int snd_usb_get_cur_mix_value(struct usb_mixer_elem_info *cval,
445445
cval->control, channel, err);
446446
return err;
447447
}
448-
cval->cached |= 1 << channel;
448+
cval->cached |= BIT(channel);
449449
cval->cache_val[index] = *value;
450450
return 0;
451451
}
@@ -522,7 +522,7 @@ int snd_usb_set_cur_mix_value(struct usb_mixer_elem_info *cval, int channel,
522522
int err;
523523
unsigned int read_only = (channel == 0) ?
524524
cval->master_readonly :
525-
cval->ch_readonly & (1 << (channel - 1));
525+
cval->ch_readonly & BIT(channel - 1);
526526

527527
if (read_only) {
528528
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,
536536
value);
537537
if (err < 0)
538538
return err;
539-
cval->cached |= 1 << channel;
539+
cval->cached |= BIT(channel);
540540
cval->cache_val[index] = value;
541541
return 0;
542542
}
@@ -1253,7 +1253,7 @@ static int get_min_max_with_quirks(struct usb_mixer_elem_info *cval,
12531253
int minchn = 0;
12541254
if (cval->cmask) {
12551255
for (i = 0; i < MAX_CHANNELS; i++)
1256-
if (cval->cmask & (1 << i)) {
1256+
if (cval->cmask & BIT(i)) {
12571257
minchn = i + 1;
12581258
break;
12591259
}
@@ -1358,7 +1358,7 @@ static int get_min_max_with_quirks(struct usb_mixer_elem_info *cval,
13581358
} else {
13591359
idx = 0;
13601360
for (i = 0; i < MAX_CHANNELS; i++) {
1361-
if (cval->cmask & (1 << i)) {
1361+
if (cval->cmask & BIT(i)) {
13621362
init_cur_mix_raw(cval, i + 1, idx);
13631363
idx++;
13641364
}
@@ -1416,7 +1416,7 @@ static int mixer_ctl_feature_get(struct snd_kcontrol *kcontrol,
14161416
if (cval->cmask) {
14171417
cnt = 0;
14181418
for (c = 0; c < MAX_CHANNELS; c++) {
1419-
if (!(cval->cmask & (1 << c)))
1419+
if (!(cval->cmask & BIT(c)))
14201420
continue;
14211421
err = snd_usb_get_cur_mix_value(cval, c + 1, cnt, &val);
14221422
if (err < 0)
@@ -1448,7 +1448,7 @@ static int mixer_ctl_feature_put(struct snd_kcontrol *kcontrol,
14481448
if (cval->cmask) {
14491449
cnt = 0;
14501450
for (c = 0; c < MAX_CHANNELS; c++) {
1451-
if (!(cval->cmask & (1 << c)))
1451+
if (!(cval->cmask & BIT(c)))
14521452
continue;
14531453
err = snd_usb_get_cur_mix_value(cval, c + 1, cnt, &oval);
14541454
if (err < 0)
@@ -1700,7 +1700,7 @@ static void __build_feature_ctl(struct usb_mixer_interface *mixer,
17001700
} else {
17011701
int i, c = 0;
17021702
for (i = 0; i < 16; i++)
1703-
if (ctl_mask & (1 << i))
1703+
if (ctl_mask & BIT(i))
17041704
c++;
17051705
cval->channels = c;
17061706
cval->ch_readonly = readonly_mask;
@@ -2060,8 +2060,8 @@ static int parse_audio_feature_unit(struct mixer_build *state, int unitid,
20602060

20612061
mask = snd_usb_combine_bytes(bmaControls +
20622062
csize * (j+1), csize);
2063-
if (mask & (1 << i))
2064-
ch_bits |= (1 << j);
2063+
if (mask & BIT(i))
2064+
ch_bits |= BIT(j);
20652065
}
20662066
/* audio class v1 controls are never read-only */
20672067

@@ -2072,7 +2072,7 @@ static int parse_audio_feature_unit(struct mixer_build *state, int unitid,
20722072
if (ch_bits & 1)
20732073
build_feature_ctl(state, _ftr, ch_bits, control,
20742074
&iterm, unitid, 0);
2075-
if (master_bits & (1 << i))
2075+
if (master_bits & BIT(i))
20762076
build_feature_ctl(state, _ftr, 0, control,
20772077
&iterm, unitid, 0);
20782078
}
@@ -2088,9 +2088,9 @@ static int parse_audio_feature_unit(struct mixer_build *state, int unitid,
20882088
mask = snd_usb_combine_bytes(bmaControls +
20892089
csize * (j+1), csize);
20902090
if (uac_v2v3_control_is_readable(mask, control)) {
2091-
ch_bits |= (1 << j);
2091+
ch_bits |= BIT(j);
20922092
if (!uac_v2v3_control_is_writeable(mask, control))
2093-
ch_read_only |= (1 << j);
2093+
ch_read_only |= BIT(j);
20942094
}
20952095
}
20962096

@@ -2181,7 +2181,7 @@ static void build_mixer_unit_ctl(struct mixer_build *state,
21812181
__u8 *c = uac_mixer_unit_bmControls(desc, state->mixer->protocol);
21822182

21832183
if (check_matrix_bitmap(c, in_ch, i, num_outs)) {
2184-
cval->cmask |= (1 << i);
2184+
cval->cmask |= BIT(i);
21852185
cval->channels++;
21862186
}
21872187
}
@@ -2504,7 +2504,7 @@ static int build_audio_procunit(struct mixer_build *state, int unitid,
25042504

25052505
if (state->mixer->protocol == UAC_VERSION_1) {
25062506
if (!(controls[valinfo->control / 8] &
2507-
(1 << ((valinfo->control % 8) - 1))))
2507+
BIT((valinfo->control % 8) - 1)))
25082508
continue;
25092509
} else { /* UAC_VERSION_2/3 */
25102510
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,
34483448
case UAC2_CS_CUR:
34493449
/* invalidate cache, so the value is read from the device */
34503450
if (channel)
3451-
info->cached &= ~(1 << channel);
3451+
info->cached &= ~BIT(channel);
34523452
else /* master channel */
34533453
info->cached = 0;
34543454

@@ -3684,9 +3684,9 @@ static int restore_mixer_value(struct usb_mixer_elem_list *list)
36843684
if (cval->cmask) {
36853685
idx = 0;
36863686
for (c = 0; c < MAX_CHANNELS; c++) {
3687-
if (!(cval->cmask & (1 << c)))
3687+
if (!(cval->cmask & BIT(c)))
36883688
continue;
3689-
if (cval->cached & (1 << (c + 1))) {
3689+
if (cval->cached & BIT(c + 1)) {
36903690
err = snd_usb_set_cur_mix_value(cval, c + 1, idx,
36913691
cval->cache_val[idx]);
36923692
if (err < 0)

sound/usb/mixer_quirks.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,7 +1139,7 @@ static int snd_ftu_create_volume_ctls(struct usb_mixer_interface *mixer)
11391139
for (out = 0; out < 8; out++) {
11401140
control = out + 1;
11411141
for (in = 0; in < 8; in++) {
1142-
cmask = 1 << in;
1142+
cmask = BIT(in);
11431143
snprintf(name, sizeof(name),
11441144
"AIn%d - Out%d Capture Volume",
11451145
in + 1, out + 1);
@@ -1150,7 +1150,7 @@ static int snd_ftu_create_volume_ctls(struct usb_mixer_interface *mixer)
11501150
return err;
11511151
}
11521152
for (in = 8; in < 16; in++) {
1153-
cmask = 1 << in;
1153+
cmask = BIT(in);
11541154
snprintf(name, sizeof(name),
11551155
"DIn%d - Out%d Playback Volume",
11561156
in - 7, out + 1);
@@ -1215,7 +1215,7 @@ static int snd_ftu_create_effect_return_ctls(struct usb_mixer_interface *mixer)
12151215
const unsigned int control = 7;
12161216

12171217
for (ch = 0; ch < 4; ++ch) {
1218-
cmask = 1 << ch;
1218+
cmask = BIT(ch);
12191219
snprintf(name, sizeof(name),
12201220
"Effect Return %d Volume", ch + 1);
12211221
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)
12391239
const unsigned int control = 9;
12401240

12411241
for (ch = 0; ch < 8; ++ch) {
1242-
cmask = 1 << ch;
1242+
cmask = BIT(ch);
12431243
snprintf(name, sizeof(name),
12441244
"Effect Send AIn%d Volume", ch + 1);
12451245
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)
12491249
return err;
12501250
}
12511251
for (ch = 8; ch < 16; ++ch) {
1252-
cmask = 1 << ch;
1252+
cmask = BIT(ch);
12531253
snprintf(name, sizeof(name),
12541254
"Effect Send DIn%d Volume", ch - 7);
12551255
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)
13521352
chan - num_outs + 1, out + 1);
13531353
}
13541354

1355-
cmask = (out == 0) ? 0 : 1 << (out - 1);
1355+
cmask = (out == 0) ? 0 : BIT(out - 1);
13561356
offset = chan * num_outs;
13571357
err = snd_create_std_mono_ctl_offset(mixer, id, control,
13581358
cmask, val_type, offset, name,
@@ -1438,7 +1438,7 @@ static int snd_c400_create_effect_vol_ctls(struct usb_mixer_interface *mixer)
14381438
chan - num_outs + 1);
14391439
}
14401440

1441-
cmask = (chan == 0) ? 0 : 1 << (chan - 1);
1441+
cmask = (chan == 0) ? 0 : BIT(chan - 1);
14421442
err = snd_create_std_mono_ctl(mixer, id, control,
14431443
cmask, val_type, name,
14441444
&snd_usb_mixer_vol_tlv);
@@ -1480,7 +1480,7 @@ static int snd_c400_create_effect_ret_vol_ctls(struct usb_mixer_interface *mixer
14801480
chan + 1);
14811481

14821482
cmask = (chan == 0) ? 0 :
1483-
1 << (chan + (chan % 2) * num_outs - 1);
1483+
BIT(chan + (chan % 2) * num_outs - 1);
14841484
err = snd_create_std_mono_ctl_offset(mixer, id, control,
14851485
cmask, val_type, offset, name,
14861486
&snd_usb_mixer_vol_tlv);
@@ -2568,12 +2568,12 @@ static int snd_bbfpro_ctl_update(struct usb_mixer_interface *mixer, u8 reg,
25682568
usb_idx = 3;
25692569
usb_val = value ? 3 : 0;
25702570
} else {
2571-
usb_idx = 1 << index;
2571+
usb_idx = BIT(index);
25722572
usb_val = value ? usb_idx : 0;
25732573
}
25742574
} else {
25752575
usb_req = SND_BBFPRO_USBREQ_CTL_REG2;
2576-
usb_idx = 1 << index;
2576+
usb_idx = BIT(index);
25772577
usb_val = value ? usb_idx : 0;
25782578
}
25792579

0 commit comments

Comments
 (0)