]> www.infradead.org Git - users/willy/linux.git/commitdiff
atm: he: fix sign-extension overflow on large shift
authorColin Ian King <colin.king@canonical.com>
Tue, 15 Jan 2019 18:03:38 +0000 (18:03 +0000)
committerDavid S. Miller <davem@davemloft.net>
Thu, 17 Jan 2019 19:27:00 +0000 (11:27 -0800)
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>
drivers/atm/he.c

index 2e9d1cfe3aeb35dab6b0322617ec45c56ffad602..211607986134dcfd3864c11ce4201967b6702707 100644 (file)
@@ -718,7 +718,7 @@ static int he_init_cs_block_rcm(struct he_dev *he_dev)
                        instead of '/ 512', use '>> 9' to prevent a call
                        to divdu3 on x86 platforms
                */
-               rate_cps = (unsigned long long) (1 << exp) * (man + 512) >> 9;
+               rate_cps = (unsigned long long) (1UL << exp) * (man + 512) >> 9;
 
                if (rate_cps < 10)
                        rate_cps = 10;  /* 2.2.1 minimum payload rate is 10 cps */