Re: [PATCH sched-next] sched/cputime: Fix unused value issue

From: Steven Rostedt
Date: Mon Nov 18 2024 - 15:30:23 EST


On Mon, 18 Nov 2024 16:43:14 +0530
Dheeraj Reddy Jonnalagadda <dheeraj.linuxdev@xxxxxxxxx> wrote:

> This commit fixes an unused value issue detected by Coverity
> (CID 1357987). The value of utime is updated but has no use as it is
> updated later on without using the stored value.
>
> Signed-off-by: Dheeraj Reddy Jonnalagadda <dheeraj.linuxdev@xxxxxxxxx>
> ---
> kernel/sched/cputime.c | 10 +++-------
> 1 file changed, 3 insertions(+), 7 deletions(-)
>
> diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
> index 0bed0fa1acd9..3dea3636a260 100644
> --- a/kernel/sched/cputime.c
> +++ b/kernel/sched/cputime.c
> @@ -571,13 +571,9 @@ 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;
> - goto update;
> - }
> -
> - if (utime == 0) {
> - stime = rtime;
> + if (stime == 0 || utime == 0) {
> + if (utime == 0)
> + stime = rtime;
> goto update;
> }
>

The above adds more branches than just having:

if (stime == 0)
goto update;

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

(or's "||" are branches)

And the latter is much easier to read!

Just fix the issue. Don't try to be clever about it.

-- Steve