Skip to contentSkip to conversation

net: wireless: ath: use div64_u64() instead of do_div()

PATCH In review Qing Wang 3 participants 4 messages Feb 9, 2022 – Feb 11, 2022

Subsystems (3)
lore
Share & tools
lore

Qing Wang

author
#0 lore raw

PATCH 1/1 net: wireless: ath: use div64_u64() instead of do_div()

From: Wang Qing <[email protected]>

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.

---
 drivers/net/wireless/ath/wil6210/debugfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/ath/wil6210/debugfs.c +1 -1
index 4c944e5..2cee9dd
@@ -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,
Signature · 1 line
2.7.4
#1 lore raw
Quoted 6 lines · Qing Wang

From: Wang Qing <[email protected]>

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.

Quoted 7 lines

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

---
 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.

Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/list/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
#2 lore raw
In reply to Qing Wang
Quoted 19 lines · Qing Wang

From: Wang Qing <[email protected]>

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.

---
 drivers/net/wireless/ath/wil6210/debugfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/ath/wil6210/debugfs.c +0 -0
index 4c944e5..2cee9dd

drivers/net/wireless/ath/wil6210/debugfs.c __acquires(&p->tid_rx_lock) __releases(&p->tid_rx_lock) · line 1769

Quoted 5 lines
drivers/net/wireless/ath/wil6210/debugfs.c +1 -1
@@ -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.

Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/list/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
#3 lore raw

From: Kalle Valo

Quoted 18 lines

Sent: 10 February 2022 12:16

Quoted 14 lines · Qing Wang

From: Wang Qing <[email protected]>

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.

---
 drivers/net/wireless/ath/wil6210/debugfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

drivers/net/wireless/ath/wil6210/debugfs.c __acquires(&p->tid_rx_lock) __releases(&p->tid_rx_lock) · line 1769

Quoted 10 lines
drivers/net/wireless/ath/wil6210/debugfs.c +1 -1
index 4c944e5..2cee9dd
@@ -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)