Re: [PATCH] iwlwifi: mvm: Use div64_s64 instead of do_div in iwl_mvm_debug_range_resp

From: Arnd Bergmann
Date: Wed Feb 20 2019 - 05:51:54 EST


On Tue, Feb 19, 2019 at 7:22 PM Nathan Chancellor
<natechancellor@xxxxxxxxx> wrote:
>

> diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/ftm-initiator.c b/drivers/net/wireless/intel/iwlwifi/mvm/ftm-initiator.c
> index e9822a3ec373..92b22250eb7d 100644
> --- a/drivers/net/wireless/intel/iwlwifi/mvm/ftm-initiator.c
> +++ b/drivers/net/wireless/intel/iwlwifi/mvm/ftm-initiator.c
> @@ -462,7 +462,7 @@ static void iwl_mvm_debug_range_resp(struct iwl_mvm *mvm, u8 index,
> {
> s64 rtt_avg = res->ftm.rtt_avg * 100;
>
> - do_div(rtt_avg, 6666);
> + div64_s64(rtt_avg, 6666);

This is wrong: div64_s64 does not modify its argument like do_div(), but
it returns the result instead. You also don't want to divide by a 64-bit
value when the second argument is a small constant.

I think the correct way should be

s64 rtt_avg = div_s64(res->ftm.rtt_avg * 100, 6666);

If you know that the value is positive, using unsigned types
and div_u64() would be slightly faster.

Arnd