From: Richard Cochran <richardcochran@gmail.com>
To: Siddaraju D H <siddarajudh@gmail.com>
Cc: john.stultz@linaro.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] ptp/ptp_clock.c: Correct input parameter range check
Date: Wed, 3 Apr 2019 20:14:55 -0700 [thread overview]
Message-ID: <20190404031455.cn4cc5wxbn6izvwe@localhost> (raw)
In-Reply-To: <20190404000958.15236-1-siddarajudh@gmail.com>
On Thu, Apr 04, 2019 at 05:39:58AM +0530, Siddaraju D H wrote:
> From: Siddaraju DH <siddarajudh@gmail.com>
>
> The ealier implementaion used to return EINVAL for -ve adjustments
> in the range -1ns to -999999999ns as these -ve numbers will fail the
> unsigned comaparison against NSEC_PER_SEC. Since the tv_sec field
> will be ZERO in this range, the user will not be able to specify
> the signedness of adjustment through the tv_sec field.
NAK, the tv_sec field can be set to -1. See the example, below.
Thanks,
Richard
void clockadj_step(clockid_t clkid, int64_t step)
{
struct timex tx;
int sign = 1;
if (step < 0) {
sign = -1;
step *= -1;
}
memset(&tx, 0, sizeof(tx));
tx.modes = ADJ_SETOFFSET | ADJ_NANO;
tx.time.tv_sec = sign * (step / NS_PER_SEC);
tx.time.tv_usec = sign * (step % NS_PER_SEC);
/*
* The value of a timeval is the sum of its fields, but the
* field tv_usec must always be non-negative.
*/
if (tx.time.tv_usec < 0) {
tx.time.tv_sec -= 1;
tx.time.tv_usec += 1000000000;
}
if (clock_adjtime(clkid, &tx) < 0)
pr_err("failed to step clock: %m");
}
next prev parent reply other threads:[~2019-04-04 3:15 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-04 0:09 [PATCH] ptp/ptp_clock.c: Correct input parameter range check Siddaraju D H
2019-04-04 3:14 ` Richard Cochran [this message]
2019-04-05 10:23 ` Siddaraju DH
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=20190404031455.cn4cc5wxbn6izvwe@localhost \
--to=richardcochran@gmail.com \
--cc=john.stultz@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=siddarajudh@gmail.com \
/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;
as well as URLs for NNTP newsgroup(s).