All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net: wireless: ath: use div64_u64() instead of do_div()
@ 2022-02-09  8:39 Qing Wang
  2022-02-10  6:40 ` Kalle Valo
  2022-02-10 12:16 ` Kalle Valo
  0 siblings, 2 replies; 4+ messages in thread
From: Qing Wang @ 2022-02-09  8:39 UTC (permalink / raw)
  To: Maya Erez, Kalle Valo, David S. Miller, Jakub Kicinski,
	linux-wireless, wil6210, netdev, linux-kernel
  Cc: Wang Qing

From: Wang Qing <wangqing@vivo.com>

do_div() does a 64-by-32 division.
When the divisor is u64, do_div() truncates it to 32 bits, this means it
can test non-zero and be truncated to zero for division.

fix do_div.cocci warning:
do_div() does a 64-by-32 division, please consider using div64_u64 instead.

Signed-off-by: Wang Qing <wangqing@vivo.com>
---
 drivers/net/wireless/ath/wil6210/debugfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/wireless/ath/wil6210/debugfs.c b/drivers/net/wireless/ath/wil6210/debugfs.c
index 4c944e5..2cee9dd
--- a/drivers/net/wireless/ath/wil6210/debugfs.c
+++ b/drivers/net/wireless/ath/wil6210/debugfs.c
@@ -1766,7 +1766,7 @@ __acquires(&p->tid_rx_lock) __releases(&p->tid_rx_lock)
 			seq_puts(s, "\n");
 			if (!num_packets)
 				continue;
-			do_div(tx_latency_avg, num_packets);
+			div64_u64(tx_latency_avg, num_packets);
 			seq_printf(s, "Tx/Latency min/avg/max (us): %d/%lld/%d",
 				   p->stats.tx_latency_min_us,
 				   tx_latency_avg,
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] net: wireless: ath: use div64_u64() instead of do_div()
  2022-02-09  8:39 [PATCH] net: wireless: ath: use div64_u64() instead of do_div() Qing Wang
@ 2022-02-10  6:40 ` Kalle Valo
  2022-02-10 12:16 ` Kalle Valo
  1 sibling, 0 replies; 4+ messages in thread
From: Kalle Valo @ 2022-02-10  6:40 UTC (permalink / raw)
  To: Qing Wang
  Cc: Maya Erez, David S. Miller, Jakub Kicinski, linux-wireless,
	wil6210, netdev, linux-kernel

Qing Wang <wangqing@vivo.com> writes:

> From: Wang Qing <wangqing@vivo.com>
>
> do_div() does a 64-by-32 division.
> When the divisor is u64, do_div() truncates it to 32 bits, this means it
> can test non-zero and be truncated to zero for division.
>
> fix do_div.cocci warning:
> do_div() does a 64-by-32 division, please consider using div64_u64 instead.
>
> Signed-off-by: Wang Qing <wangqing@vivo.com>
> ---
>  drivers/net/wireless/ath/wil6210/debugfs.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

The subject prefix should be "wil6210:", but I can fix that.

-- 
https://patchwork.kernel.org/project/linux-wireless/list/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] net: wireless: ath: use div64_u64() instead of do_div()
  2022-02-09  8:39 [PATCH] net: wireless: ath: use div64_u64() instead of do_div() Qing Wang
  2022-02-10  6:40 ` Kalle Valo
@ 2022-02-10 12:16 ` Kalle Valo
  2022-02-11 12:23   ` David Laight
  1 sibling, 1 reply; 4+ messages in thread
From: Kalle Valo @ 2022-02-10 12:16 UTC (permalink / raw)
  To: Qing Wang
  Cc: Maya Erez, David S. Miller, Jakub Kicinski, linux-wireless,
	wil6210, netdev, linux-kernel

Qing Wang <wangqing@vivo.com> writes:

> From: Wang Qing <wangqing@vivo.com>
>
> do_div() does a 64-by-32 division.
> When the divisor is u64, do_div() truncates it to 32 bits, this means it
> can test non-zero and be truncated to zero for division.
>
> fix do_div.cocci warning:
> do_div() does a 64-by-32 division, please consider using div64_u64 instead.
>
> Signed-off-by: Wang Qing <wangqing@vivo.com>
> ---
>  drivers/net/wireless/ath/wil6210/debugfs.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/net/wireless/ath/wil6210/debugfs.c b/drivers/net/wireless/ath/wil6210/debugfs.c
> index 4c944e5..2cee9dd
> --- a/drivers/net/wireless/ath/wil6210/debugfs.c
> +++ b/drivers/net/wireless/ath/wil6210/debugfs.c
> @@ -1766,7 +1766,7 @@ __acquires(&p->tid_rx_lock) __releases(&p->tid_rx_lock)
>  			seq_puts(s, "\n");
>  			if (!num_packets)
>  				continue;
> -			do_div(tx_latency_avg, num_packets);
> +			div64_u64(tx_latency_avg, num_packets);

As you have been pointed out in your other patches, do_div() and
div64_u64() work differently.

-- 
https://patchwork.kernel.org/project/linux-wireless/list/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [PATCH] net: wireless: ath: use div64_u64() instead of do_div()
  2022-02-10 12:16 ` Kalle Valo
@ 2022-02-11 12:23   ` David Laight
  0 siblings, 0 replies; 4+ messages in thread
From: David Laight @ 2022-02-11 12:23 UTC (permalink / raw)
  To: 'Kalle Valo', Qing Wang
  Cc: Maya Erez, David S. Miller, Jakub Kicinski, linux-wireless,
	wil6210, netdev, linux-kernel

From: Kalle Valo
> Sent: 10 February 2022 12:16
> 
> Qing Wang <wangqing@vivo.com> writes:
> 
> > From: Wang Qing <wangqing@vivo.com>
> >
> > do_div() does a 64-by-32 division.
> > When the divisor is u64, do_div() truncates it to 32 bits, this means it
> > can test non-zero and be truncated to zero for division.
> >
> > fix do_div.cocci warning:
> > do_div() does a 64-by-32 division, please consider using div64_u64 instead.
> >
> > Signed-off-by: Wang Qing <wangqing@vivo.com>
> > ---
> >  drivers/net/wireless/ath/wil6210/debugfs.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/net/wireless/ath/wil6210/debugfs.c b/drivers/net/wireless/ath/wil6210/debugfs.c
> > index 4c944e5..2cee9dd
> > --- a/drivers/net/wireless/ath/wil6210/debugfs.c
> > +++ b/drivers/net/wireless/ath/wil6210/debugfs.c
> > @@ -1766,7 +1766,7 @@ __acquires(&p->tid_rx_lock) __releases(&p->tid_rx_lock)
> >  			seq_puts(s, "\n");
> >  			if (!num_packets)
> >  				continue;
> > -			do_div(tx_latency_avg, num_packets);
> > +			div64_u64(tx_latency_avg, num_packets);
> 
> As you have been pointed out in your other patches, do_div() and
> div64_u64() work differently.

And how long does it take for num_packets to exceed 2^32.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-02-11 12:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-09  8:39 [PATCH] net: wireless: ath: use div64_u64() instead of do_div() Qing Wang
2022-02-10  6:40 ` Kalle Valo
2022-02-10 12:16 ` Kalle Valo
2022-02-11 12:23   ` David Laight

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.