Skip to content

Commit 4850cf4

Browse files
Eugenia Emantayevdavem330
authored andcommitted
net/mlx4_en: Resolve dividing by zero in 32-bit system
When doing roundup_pow_of_two for large enough number with bit 31, an overflow will occur and a value equal to 1 will be returned. In this case 1 will be subtracted from the return value and division by zero will be reached. Fixes: 31c128b ("net/mlx4_en: Choose time-stamping shift value according to HW frequency") Signed-off-by: Eugenia Emantayev <[email protected]> Signed-off-by: Tariq Toukan <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 72da2e9 commit 4850cf4

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,11 @@ static u32 freq_to_shift(u16 freq)
245245
{
246246
u32 freq_khz = freq * 1000;
247247
u64 max_val_cycles = freq_khz * 1000 * MLX4_EN_WRAP_AROUND_SEC;
248+
u64 tmp_rounded =
249+
roundup_pow_of_two(max_val_cycles) > max_val_cycles ?
250+
roundup_pow_of_two(max_val_cycles) - 1 : UINT_MAX;
248251
u64 max_val_cycles_rounded = is_power_of_2(max_val_cycles + 1) ?
249-
max_val_cycles : roundup_pow_of_two(max_val_cycles) - 1;
252+
max_val_cycles : tmp_rounded;
250253
/* calculate max possible multiplier in order to fit in 64bit */
251254
u64 max_mul = div_u64(0xffffffffffffffffULL, max_val_cycles_rounded);
252255

0 commit comments

Comments
 (0)