Skip to content

Commit

Permalink
drivers/net/wireless: Use DIV_ROUND_CLOSEST
Browse files Browse the repository at this point in the history
The kernel.h macro DIV_ROUND_CLOSEST performs the computation (x + d/2)/d
but is perhaps more readable.

The semantic patch that makes this change is as follows:
(http://www.emn.fr/x-info/coccinelle/)

// <smpl>
@haskernel@
@@

#include <linux/kernel.h>

@depends on haskernel@
expression x,__divisor;
@@

- (((x) + ((__divisor) / 2)) / (__divisor))
+ DIV_ROUND_CLOSEST(x,__divisor)
// </smpl>

Signed-off-by: Julia Lawall <julia@diku.dk>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
  • Loading branch information
Julia Lawall authored and John W. Linville committed Aug 4, 2009
1 parent 2c8d510 commit 87cdb98
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions drivers/net/wireless/strip.c
Original file line number Diff line number Diff line change
Expand Up @@ -1550,9 +1550,12 @@ static int strip_xmit(struct sk_buff *skb, struct net_device *dev)

if (time_after(jiffies, strip_info->pps_timer + HZ)) {
unsigned long t = jiffies - strip_info->pps_timer;
unsigned long rx_pps_count = (strip_info->rx_pps_count * HZ * 8 + t / 2) / t;
unsigned long tx_pps_count = (strip_info->tx_pps_count * HZ * 8 + t / 2) / t;
unsigned long sx_pps_count = (strip_info->sx_pps_count * HZ * 8 + t / 2) / t;
unsigned long rx_pps_count =
DIV_ROUND_CLOSEST(strip_info->rx_pps_count*HZ*8, t);
unsigned long tx_pps_count =
DIV_ROUND_CLOSEST(strip_info->tx_pps_count*HZ*8, t);
unsigned long sx_pps_count =
DIV_ROUND_CLOSEST(strip_info->sx_pps_count*HZ*8, t);

strip_info->pps_timer = jiffies;
strip_info->rx_pps_count = 0;
Expand Down

0 comments on commit 87cdb98

Please sign in to comment.