Skip to content

Commit

Permalink
sched/cputime: Refactor the cputime_adjust() code
Browse files Browse the repository at this point in the history
Address a Coverity false positive, which is caused by overly
convoluted code:

Value assigned to variable 'utime' at line 619:utime = rtime;
is overwritten at line 642:utime = rtime - stime; before it
can be used. This makes such variable assignment useless.

Remove this variable assignment and refactor the code related.

Addresses-Coverity-ID: 1371643
Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
Cc: Frans Klaver <fransklaver@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rik van Riel <riel@redhat.com>
Cc: Stanislaw Gruszka <sgruszka@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wanpeng Li <wanpeng.li@hotmail.com>
Link: http://lkml.kernel.org/r/20170629184128.GA5271@embeddedgus
Signed-off-by: Ingo Molnar <mingo@kernel.org>
  • Loading branch information
Gustavo A. R. Silva authored and Ingo Molnar committed Jun 30, 2017
1 parent 48365b3 commit 72298e5
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions kernel/sched/cputime.c
Original file line number Diff line number Diff line change
Expand Up @@ -615,19 +615,13 @@ static void cputime_adjust(struct task_cputime *curr,
* userspace. Once a task gets some ticks, the monotonicy code at
* 'update' will ensure things converge to the observed ratio.
*/
if (stime == 0) {
utime = rtime;
goto update;
if (stime != 0) {
if (utime == 0)
stime = rtime;
else
stime = scale_stime(stime, rtime, stime + utime);
}

if (utime == 0) {
stime = rtime;
goto update;
}

stime = scale_stime(stime, rtime, stime + utime);

update:
/*
* Make sure stime doesn't go backwards; this preserves monotonicity
* for utime because rtime is monotonic.
Expand Down

0 comments on commit 72298e5

Please sign in to comment.