]> git.karo-electronics.de Git - linux-beck.git/commitdiff
staging: comedi: ni_atmio16d.c: remove pointless condition
authorAndrey Utkin <andrey.krieger.utkin@gmail.com>
Fri, 11 Jul 2014 14:38:30 +0000 (15:38 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 12 Jul 2014 00:40:06 +0000 (17:40 -0700)
The issue was discovered with static analysis and has two instances in
this file. The code looks like this
if (x < 65536000) {
...
} else if (x < 655360000) {
...
} else if (x <= 0xffffffff /* 6553600000 */) {
...
} else if (x <= 0xffffffff /* 65536000000 */) {
...
}

The meaning of this block is to select appropriate clock frequency for
interval timer basing on "x", which is amount of time.

Notes:
1. That last condition matches previous one - that's the issue.
2. Decimal numbers in comments don't match hex numbers in expressions.
But in first case the numbers have same order, while in the second case
the hex number is the same, and the decimal one is 10 times bigger.
3. Actually type of "x" is "unsigned int", so its exact upper limit is
not obviously known.
4. There's no "else" block.

So it makes sense to make an "else" block from last "else if" case. The
code inside the block seems correct for such usage.

[ Actually, get rid of the final "else if" case and change the
next-to-last "else if" case to an "else" as the upper limit of "x" _is_
known to be 0xffffffff (UINT_MAX), which is less than 6553600000 -- Ian ]

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=79871
Reported-by: David Binderman <dcb314@hotmail.com>
Signed-off-by: Andrey Utkin <andrey.krieger.utkin@gmail.com>
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/comedi/drivers/ni_atmio16d.c

index 6ad27f50c6ecb28561aae9845a7343eaa97e2c45..b1b4744bc42e8bf1ee5674abe27ba18cc160ac3f 100644 (file)
@@ -335,12 +335,9 @@ static int atmio16d_ai_cmd(struct comedi_device *dev,
        } else if (cmd->convert_arg < 655360000) {
                base_clock = CLOCK_100_KHZ;
                timer = cmd->convert_arg / 10000;
-       } else if (cmd->convert_arg <= 0xffffffff /* 6553600000 */) {
+       } else /* cmd->convert_arg < 6553600000 */ {
                base_clock = CLOCK_10_KHZ;
                timer = cmd->convert_arg / 100000;
-       } else if (cmd->convert_arg <= 0xffffffff /* 65536000000 */) {
-               base_clock = CLOCK_1_KHZ;
-               timer = cmd->convert_arg / 1000000;
        }
        outw(0xFF03, dev->iobase + AM9513A_COM_REG);
        outw(base_clock, dev->iobase + AM9513A_DATA_REG);
@@ -403,12 +400,9 @@ static int atmio16d_ai_cmd(struct comedi_device *dev,
                } else if (cmd->scan_begin_arg < 655360000) {
                        base_clock = CLOCK_100_KHZ;
                        timer = cmd->scan_begin_arg / 10000;
-               } else if (cmd->scan_begin_arg < 0xffffffff /* 6553600000 */) {
+               } else /* cmd->scan_begin_arg < 6553600000 */ {
                        base_clock = CLOCK_10_KHZ;
                        timer = cmd->scan_begin_arg / 100000;
-               } else if (cmd->scan_begin_arg < 0xffffffff /* 65536000000 */) {
-                       base_clock = CLOCK_1_KHZ;
-                       timer = cmd->scan_begin_arg / 1000000;
                }
                outw(0xFF02, dev->iobase + AM9513A_COM_REG);
                outw(base_clock, dev->iobase + AM9513A_DATA_REG);