Skip to contentSkip to conversation

staging: comedi: drivers: use comedi_dio_update_state() for complex cases

DISCUSSION Dave Jones 2 participants 6 messages Nov 8, 2013 – Nov 27, 2013 1 message not in the archive Staging

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Dave Jones

author
#1 lore raw
Quoted 10 lines · Linux Kernel
Gitweb:     http://git.kernel.org/linus/;a=commit;h=b3ff824a81e8978deb56f6d163479c1a0a606037
Commit:     b3ff824a81e8978deb56f6d163479c1a0a606037
Parent:     97f4289ad08cffe55de06d4ac4f89ac540450aee
Author:     H Hartley Sweeten <[email protected]>
AuthorDate: Fri Aug 30 11:06:17 2013 -0700
Committer:  Greg Kroah-Hartman <[email protected]>
CommitDate: Tue Sep 17 07:47:40 2013 -0700

staging: comedi: drivers: use comedi_dio_update_state() for complex cases

Quoted 7 lines

Use comedi_dio_update_state() to handle the boilerplate code to update the subdevice s->state for more complex cases where the hardware is only updated based on the 'mask' of the channels that are modified.

This bit looks suspect :-

Quoted 6 lines
(quoted diff) +0 -3
 	if (mask) {
-		s->state &= ~mask;
-		s->state |= (bits & mask);
-
 		if (mask & 0x00ff)
 			outb(s->state & 0xff, dev->iobase + reg);

Review

Quoted 10 lines
(quoted diff) +3 -3
-		if ((mask & 0xff00) && (s->n_chan > 8))
+		if ((mask & 0xff00) & (s->n_chan > 8))
 			outb((s->state >> 8) & 0xff, dev->iobase + reg + 1);
-		if ((mask & 0xff0000) && (s->n_chan > 16))
+		if ((mask & 0xff0000) & (s->n_chan > 16))
 			outb((s->state >> 16) & 0xff, dev->iobase + reg + 2);
-		if ((mask & 0xff000000) && (s->n_chan > 24))
+		if ((mask & 0xff000000) & (s->n_chan > 24))
 			outb((s->state >> 24) & 0xff, dev->iobase + reg + 3);
 	}

should those be shifts ? Like so ?

