Skip to content

Commit 051147c

Browse files
Dan CarpenterNipaLocal
Dan Carpenter
authored and
NipaLocal
committed
net/mlx4_en: Prevent potential integer overflow calculating Hz
The "freq" variable is in terms of MHz and "max_val_cycles" is in terms of Hz. The fact that "max_val_cycles" is a u64 suggests that support for high frequency is intended but the "freq_khz * 1000" would overflow the u32 type if we went above 4GHz. Use unsigned long long type for the mutliplication to prevent that. Fixes: 31c128b ("net/mlx4_en: Choose time-stamping shift value according to HW frequency") Signed-off-by: Dan Carpenter <[email protected]> Reviewed-by: Simon Horman <[email protected]> Signed-off-by: NipaLocal <nipa@local>
1 parent e4f00b9 commit 051147c

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/net/ethernet/mellanox/mlx4/en_clock.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ static const struct ptp_clock_info mlx4_en_ptp_clock_info = {
249249
static u32 freq_to_shift(u16 freq)
250250
{
251251
u32 freq_khz = freq * 1000;
252-
u64 max_val_cycles = freq_khz * 1000 * MLX4_EN_WRAP_AROUND_SEC;
252+
u64 max_val_cycles = freq_khz * 1000ULL * MLX4_EN_WRAP_AROUND_SEC;
253253
u64 max_val_cycles_rounded = 1ULL << fls64(max_val_cycles - 1);
254254
/* calculate max possible multiplier in order to fit in 64bit */
255255
u64 max_mul = div64_u64(ULLONG_MAX, max_val_cycles_rounded);

0 commit comments

Comments
 (0)