Skip to content

Commit

Permalink
irda: irda-usb: Replace timeval with ktime_t
Browse files Browse the repository at this point in the history
The irda usb driver uses 'timeval', which we try to remove in the kernel
because all 32-bit time types will break in the year 2038.

This patch also changes do_gettimeofday() to ktime_get() accordingly,
since ktime_get returns a ktime_t, but do_gettimeofday returns a
struct timeval, and the other reason is that ktime_get() uses
the monotonic clock.

This patch uses ktime_us_delta to get the elapsed time, and in this
way it no longer needs to check for the overflow, because
ktime_us_delta returns time difference of microsecond.

Signed-off-by: Chunyan Zhang <zhang.chunyan@linaro.org>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Chunyan Zhang authored and David S. Miller committed Jan 12, 2015
1 parent 9f61e30 commit ca98278
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
10 changes: 2 additions & 8 deletions drivers/net/irda/irda-usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -495,18 +495,12 @@ static netdev_tx_t irda_usb_hard_xmit(struct sk_buff *skb,
mtt = irda_get_mtt(skb);
if (mtt) {
int diff;
do_gettimeofday(&self->now);
diff = self->now.tv_usec - self->stamp.tv_usec;
diff = ktime_us_delta(ktime_get(), self->stamp);
#ifdef IU_USB_MIN_RTT
/* Factor in USB delays -> Get rid of udelay() that
* would be lost in the noise - Jean II */
diff += IU_USB_MIN_RTT;
#endif /* IU_USB_MIN_RTT */
/* If the usec counter did wraparound, the diff will
* go negative (tv_usec is a long), so we need to
* correct it by one second. Jean II */
if (diff < 0)
diff += 1000000;

/* Check if the mtt is larger than the time we have
* already used by all the protocol processing
Expand Down Expand Up @@ -869,7 +863,7 @@ static void irda_usb_receive(struct urb *urb)
* reduce the min turn time a bit since we will know
* how much time we have used for protocol processing
*/
do_gettimeofday(&self->stamp);
self->stamp = ktime_get();

/* Check if we need to copy the data to a new skb or not.
* For most frames, we use ZeroCopy and pass the already
Expand Down
5 changes: 2 additions & 3 deletions drivers/net/irda/irda-usb.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*
*****************************************************************************/

#include <linux/time.h>
#include <linux/ktime.h>

#include <net/irda/irda.h>
#include <net/irda/irda_device.h> /* struct irlap_cb */
Expand Down Expand Up @@ -157,8 +157,7 @@ struct irda_usb_cb {
char *speed_buff; /* Buffer for speed changes */
char *tx_buff;

struct timeval stamp;
struct timeval now;
ktime_t stamp;

spinlock_t lock; /* For serializing Tx operations */

Expand Down

0 comments on commit ca98278

Please sign in to comment.