Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

atm: he: fix sign-extension overflow on large shift

Shifting the 1 by exp by an int can lead to sign-extension overlow when
exp is 31 since 1 is an signed int and sign-extending this result to an
unsigned long long will set the upper 32 bits. Fix this by shifting an
unsigned long.

Detected by cppcheck:
(warning) Shifting signed 32-bit value by 31 bits is undefined behaviour

Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Colin Ian King and committed by
David S. Miller
cb12d72b 0f149c9f

+1 -1
+1 -1
drivers/atm/he.c
··· 718 718 instead of '/ 512', use '>> 9' to prevent a call 719 719 to divdu3 on x86 platforms 720 720 */ 721 - rate_cps = (unsigned long long) (1 << exp) * (man + 512) >> 9; 721 + rate_cps = (unsigned long long) (1UL << exp) * (man + 512) >> 9; 722 722 723 723 if (rate_cps < 10) 724 724 rate_cps = 10; /* 2.2.1 minimum payload rate is 10 cps */