Skip to content

Commit 61b6034

Browse files
slavashwdavem330
authored andcommitted
net/mlx4_en: Fix type mismatch for 32-bit systems
is_power_of_2 expects unsigned long and we pass u64 max_val_cycles, this will be truncated on 32 bit systems, and the result is not what we were expecting. div_u64 expects u32 as a second argument and we pass max_val_cycles_rounded which is u64 hence it will always be truncated. Fix was tested on both 64 and 32 bit systems and got same results for max_val_cycles and max_val_cycles_rounded. Fixes: 4850cf4 ("net/mlx4_en: Resolve dividing by zero in 32-bit system") Signed-off-by: Slava Shwartsman <slavash@mellanox.com> Signed-off-by: Tariq Toukan <tariqt@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent c1d5f8f commit 61b6034

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,13 +245,9 @@ 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;
251-
u64 max_val_cycles_rounded = is_power_of_2(max_val_cycles + 1) ?
252-
max_val_cycles : tmp_rounded;
248+
u64 max_val_cycles_rounded = 1ULL << fls64(max_val_cycles - 1);
253249
/* calculate max possible multiplier in order to fit in 64bit */
254-
u64 max_mul = div_u64(0xffffffffffffffffULL, max_val_cycles_rounded);
250+
u64 max_mul = div64_u64(ULLONG_MAX, max_val_cycles_rounded);
255251

256252
/* This comes from the reverse of clocksource_khz2mult */
257253
return ilog2(div_u64(max_mul * freq_khz, 1000000));

0 commit comments

Comments
 (0)