@@ -158,6 +158,20 @@ static void snd_soc_read_signed(struct snd_soc_component *component,
158158 * signed_val = ret ;
159159}
160160
161+ static int soc_mixer_mask (struct soc_mixer_control * mc )
162+ {
163+ if (mc -> sign_bit )
164+ return GENMASK (mc -> sign_bit , 0 );
165+ else
166+ return GENMASK (fls (mc -> max ) - 1 , 0 );
167+ }
168+
169+ static int soc_mixer_sx_mask (struct soc_mixer_control * mc )
170+ {
171+ // min + max will take us 1-bit over the size of the mask
172+ return GENMASK (fls (mc -> min + mc -> max ) - 2 , 0 );
173+ }
174+
161175/**
162176 * snd_soc_info_volsw - single mixer info callback
163177 * @kcontrol: mixer control
@@ -260,13 +274,10 @@ int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
260274 int max = mc -> max ;
261275 int min = mc -> min ;
262276 int sign_bit = mc -> sign_bit ;
263- unsigned int mask = ( 1ULL << fls ( max )) - 1 ;
277+ unsigned int mask = soc_mixer_mask ( mc ) ;
264278 unsigned int invert = mc -> invert ;
265279 int val ;
266280
267- if (sign_bit )
268- mask = BIT (sign_bit + 1 ) - 1 ;
269-
270281 snd_soc_read_signed (component , reg , mask , shift , sign_bit , & val );
271282
272283 ucontrol -> value .integer .value [0 ] = val - min ;
@@ -312,17 +323,13 @@ int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
312323 unsigned int rshift = mc -> rshift ;
313324 int max = mc -> max ;
314325 int min = mc -> min ;
315- unsigned int sign_bit = mc -> sign_bit ;
316- unsigned int mask = (1 << fls (max )) - 1 ;
326+ unsigned int mask = soc_mixer_mask (mc );
317327 unsigned int invert = mc -> invert ;
318328 int err , ret ;
319329 bool type_2r = false;
320330 unsigned int val2 = 0 ;
321331 unsigned int val , val_mask ;
322332
323- if (sign_bit )
324- mask = BIT (sign_bit + 1 ) - 1 ;
325-
326333 if (ucontrol -> value .integer .value [0 ] < 0 )
327334 return - EINVAL ;
328335 val = ucontrol -> value .integer .value [0 ];
@@ -391,9 +398,8 @@ int snd_soc_get_volsw_sx(struct snd_kcontrol *kcontrol,
391398 unsigned int reg2 = mc -> rreg ;
392399 unsigned int shift = mc -> shift ;
393400 unsigned int rshift = mc -> rshift ;
394- int max = mc -> max ;
395401 int min = mc -> min ;
396- unsigned int mask = ( 1U << ( fls ( min + max ) - 1 )) - 1 ;
402+ unsigned int mask = soc_mixer_sx_mask ( mc ) ;
397403 unsigned int val ;
398404
399405 val = snd_soc_component_read (component , reg );
@@ -431,7 +437,7 @@ int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol,
431437 unsigned int val , val_mask ;
432438 int max = mc -> max ;
433439 int min = mc -> min ;
434- unsigned int mask = ( 1U << ( fls ( min + max ) - 1 )) - 1 ;
440+ unsigned int mask = soc_mixer_sx_mask ( mc ) ;
435441 int err = 0 ;
436442 int ret ;
437443
@@ -525,7 +531,7 @@ int snd_soc_put_volsw_range(struct snd_kcontrol *kcontrol,
525531 unsigned int shift = mc -> shift ;
526532 int min = mc -> min ;
527533 int max = mc -> max ;
528- unsigned int mask = ( 1 << fls ( max )) - 1 ;
534+ unsigned int mask = soc_mixer_mask ( mc ) ;
529535 unsigned int invert = mc -> invert ;
530536 unsigned int val , val_mask ;
531537 int err , ret , tmp ;
@@ -597,7 +603,7 @@ int snd_soc_get_volsw_range(struct snd_kcontrol *kcontrol,
597603 unsigned int shift = mc -> shift ;
598604 int min = mc -> min ;
599605 int max = mc -> max ;
600- unsigned int mask = ( 1 << fls ( max )) - 1 ;
606+ unsigned int mask = soc_mixer_mask ( mc ) ;
601607 unsigned int invert = mc -> invert ;
602608 unsigned int val ;
603609
@@ -891,9 +897,9 @@ int snd_soc_get_xr_sx(struct snd_kcontrol *kcontrol,
891897 unsigned int regbase = mc -> regbase ;
892898 unsigned int regcount = mc -> regcount ;
893899 unsigned int regwshift = component -> val_bytes * BITS_PER_BYTE ;
894- unsigned int regwmask = (1UL << regwshift ) - 1 ;
900+ unsigned int regwmask = GENMASK (regwshift - 1 , 0 );
901+ unsigned long mask = GENMASK (mc -> nbits - 1 , 0 );
895902 unsigned int invert = mc -> invert ;
896- unsigned long mask = (1UL << mc -> nbits ) - 1 ;
897903 long min = mc -> min ;
898904 long max = mc -> max ;
899905 long val = 0 ;
@@ -938,9 +944,9 @@ int snd_soc_put_xr_sx(struct snd_kcontrol *kcontrol,
938944 unsigned int regbase = mc -> regbase ;
939945 unsigned int regcount = mc -> regcount ;
940946 unsigned int regwshift = component -> val_bytes * BITS_PER_BYTE ;
941- unsigned int regwmask = (1UL << regwshift ) - 1 ;
947+ unsigned int regwmask = GENMASK (regwshift - 1 , 0 );
948+ unsigned long mask = GENMASK (mc -> nbits - 1 , 0 );
942949 unsigned int invert = mc -> invert ;
943- unsigned long mask = (1UL << mc -> nbits ) - 1 ;
944950 long max = mc -> max ;
945951 long val = ucontrol -> value .integer .value [0 ];
946952 int ret = 0 ;
@@ -986,7 +992,7 @@ int snd_soc_get_strobe(struct snd_kcontrol *kcontrol,
986992 (struct soc_mixer_control * )kcontrol -> private_value ;
987993 unsigned int reg = mc -> reg ;
988994 unsigned int shift = mc -> shift ;
989- unsigned int mask = 1 << shift ;
995+ unsigned int mask = BIT ( shift ) ;
990996 unsigned int invert = mc -> invert != 0 ;
991997 unsigned int val ;
992998
@@ -1019,7 +1025,7 @@ int snd_soc_put_strobe(struct snd_kcontrol *kcontrol,
10191025 (struct soc_mixer_control * )kcontrol -> private_value ;
10201026 unsigned int reg = mc -> reg ;
10211027 unsigned int shift = mc -> shift ;
1022- unsigned int mask = 1 << shift ;
1028+ unsigned int mask = BIT ( shift ) ;
10231029 unsigned int invert = mc -> invert != 0 ;
10241030 unsigned int strobe = ucontrol -> value .enumerated .item [0 ] != 0 ;
10251031 unsigned int val1 = (strobe ^ invert ) ? mask : 0 ;
0 commit comments