public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: simran singhal <singhalsimran0@gmail.com>, forest@alittletooquiet.net
Cc: gregkh@linuxfoundation.org, devel@driverdev.osuosl.org,
	linux-kernel@vger.kernel.org, outreachy-kernel@googlegroups.com
Subject: Re: [PATCH 1/6] staging: vt6655: Compress return logic
Date: Sat, 18 Feb 2017 12:51:15 -0800	[thread overview]
Message-ID: <1487451075.2198.29.camel@perches.com> (raw)
In-Reply-To: <20170218202056.GA3995@singhal-Inspiron-5558>

On Sun, 2017-02-19 at 01:50 +0530, simran singhal wrote:
> Simplify function returns by merging assignment and return into
> one command line.
> Found with Coccinelle
> @@
> local idexpression ret;
> expression e;
> @@
> 
> -ret =
> +return
>      e;
> -return ret;
[]
> diff --git a/drivers/staging/vt6655/card.c b/drivers/staging/vt6655/card.c
[]
> @@ -920,7 +920,7 @@ u64 CARDqGetTSFOffset(unsigned char byRxRate, u64 qwTSF1, u64 qwTSF2)
>  
>  	qwTSFOffset = qwTSF1 - qwTSF2;
>  
> -	return qwTSFOffset;
> +	return qwTSF1 - qwTSF2;
>  }

It's not a problem here but generically, this transformation may
introduce defects when the local idexpression being assigned to
is a smaller type than the return type.  e.g.:

u64 foo(u64 a, u64 b)
{
	u8 bar = a - b;
	return bar;
}

      parent reply	other threads:[~2017-02-18 20:51 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-18 20:20 [PATCH 1/6] staging: vt6655: Compress return logic simran singhal
2017-02-18 20:42 ` [Outreachy kernel] " Julia Lawall
2017-02-18 20:51 ` Joe Perches [this message]

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=1487451075.2198.29.camel@perches.com \
    --to=joe@perches.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=forest@alittletooquiet.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=outreachy-kernel@googlegroups.com \
    --cc=singhalsimran0@gmail.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