[PATCH v2] Staging: dgnc: Replace timeval with ktime_t

7 views
Skip to first unread message

Somya Anand

unread,
Oct 20, 2014, 4:26:19 AM10/20/14
to ar...@arndb.de, opw-k...@googlegroups.com, somyaa...@gmail.com
'timeval' is used to create header timestamps for the data dump.

32-bit systems using 'struct timeval' will break in the year 2038,
So we have to replace that code with more appropriate types.
This patch changes the dgnc driver to use ktime_t instead of timeval.

It uses ktime_get() to get current timestamp. It is better than
do_gettimeofday() as it uses the monotonic clock.

---

Changes since v1:
* Reword commit message
* Fixed line over 80 characters warning on line :471

Signed-off-by: Somya Anand <somyaa...@gmail.com>
---
drivers/staging/dgnc/dgnc_tty.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/dgnc/dgnc_tty.c b/drivers/staging/dgnc/dgnc_tty.c
index 03c1506..340bce8 100644
--- a/drivers/staging/dgnc/dgnc_tty.c
+++ b/drivers/staging/dgnc/dgnc_tty.c
@@ -49,7 +49,7 @@
#include <linux/delay.h> /* For udelay */
#include <linux/uaccess.h> /* For copy_from_user/copy_to_user */
#include <linux/pci.h>
-
+#include <linux/ktime.h>
#include "dgnc_driver.h"
#include "dgnc_tty.h"
#include "dgnc_types.h"
@@ -452,7 +452,7 @@ void dgnc_tty_uninit(struct dgnc_board *brd)
*/
void dgnc_sniff_nowait_nolock(struct channel_t *ch, unsigned char *text, unsigned char *buf, int len)
{
- struct timeval tv;
+ ktime_t kt;
int n;
int r;
int nbuf;
@@ -471,10 +471,10 @@ void dgnc_sniff_nowait_nolock(struct channel_t *ch, unsigned char *text, unsigne
if (!(ch->ch_sniff_flags & SNIFF_OPEN))
goto exit;

- do_gettimeofday(&tv);
-
+ kt = ktime_get();
/* Create our header for data dump */
- p += sprintf(p, "<%ld %ld><%s><", tv.tv_sec, tv.tv_usec, text);
+ p += sprintf(p, "<%llu %llu><%s><", ktime_divns(kt, NSEC_PER_SEC),
+ ktime_to_us(kt), text);
tmpbuflen = p - tmpbuf;

do {
--
1.9.1

Arnd Bergmann

unread,
Oct 20, 2014, 9:33:44 AM10/20/14
to Somya Anand, opw-k...@googlegroups.com
On Monday 20 October 2014 13:56:01 Somya Anand wrote:
> -
> + kt = ktime_get();
> /* Create our header for data dump */
> - p += sprintf(p, "<%ld %ld><%s><", tv.tv_sec, tv.tv_usec, text);
> + p += sprintf(p, "<%llu %llu><%s><", ktime_divns(kt, NSEC_PER_SEC),
> + ktime_to_us(kt), text);
> tmpbuflen = p - tmpbuf;
>

One more instance of the same bug that came up a few times: ktime_to_us
is not the sub-second part of kt, but is instead the entire microseconds.

Moreover, I already commented on this driver when someone asked about
it: The function dgnc_sniff_nowait_nolock writes to a buffer that is
completely unused, and the correct solution is to remove the function
along with all the ch_sniff_* stuff from struct channel_t.

Arnd
Reply all
Reply to author
Forward
0 new messages