drivers/staging/comedi/drivers/me4000.c: adjust suspicious bit operation
authorJulia Lawall <Julia.Lawall@lip6.fr>
Wed, 6 Jun 2012 21:41:36 +0000 (23:41 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 11 Jun 2012 23:54:29 +0000 (16:54 -0700)
TRIG_ROUND_NEAREST is 0, so a bit-and with it is always false.  The
value TRIG_ROUND_MASK covers the bits of the TRIG_ROUND constants, so
first pick those bits and then make the test using ==.

The same is done for TRIG_ROUND_UP for symmetry, even though bit-and would
be sufficient in this case.

This problem was found using Coccinelle (http://coccinelle.lip6.fr/).

Signed-off-by: Julia Lawall <julia@diku.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/comedi/drivers/me4000.c

index cb6bf8c5fb45b0d0e1d62e1b245b39d4efb62b92..09890b8c586ce221be6ae543254d28c06b479903 100644 (file)
@@ -948,10 +948,10 @@ static int ai_round_cmd_args(struct comedi_device *dev,
                *init_ticks = (cmd->start_arg * 33) / 1000;
                rest = (cmd->start_arg * 33) % 1000;
 
-               if (cmd->flags & TRIG_ROUND_NEAREST) {
+               if ((cmd->flags & TRIG_ROUND_MASK) == TRIG_ROUND_NEAREST) {
                        if (rest > 33)
                                (*init_ticks)++;
-               } else if (cmd->flags & TRIG_ROUND_UP) {
+               } else if ((cmd->flags & TRIG_ROUND_MASK) == TRIG_ROUND_UP) {
                        if (rest)
                                (*init_ticks)++;
                }
@@ -961,10 +961,10 @@ static int ai_round_cmd_args(struct comedi_device *dev,
                *scan_ticks = (cmd->scan_begin_arg * 33) / 1000;
                rest = (cmd->scan_begin_arg * 33) % 1000;
 
-               if (cmd->flags & TRIG_ROUND_NEAREST) {
+               if ((cmd->flags & TRIG_ROUND_MASK) == TRIG_ROUND_NEAREST) {
                        if (rest > 33)
                                (*scan_ticks)++;
-               } else if (cmd->flags & TRIG_ROUND_UP) {
+               } else if ((cmd->flags & TRIG_ROUND_MASK) == TRIG_ROUND_UP) {
                        if (rest)
                                (*scan_ticks)++;
                }
@@ -974,10 +974,10 @@ static int ai_round_cmd_args(struct comedi_device *dev,
                *chan_ticks = (cmd->convert_arg * 33) / 1000;
                rest = (cmd->convert_arg * 33) % 1000;
 
-               if (cmd->flags & TRIG_ROUND_NEAREST) {
+               if ((cmd->flags & TRIG_ROUND_MASK) == TRIG_ROUND_NEAREST) {
                        if (rest > 33)
                                (*chan_ticks)++;
-               } else if (cmd->flags & TRIG_ROUND_UP) {
+               } else if ((cmd->flags & TRIG_ROUND_MASK) == TRIG_ROUND_UP) {
                        if (rest)
                                (*chan_ticks)++;
                }