lkml.org 
[lkml]   [2019]   [Apr]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] ptp/ptp_clock.c: Correct input parameter range check
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");
}


\
 
 \ /
  Last update: 2019-04-04 05:16    [W:0.030 / U:0.220 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site