Skip to contentSkip to conversation

sched/cputime: Remove unnecessary assignment statement

PATCH In review Ketan Patil 4 participants 7 messages Feb 27, 2019 – Feb 28, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sched/cputime: Remove unnecessary assignment statement

The original code assigns the value from rtime to utime variable, and then jumps to the update label. And the value of utime is then updated, so the earlier value of utime is not used. Hence remove that unnecessary assignment statement.

This fixes one of the coverity defects.

Based on work by Ishan Mittal <[email protected]>

---
 kernel/sched/cputime.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
kernel/sched/cputime.c +1 -3
index ba4a143..ad64771 100644
@@ -616,10 +616,8 @@ void cputime_adjust(struct task_cputime *curr, struct prev_cputime *prev,
 	 * Once a task gets some ticks, the monotonicy code at 'update:'
 	 * will ensure things converge to the observed ratio.
 	 */
-	if (stime == 0) {
-		utime = rtime;
+	if (stime == 0)
 		goto update;
-	}
 
 	if (utime == 0) {
 		stime = rtime;
Signature · 1 line
2.7.4
maintainer
#1 lore raw
Quoted 6 lines · Ketan Patil

The original code assigns the value from rtime to utime variable, and then jumps to the update label. And the value of utime is then updated, so the earlier value of utime is not used. Hence remove that unnecessary assignment statement.

This fixes one of the coverity defects.

Why does coverity care? I like the way the code is now, it makes conceptual sense. Removing that assignment makes the code harder to read and less symmetric (see the utime case right below).

Any sensible compiler will 'fix' this for us anyway.

Quoted 22 lines

Based on work by Ishan Mittal <[email protected]>

---
 kernel/sched/cputime.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
kernel/sched/cputime.c +1 -3
index ba4a143..ad64771 100644
@@ -616,10 +616,8 @@ void cputime_adjust(struct task_cputime *curr, struct prev_cputime *prev,
 	 * Once a task gets some ticks, the monotonicy code at 'update:'
 	 * will ensure things converge to the observed ratio.
 	 */
-	if (stime == 0) {
-		utime = rtime;
+	if (stime == 0)
 		goto update;
-	}
 
 	if (utime == 0) {
 		stime = rtime;
#2 lore raw

The coverity tool has detected this issue as an unused value, since

the code assigns the value to utime variable and then after the jump, the

value of utime again gets updated, hence the previous value is not at all

useful and this patch removes that first assignment.

Quoted 35 lines · Peter Zijlstra
Quoted 6 lines · Ketan Patil

The original code assigns the value from rtime to utime variable, and then jumps to the update label. And the value of utime is then updated, so the earlier value of utime is not used. Hence remove that unnecessary assignment statement.

This fixes one of the coverity defects.

Why does coverity care? I like the way the code is now, it makes conceptual sense. Removing that assignment makes the code harder to read and less symmetric (see the utime case right below).

Any sensible compiler will 'fix' this for us anyway.

Quoted 22 lines

Based on work by Ishan Mittal <[email protected]>

---
  kernel/sched/cputime.c | 4 +---
  1 file changed, 1 insertion(+), 3 deletions(-)
kernel/sched/cputime.c +1 -3
index ba4a143..ad64771 100644
@@ -616,10 +616,8 @@ void cputime_adjust(struct task_cputime *curr, struct prev_cputime *prev,
  	 * Once a task gets some ticks, the monotonicy code at 'update:'
  	 * will ensure things converge to the observed ratio.
  	 */
-	if (stime == 0) {
-		utime = rtime;
+	if (stime == 0)
  		goto update;
-	}
 
  	if (utime == 0) {
  		stime = rtime;
maintainer
#3 lore raw

A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?

Quoted 4 lines · Ketan Patil

The coverity tool has detected this issue as an unused value, since the code assigns the value to utime variable and then after the jump, the value of utime again gets updated, hence the previous value is not at all useful and this patch removes that first assignment.

Not a security issue then; just tell coverity to shut up.

#4 lore raw

Ketan,
What is the Coverity Impact Level for this defect? If it is Low then we can whitelist this defect and change.

Peter,
This isn't a security fix.
However, I see this is kind of code cleanup.

-----Original Message-----
From: Peter Zijlstra <[email protected]>
Sent: Thursday, February 28, 2019 3:18 PM
To: Ketan Patil <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; Sachin Nikam <[email protected]>; Bharat Nihalani <[email protected]>; Bo Yan <[email protected]>; Sai Gurrappadi <[email protected]>; Thierry Reding <[email protected]>; Timo Alho <[email protected]>
Subject: Re: [PATCH] sched/cputime: Remove unnecessary assignment statement

A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?

Quoted 4 lines · Ketan Patil

The coverity tool has detected this issue as an unused value, since the code assigns the value to utime variable and then after the jump, the value of utime again gets updated, hence the previous value is not at all useful and this patch removes that first assignment.

Not a security issue then; just tell coverity to shut up.

maintainer
#5 lore raw

Clearly, because reading comprehension isn't your strong point:

A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?

Quoted 2 lines · Sachin Nikam

This isn't a security fix.
However, I see this is kind of code cleanup.

As I've explained previously, it makes conceptual sense to have it in the code, and any halfway sane compiler will observe the same double store and eliminate it in its DCE pass.

maintainer
#6 lore raw
Quoted 7 lines · Peter Zijlstra

Clearly, because reading comprehension isn't your strong point:

A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?

Sorry we have a few people helping out cleaning up our kernel branches and we need to do a better job here indeed!

Quoted 8 lines · Sachin Nikam
Quoted 3 lines

This isn't a security fix.
However, I see this is kind of code cleanup.

As I've explained previously, it makes conceptual sense to have it in the code, and any halfway sane compiler will observe the same double store and eliminate it in its DCE pass.

OK. Thanks for the feedback. We can agree to drop this and we will try to do a better job reviewing this type of thing before hand in future.

Cheers
Jon

Signature · 1 line
nvpublic