public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@arndb.de>
To: Tina Ruchandani <ruchandani.tina@gmail.com>
Cc: Karsten Keil <isdn@linux-pingi.de>,
	netdev@vger.kernel.org, y2038@lists.linaro.org
Subject: Re: [PATCH] isdn: Use ktime_t instead of 'struct timeval'
Date: Mon, 11 May 2015 17:31:39 +0200	[thread overview]
Message-ID: <3634168.ue6qDafuIU@wuerfel> (raw)
In-Reply-To: <20150511023257.GA2612@tinar>

On Monday 11 May 2015 08:02:57 Tina Ruchandani wrote:

> -			do_gettimeofday(&tv_now);
> -		elapsed_sec = tv_now.tv_sec - iclock_tv.tv_sec;
> -		elapsed_8000th = (tv_now.tv_usec / 125)
> -			- (iclock_tv.tv_usec / 125);
> -		if (elapsed_8000th < 0) {
> -			elapsed_sec -= 1;
> -			elapsed_8000th += 8000;
> -		}
> +			tv_now = ktime_get();

A minor coding style comment here: If you have a multi-line
block after if() using curly braces, then you should also use
that for the else path, even if that is just one line.

However, if both sides do not need curly braces, leave them
out entirely.

> +		delta = ktime_to_us(ktime_sub(tv_now, iclock_tv));

We have a ktime_us_delta() function now that would simplify this
slightly.

> +		delta = delta / 125;

This looks like a possible bug: delta is a 16-bit number, so it will
be truncated to 65536 microseconds when assigning the result of
ktime_us_delta() or ktime_to_us(), and then you divide by 125, so
it will now be a number that is smaller than 524, and if the elapsed
time is more than 65536 microseconds, you can an incorrect result.

You can avoid that by using a 32-bit temporary, or doing it
implicitly as

	delta = ktime_us_delta(tv_now, iclock_tv) / 125;

Another option would be to calculate the right number from the
nanoseconds:

	delta = ktime_divns(ktime_sub(tv_now, iclock_tv), (NS_PER_SEC / 8000));

	Arnd

      reply	other threads:[~2015-05-11 15:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-11  2:32 [PATCH] isdn: Use ktime_t instead of 'struct timeval' Tina Ruchandani
2015-05-11 15:31 ` Arnd Bergmann [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3634168.ue6qDafuIU@wuerfel \
    --to=arnd@arndb.de \
    --cc=isdn@linux-pingi.de \
    --cc=netdev@vger.kernel.org \
    --cc=ruchandani.tina@gmail.com \
    --cc=y2038@lists.linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox