public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Dheeraj Reddy Jonnalagadda <dheeraj.linuxdev@gmail.com>,
	mingo@redhat.com, juri.lelli@redhat.com,
	vincent.guittot@linaro.org, linux-kernel@vger.kernel.org,
	dietmar.eggemann@arm.com, bsegall@google.com, mgorman@suse.de,
	vschneid@redhat.com
Subject: Re: [PATCH sched-next] sched/cputime: Fix unused value issue
Date: Tue, 19 Nov 2024 09:36:50 +0100	[thread overview]
Message-ID: <20241119083650.GD11903@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <20241118153047.7e90015f@gandalf.local.home>

On Mon, Nov 18, 2024 at 03:30:47PM -0500, Steven Rostedt wrote:
> On Mon, 18 Nov 2024 16:43:14 +0530
> Dheeraj Reddy Jonnalagadda <dheeraj.linuxdev@gmail.com> 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@gmail.com>
> > ---
> >  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.

There is nothing to fix. Yes there is an unused assignment, but the
compiler is free to elide it (and it does).

Keep the code as is, it is simple and straight-forward.

  reply	other threads:[~2024-11-19  8:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-18 11:13 [PATCH sched-next] sched/cputime: Fix unused value issue Dheeraj Reddy Jonnalagadda
2024-11-18 20:30 ` Steven Rostedt
2024-11-19  8:36   ` Peter Zijlstra [this message]
2024-11-19 13:08     ` Steven Rostedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241119083650.GD11903@noisy.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=bsegall@google.com \
    --cc=dheeraj.linuxdev@gmail.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=rostedt@goodmis.org \
    --cc=vincent.guittot@linaro.org \
    --cc=vschneid@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox