Skip to content

Commit

Permalink
ALSA: xen-front: fix unintention integer overflow on left shifts
Browse files Browse the repository at this point in the history
Shifting the integer value 1 is evaluated using 32-bit
arithmetic and then used in an expression that expects a 64-bit
value, so there is potentially an integer overflow. Fix this
by using the BIT_ULL macro to perform the shift.

[ Note: as of the time being, no actual integer overflow hits because
  all values are less than 32bit, not including the extended 3-byte or
  DSD formats.  But this is the right fix for future usage, of
  course. -- tiwai ]

Addresses-Coverity: ("Unintentional integer overflow")
Signed-off-by: Colin Ian King <[email protected]>
Signed-off-by: Takashi Iwai <[email protected]>
  • Loading branch information
Colin Ian King authored and tiwai committed Jun 28, 2019
1 parent 801ebf1 commit 3fc4147
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions sound/xen/xen_snd_front_alsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ static u64 to_sndif_formats_mask(u64 alsa_formats)
mask = 0;
for (i = 0; i < ARRAY_SIZE(ALSA_SNDIF_FORMATS); i++)
if (pcm_format_to_bits(ALSA_SNDIF_FORMATS[i].alsa) & alsa_formats)
mask |= 1 << ALSA_SNDIF_FORMATS[i].sndif;
mask |= BIT_ULL(ALSA_SNDIF_FORMATS[i].sndif);

return mask;
}
Expand All @@ -208,7 +208,7 @@ static u64 to_alsa_formats_mask(u64 sndif_formats)

mask = 0;
for (i = 0; i < ARRAY_SIZE(ALSA_SNDIF_FORMATS); i++)
if (1 << ALSA_SNDIF_FORMATS[i].sndif & sndif_formats)
if (BIT_ULL(ALSA_SNDIF_FORMATS[i].sndif) & sndif_formats)
mask |= pcm_format_to_bits(ALSA_SNDIF_FORMATS[i].alsa);

return mask;
Expand Down

0 comments on commit 3fc4147

Please sign in to comment.