2015-07-26 17:34:20

by Shraddha Barke

[permalink] [raw]
Subject: [PATCH] Staging:dgap :Compression of lines for immediate return

This patch compresses two lines into a single line if immediate return statement
is found. Also,remove variable rc as it is no longer needed.
It is done using tool Coccinelle. And semantic patch used for this is as follows:

@@
expression ret;
identifier f;
@@

-ret =
+return
f(...);
-return ret;
---
drivers/staging/dgap/dgap.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/staging/dgap/dgap.c b/drivers/staging/dgap/dgap.c
index 26b0446..2bb6c68 100644
--- a/drivers/staging/dgap/dgap.c
+++ b/drivers/staging/dgap/dgap.c
@@ -4953,9 +4953,8 @@ static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
spin_unlock_irqrestore(&bd->bd_lock, lock_flags);

- rc = put_user(C_CLOCAL(tty) ? 1 : 0,
+ return put_user(C_CLOCAL(tty) ? 1 : 0,
(unsigned long __user *) arg);
- return rc;

case TIOCSSOFTCAR:
spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
--
2.1.0


2015-07-26 19:39:28

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH] Staging:dgap :Compression of lines for immediate return

On Sun, 2015-07-26 at 23:04 +0530, Shraddha Barke wrote:
> This patch compresses two lines into a single line if immediate return statement
> is found. Also,remove variable rc as it is no longer needed.
> It is done using tool Coccinelle. And semantic patch used for this is as follows:
>
> @@
> expression ret;
> identifier f;
> @@
> -ret =
> +return
> f(...);
> -return ret;

This isn't an always safe or side-effect free
semantic patch as there may be a cast lost by
such a conversion.

int foo(void)
{
char i = 0xffffffff;
return i;
}

where i is now int not char

2015-07-27 04:31:00

by Sudip Mukherjee

[permalink] [raw]
Subject: Re: [PATCH] Staging:dgap :Compression of lines for immediate return

On Sun, Jul 26, 2015 at 11:04:13PM +0530, Shraddha Barke wrote:
> This patch compresses two lines into a single line if immediate return statement
> is found. Also,remove variable rc as it is no longer needed.
> It is done using tool Coccinelle. And semantic patch used for this is as follows:
>
> @@
> expression ret;
> identifier f;
> @@
>
> -ret =
> +return
> f(...);
> -return ret;
> ---
Missed the Signed-off-by: here also, and always add the maintainers in
your To: list.

regards
sudip