drivers/staging/comedi/drivers/pcl730.c +3 -3
index d041b714db29..29a54e5d73d6 100644
@@ -173,11 +173,11 @@ static int pcl730_do_insn_bits(struct comedi_device *dev,
 	if (mask) {
 		if (mask & 0x00ff)
 			outb(s->state & 0xff, dev->iobase + reg);
-		if ((mask & 0xff00) & (s->n_chan > 8))
+		if ((mask & 0xff00) & (s->n_chan >> 8))
 			outb((s->state >> 8) & 0xff, dev->iobase + reg + 1);
-		if ((mask & 0xff0000) & (s->n_chan > 16))
+		if ((mask & 0xff0000) & (s->n_chan >> 16))
 			outb((s->state >> 16) & 0xff, dev->iobase + reg + 2);
-		if ((mask & 0xff000000) & (s->n_chan > 24))
+		if ((mask & 0xff000000) & (s->n_chan >> 24))
 			outb((s->state >> 24) & 0xff, dev->iobase + reg + 3);
 	}
 
#2 lore raw
Quoted 50 lines · Dave Jones
Quoted 10 lines · Linux Kernel
Gitweb:     http://git.kernel.org/linus/;a=commit;h=b3ff824a81e8978deb56f6d163479c1a0a606037
Commit:     b3ff824a81e8978deb56f6d163479c1a0a606037
Parent:     97f4289ad08cffe55de06d4ac4f89ac540450aee
Author:     H Hartley Sweeten <[email protected]>
AuthorDate: Fri Aug 30 11:06:17 2013 -0700
Committer:  Greg Kroah-Hartman <[email protected]>
CommitDate: Tue Sep 17 07:47:40 2013 -0700

staging: comedi: drivers: use comedi_dio_update_state() for complex cases

Quoted 7 lines

Use comedi_dio_update_state() to handle the boilerplate code to update the subdevice s->state for more complex cases where the hardware is only updated based on the 'mask' of the channels that are modified.

This bit looks suspect :-

Quoted 6 lines
(quoted diff) +0 -3
 	if (mask) {
-		s->state &= ~mask;
-		s->state |= (bits & mask);
-
 		if (mask & 0x00ff)
 			outb(s->state & 0xff, dev->iobase + reg);

Review

Quoted 10 lines
(quoted diff) +3 -3
-		if ((mask & 0xff00) && (s->n_chan > 8))
+		if ((mask & 0xff00) & (s->n_chan > 8))
 			outb((s->state >> 8) & 0xff, dev->iobase + reg + 1);
-		if ((mask & 0xff0000) && (s->n_chan > 16))
+		if ((mask & 0xff0000) & (s->n_chan > 16))
 			outb((s->state >> 16) & 0xff, dev->iobase + reg + 2);
-		if ((mask & 0xff000000) && (s->n_chan > 24))
+		if ((mask & 0xff000000) & (s->n_chan > 24))
 			outb((s->state >> 24) & 0xff, dev->iobase + reg + 3);
 	}

should those be shifts ? Like so ?

drivers/staging/comedi/drivers/pcl730.c +0 -0
index d041b714db29..29a54e5d73d6 100644
@@ -173,11 +173,11 @@ static int pcl730_do_insn_bits(struct comedi_device *dev,
 	if (mask) {
 		if (mask & 0x00ff)
  			outb(s->state & 0xff, dev->iobase + reg);

drivers/staging/comedi/drivers/pcl730.c static int pcl730_do_insn_bits(struct comedi_device *dev, · line 182

Quoted 10 lines
drivers/staging/comedi/drivers/pcl730.c +3 -3
-		if ((mask & 0xff00) & (s->n_chan > 8))
+		if ((mask & 0xff00) & (s->n_chan >> 8))
 			outb((s->state >> 8) & 0xff, dev->iobase + reg + 1);
-		if ((mask & 0xff0000) & (s->n_chan > 16))
+		if ((mask & 0xff0000) & (s->n_chan >> 16))
 			outb((s->state >> 16) & 0xff, dev->iobase + reg + 2);
-		if ((mask & 0xff000000) & (s->n_chan > 24))
+		if ((mask & 0xff000000) & (s->n_chan >> 24))
 			outb((s->state >> 24) & 0xff, dev->iobase + reg + 3);
 	}

No, they should not be bit-shifts.

But, there is a bug here. The if tests should be like this:

		if ((mask & 0xff00) && (s->n_chan > 8))

Sorry about that.

Do you want to post a patch? If I don't see one in the next couple days I'll fix it.

Regards,
Hartley

author
#3 lore raw

staging: comedi: Fix boolean/logical and mix-up.

Introduced in commit b3ff824a81e8.

drivers/staging/comedi/drivers/pcl730.c +3 -3
index d041b714db29..2baaf1db6fbf 100644
@@ -173,11 +173,11 @@ static int pcl730_do_insn_bits(struct comedi_device *dev,
 	if (mask) {
 		if (mask & 0x00ff)
 			outb(s->state & 0xff, dev->iobase + reg);
-		if ((mask & 0xff00) & (s->n_chan > 8))
+		if ((mask & 0xff00) && (s->n_chan > 8))
 			outb((s->state >> 8) & 0xff, dev->iobase + reg + 1);
-		if ((mask & 0xff0000) & (s->n_chan > 16))
+		if ((mask & 0xff0000) && (s->n_chan > 16))
 			outb((s->state >> 16) & 0xff, dev->iobase + reg + 2);
-		if ((mask & 0xff000000) & (s->n_chan > 24))
+		if ((mask & 0xff000000) && (s->n_chan > 24))
 			outb((s->state >> 24) & 0xff, dev->iobase + reg + 3);
 	}
 
Acked-by H Hartley Sweeten
#4 lore raw

RE: staging: comedi: Fix boolean/logical and mix-up.

Quoted 12 lines · Dave Jones

Introduced in commit b3ff824a81e8.

drivers/staging/comedi/drivers/pcl730.c +0 -0
index d041b714db29..2baaf1db6fbf 100644
@@ -173,11 +173,11 @@ static int pcl730_do_insn_bits(struct comedi_device *dev,
 	if (mask) {
 		if (mask & 0x00ff)
 			outb(s->state & 0xff, dev->iobase + reg);

drivers/staging/comedi/drivers/pcl730.c static int pcl730_do_insn_bits(struct comedi_device *dev, · line 182

Quoted 10 lines
drivers/staging/comedi/drivers/pcl730.c +3 -3
-		if ((mask & 0xff00) & (s->n_chan > 8))
+		if ((mask & 0xff00) && (s->n_chan > 8))
 			outb((s->state >> 8) & 0xff, dev->iobase + reg + 1);
-		if ((mask & 0xff0000) & (s->n_chan > 16))
+		if ((mask & 0xff0000) && (s->n_chan > 16))
 			outb((s->state >> 16) & 0xff, dev->iobase + reg + 2);
-		if ((mask & 0xff000000) & (s->n_chan > 24))
+		if ((mask & 0xff000000) && (s->n_chan > 24))
 			outb((s->state >> 24) & 0xff, dev->iobase + reg + 3);
 	}

My bad...

Added Greg KH and the staging devel list to the CCs.

#5 lore raw

RE: staging: comedi: Fix boolean/logical and mix-up.

Quoted 26 lines · Hartley Sweeten
Quoted 12 lines · Dave Jones

Introduced in commit b3ff824a81e8.

drivers/staging/comedi/drivers/pcl730.c +0 -0
index d041b714db29..2baaf1db6fbf 100644
@@ -173,11 +173,11 @@ static int pcl730_do_insn_bits(struct comedi_device *dev,
 	if (mask) {
 		if (mask & 0x00ff)
 			outb(s->state & 0xff, dev->iobase + reg);

drivers/staging/comedi/drivers/pcl730.c static int pcl730_do_insn_bits(struct comedi_device *dev, · line 182

Quoted 10 lines
drivers/staging/comedi/drivers/pcl730.c +3 -3
-		if ((mask & 0xff00) & (s->n_chan > 8))
+		if ((mask & 0xff00) && (s->n_chan > 8))
 			outb((s->state >> 8) & 0xff, dev->iobase + reg + 1);
-		if ((mask & 0xff0000) & (s->n_chan > 16))
+		if ((mask & 0xff0000) && (s->n_chan > 16))
 			outb((s->state >> 16) & 0xff, dev->iobase + reg + 2);
-		if ((mask & 0xff000000) & (s->n_chan > 24))
+		if ((mask & 0xff000000) && (s->n_chan > 24))
 			outb((s->state >> 24) & 0xff, dev->iobase + reg + 3);
 	}

My bad...

Quoted 3 lines

Added Greg KH and the staging devel list to the CCs.

Dave,

I just noticed that Dan Carpenter already submitted a patch that fixed this. It was merged as commit 9382c06e2d192adec090fb09ff0b699e951f88e1.

Hartley
_______________________________________________
devel mailing list
[email protected]
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

author
#6 lore raw

Re: staging: comedi: Fix boolean/logical and mix-up.

Quoted 4 lines · Hartley Sweeten
Quoted 1 line

Added Greg KH and the staging devel list to the CCs.

I just noticed that Dan Carpenter already submitted a patch that fixed this. It was merged as commit 9382c06e2d192adec090fb09ff0b699e951f88e1.

Ah, I didn't look at -next.

thanks,

Dave