All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2/6] staging: comedi: comedi_fops: Merge if conditions
@ 2016-02-10  8:59 Amitoj Kaur Chawla
  2016-02-10  9:13 ` [Outreachy kernel] " Julia Lawall
  2016-02-12  3:44 ` Greg KH
  0 siblings, 2 replies; 3+ messages in thread
From: Amitoj Kaur Chawla @ 2016-02-10  8:59 UTC (permalink / raw)
  To: outreachy-kernel

Merge if conditions with the same statements.

Found using Coccinelle. The semantic patch used to find this is as
follows:

//<smpl>
@@
statement S;
expression e,x;
@@

* if(e)
(
{ ... return ...; }
&
S
)

* if(x)
(
{ ... return ...; }
&
S
)
//</smpl>

Signed-off-by: Amitoj Kaur Chawla <amitoj1606@gmail.com>
---
 drivers/staging/comedi/comedi_fops.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c
index d57fade..d6bcf73 100644
--- a/drivers/staging/comedi/comedi_fops.c
+++ b/drivers/staging/comedi/comedi_fops.c
@@ -795,9 +795,7 @@ static int is_device_busy(struct comedi_device *dev)
 
 	for (i = 0; i < dev->n_subdevices; i++) {
 		s = &dev->subdevices[i];
-		if (s->busy)
-			return 1;
-		if (s->async && comedi_buf_is_mmapped(s))
+		if (s->busy || (s->async && comedi_buf_is_mmapped(s)))
 			return 1;
 	}
 
@@ -2216,11 +2214,7 @@ static int comedi_mmap(struct file *file, struct vm_area_struct *vma)
 	}
 
 	size = vma->vm_end - vma->vm_start;
-	if (size > async->prealloc_bufsz) {
-		retval = -EFAULT;
-		goto done;
-	}
-	if (size & (~PAGE_MASK)) {
+	if ((size > async->prealloc_bufsz) || (size & (~PAGE_MASK))) {
 		retval = -EFAULT;
 		goto done;
 	}
-- 
1.9.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Outreachy kernel] [PATCH 2/6] staging: comedi: comedi_fops: Merge if conditions
  2016-02-10  8:59 [PATCH 2/6] staging: comedi: comedi_fops: Merge if conditions Amitoj Kaur Chawla
@ 2016-02-10  9:13 ` Julia Lawall
  2016-02-12  3:44 ` Greg KH
  1 sibling, 0 replies; 3+ messages in thread
From: Julia Lawall @ 2016-02-10  9:13 UTC (permalink / raw)
  To: Amitoj Kaur Chawla; +Cc: outreachy-kernel



On Wed, 10 Feb 2016, Amitoj Kaur Chawla wrote:

> Merge if conditions with the same statements.
>
> Found using Coccinelle. The semantic patch used to find this is as
> follows:
>
> //<smpl>
> @@
> statement S;
> expression e,x;
> @@
>
> * if(e)
> (
> { ... return ...; }
> &
> S
> )
>
> * if(x)
> (
> { ... return ...; }
> &
> S
> )
> //</smpl>
>
> Signed-off-by: Amitoj Kaur Chawla <amitoj1606@gmail.com>
> ---
>  drivers/staging/comedi/comedi_fops.c | 10 ++--------
>  1 file changed, 2 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c
> index d57fade..d6bcf73 100644
> --- a/drivers/staging/comedi/comedi_fops.c
> +++ b/drivers/staging/comedi/comedi_fops.c
> @@ -795,9 +795,7 @@ static int is_device_busy(struct comedi_device *dev)
>
>  	for (i = 0; i < dev->n_subdevices; i++) {
>  		s = &dev->subdevices[i];
> -		if (s->busy)
> -			return 1;
> -		if (s->async && comedi_buf_is_mmapped(s))
> +		if (s->busy || (s->async && comedi_buf_is_mmapped(s)))

This one is probably fine as is, with the parentheses.

julia

>  			return 1;
>  	}
>
> @@ -2216,11 +2214,7 @@ static int comedi_mmap(struct file *file, struct vm_area_struct *vma)
>  	}
>
>  	size = vma->vm_end - vma->vm_start;
> -	if (size > async->prealloc_bufsz) {
> -		retval = -EFAULT;
> -		goto done;
> -	}
> -	if (size & (~PAGE_MASK)) {
> +	if ((size > async->prealloc_bufsz) || (size & (~PAGE_MASK))) {
>  		retval = -EFAULT;
>  		goto done;
>  	}
> --
> 1.9.1
>
> --
> You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to outreachy-kernel+unsubscribe@googlegroups.com.
> To post to this group, send email to outreachy-kernel@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20160210085916.GA14597%40amitoj-Inspiron-3542.
> For more options, visit https://groups.google.com/d/optout.
>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Outreachy kernel] [PATCH 2/6] staging: comedi: comedi_fops: Merge if conditions
  2016-02-10  8:59 [PATCH 2/6] staging: comedi: comedi_fops: Merge if conditions Amitoj Kaur Chawla
  2016-02-10  9:13 ` [Outreachy kernel] " Julia Lawall
@ 2016-02-12  3:44 ` Greg KH
  1 sibling, 0 replies; 3+ messages in thread
From: Greg KH @ 2016-02-12  3:44 UTC (permalink / raw)
  To: Amitoj Kaur Chawla; +Cc: outreachy-kernel

On Wed, Feb 10, 2016 at 02:29:16PM +0530, Amitoj Kaur Chawla wrote:
> Merge if conditions with the same statements.
> 
> Found using Coccinelle. The semantic patch used to find this is as
> follows:
> 
> //<smpl>
> @@
> statement S;
> expression e,x;
> @@
> 
> * if(e)
> (
> { ... return ...; }
> &
> S
> )
> 
> * if(x)
> (
> { ... return ...; }
> &
> S
> )
> //</smpl>
> 
> Signed-off-by: Amitoj Kaur Chawla <amitoj1606@gmail.com>
> ---
>  drivers/staging/comedi/comedi_fops.c | 10 ++--------
>  1 file changed, 2 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c
> index d57fade..d6bcf73 100644
> --- a/drivers/staging/comedi/comedi_fops.c
> +++ b/drivers/staging/comedi/comedi_fops.c
> @@ -795,9 +795,7 @@ static int is_device_busy(struct comedi_device *dev)
>  
>  	for (i = 0; i < dev->n_subdevices; i++) {
>  		s = &dev->subdevices[i];
> -		if (s->busy)
> -			return 1;
> -		if (s->async && comedi_buf_is_mmapped(s))
> +		if (s->busy || (s->async && comedi_buf_is_mmapped(s)))
>  			return 1;
>  	}
>  
> @@ -2216,11 +2214,7 @@ static int comedi_mmap(struct file *file, struct vm_area_struct *vma)
>  	}
>  
>  	size = vma->vm_end - vma->vm_start;
> -	if (size > async->prealloc_bufsz) {
> -		retval = -EFAULT;
> -		goto done;
> -	}
> -	if (size & (~PAGE_MASK)) {
> +	if ((size > async->prealloc_bufsz) || (size & (~PAGE_MASK))) {

Personally, I like the original code, it's simpler and easier to read,
why make this more complex?

sorry,

greg k-h


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-02-12  3:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-10  8:59 [PATCH 2/6] staging: comedi: comedi_fops: Merge if conditions Amitoj Kaur Chawla
2016-02-10  9:13 ` [Outreachy kernel] " Julia Lawall
2016-02-12  3:44 ` Greg KH

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.