Navigation Menu

Skip to content

Commit

Permalink
net: gptp: Fix unsigned value comparison
Browse files Browse the repository at this point in the history
The nanosecond check was using <0 for unsigned value.

Coverity-CID: 187080
Fixes #8987

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
  • Loading branch information
jukkar authored and nashif committed Jul 20, 2018
1 parent 81a2c4b commit 4670214
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion subsys/net/l2/ethernet/gptp/gptp_mi.c
Expand Up @@ -707,11 +707,21 @@ static void gptp_update_local_port_clock(void)
if (second_diff || (second_diff == 0 &&
(nanosecond_diff < -5000 ||
nanosecond_diff > 5000))) {
bool underflow = false;

key = irq_lock();
ptp_clock_get(clk, &tm);

tm.second += second_diff;

if (nanosecond_diff < 0 &&
tm.nanosecond < -nanosecond_diff) {
underflow = true;
}

tm.nanosecond += nanosecond_diff;
if (tm.nanosecond < 0) {

if (underflow) {
tm.second--;
tm.nanosecond += NSEC_PER_SEC;
} else if (tm.nanosecond >= NSEC_PER_SEC) {
Expand Down

0 comments on commit 4670214

Please sign in to comment.