staging: comedi: comedi_fops: Merge if conditions
PATCH 2/6 staging: comedi: comedi_fops: Merge if conditions
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>
--- drivers/staging/comedi/comedi_fops.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)
drivers/staging/comedi/comedi_fops.c +2 -8
@@ -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; }
Signature · 1 line
1.9.1
Quoted 36 lines · Amitoj Kaur Chawla
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 <[email protected]>--- drivers/staging/comedi/comedi_fops.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)drivers/staging/comedi/comedi_fops.c +0
-0
drivers/staging/comedi/comedi_fops.c static int is_device_busy(struct comedi_device *dev) · line 798
Quoted 7 lines
drivers/staging/comedi/comedi_fops.c +1
-3@@ -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
Quoted 26 lines
drivers/staging/comedi/comedi_fops.c +1
-6return 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 [email protected]. To post to this group, send email to [email protected].
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.
Greg KH
maintainerQuoted 47 lines · Amitoj Kaur Chawla
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 <[email protected]>--- drivers/staging/comedi/comedi_fops.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)drivers/staging/comedi/comedi_fops.c +1
-3@@ -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 ; }
drivers/staging/comedi/comedi_fops.c static int comedi_mmap(struct file *file, struct vm_area_struct *vma) · line 2217
Quoted 9 lines
drivers/staging/comedi/comedi_fops.c +1
-5@@ -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