From: Zeng Jingxiang <[email protected]>
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 <[email protected]>
---
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
On Wed, Jul 20, 2022 at 06:29:56PM +0800, [email protected] wrote:
> From: Zeng Jingxiang <[email protected]>
>
> 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.
Peter Zijlstra <[email protected]> 于2022年7月20日周三 19:33写道:
>
> On Wed, Jul 20, 2022 at 06:29:56PM +0800, [email protected] wrote:
> > From: Zeng Jingxiang <[email protected]>
> >
> > 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.