mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] kernel/sched/cputime: Fix unused value in cputime_adjust()
@ 2022-07-20 10:29 zengjx95
  2022-07-20 11:33 ` Peter Zijlstra
  0 siblings, 1 reply; 3+ messages in thread
From: zengjx95 @ 2022-07-20 10:29 UTC (permalink / raw)
  To: mingo, peterz, juri.lelli, vincent.guittot, dietmar.eggemann,
	rostedt, bsegall, mgorman, bristot, vschneid
  Cc: linux-kernel, Zeng Jingxiang

From: Zeng Jingxiang <linuszeng@tencent.com>

Coverity warns uf an unused value:

assigned_value: Assign the value of the variable rtime to utime here,
but that stored value is overwritten before it can be used.
568	if (stime == 0) {
569		utime = rtime;
570		goto update;
571	}

value_overwrite: Overwriting previous write to utime with
the value of expression rtime - stime.
592	utime = rtime - stime;

Signed-off-by: Zeng Jingxiang <linuszeng@tencent.com>
---
 kernel/sched/cputime.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
index 78a233d43757..531df8b29e6d 100644
--- a/kernel/sched/cputime.c
+++ b/kernel/sched/cputime.c
@@ -565,10 +565,8 @@ void cputime_adjust(struct task_cputime *curr, struct prev_cputime *prev,
 	 * Once a task gets some ticks, the monotonicity 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.27.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] kernel/sched/cputime: Fix unused value in cputime_adjust()
  2022-07-20 10:29 [PATCH] kernel/sched/cputime: Fix unused value in cputime_adjust() zengjx95
@ 2022-07-20 11:33 ` Peter Zijlstra
  2022-07-20 12:25   ` jingxiang zeng
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Zijlstra @ 2022-07-20 11:33 UTC (permalink / raw)
  To: zengjx95
  Cc: mingo, juri.lelli, vincent.guittot, dietmar.eggemann, rostedt,
	bsegall, mgorman, bristot, vschneid, linux-kernel,
	Zeng Jingxiang

On Wed, Jul 20, 2022 at 06:29:56PM +0800, zengjx95@gmail.com wrote:
> From: Zeng Jingxiang <linuszeng@tencent.com>
> 
> Coverity warns uf an unused value:
> 
> assigned_value: Assign the value of the variable rtime to utime here,
> but that stored value is overwritten before it can be used.
> 568	if (stime == 0) {
> 569		utime = rtime;
> 570		goto update;
> 571	}
> 
> value_overwrite: Overwriting previous write to utime with
> the value of expression rtime - stime.
> 592	utime = rtime - stime;

Coverity is being daft, the compiler has a dead-store-elimination pass.

This way the code is more consistent / easier to ready.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] kernel/sched/cputime: Fix unused value in cputime_adjust()
  2022-07-20 11:33 ` Peter Zijlstra
@ 2022-07-20 12:25   ` jingxiang zeng
  0 siblings, 0 replies; 3+ messages in thread
From: jingxiang zeng @ 2022-07-20 12:25 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: mingo, juri.lelli, vincent.guittot, dietmar.eggemann, rostedt,
	bsegall, mgorman, bristot, vschneid, linux-kernel,
	Zeng Jingxiang

Peter Zijlstra <peterz@infradead.org> 于2022年7月20日周三 19:33写道:
>
> On Wed, Jul 20, 2022 at 06:29:56PM +0800, zengjx95@gmail.com wrote:
> > From: Zeng Jingxiang <linuszeng@tencent.com>
> >
> > Coverity warns uf an unused value:
> >
> > assigned_value: Assign the value of the variable rtime to utime here,
> > but that stored value is overwritten before it can be used.
> > 568   if (stime == 0) {
> > 569           utime = rtime;
> > 570           goto update;
> > 571   }
> >
> > value_overwrite: Overwriting previous write to utime with
> > the value of expression rtime - stime.
> > 592   utime = rtime - stime;
>
> Coverity is being daft, the compiler has a dead-store-elimination pass.
>
> This way the code is more consistent / easier to ready.


Thank you for your suggestion, I will try it.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-07-20 12:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-20 10:29 [PATCH] kernel/sched/cputime: Fix unused value in cputime_adjust() zengjx95
2022-07-20 11:33 ` Peter Zijlstra
2022-07-20 12:25   ` jingxiang zeng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®