Skip to contentSkip to conversation

staging: comedi: comedi_fops: Merge if conditions

PATCH In review Amitoj Kaur Chawla 3 participants 3 messages Feb 10, 2016 – Feb 12, 2016 Staging

lore
Share & tools
lore
#0 lore raw

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
index d57fade..d6bcf73 100644
@@ -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
#1 lore raw
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>

---
 drivers/staging/comedi/comedi_fops.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)
drivers/staging/comedi/comedi_fops.c +0 -0
index d57fade..d6bcf73 100644

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 -6
 			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 [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.

maintainer
#2 lore raw
In reply to Amitoj Kaur Chawla
Quoted 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>

---
 drivers/staging/comedi/comedi_fops.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)
drivers/staging/comedi/comedi_fops.c +1 -3
index d57fade..d6bcf73 100644
@@ -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