staging: comedi: drivers: correct mode check for i8254_set_mode()
authorIan Abbott <abbotti@mev.co.uk>
Thu, 1 May 2014 16:38:23 +0000 (17:38 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 4 May 2014 00:08:56 +0000 (20:08 -0400)
The upper bound check on the `mode` parameter of `i8254_set_mode()` and
`i8254_mm_set_mode()` is incorrect.  The `mode` parameter value consists
of a mode number in the range 0 to 5 in bits 3..1 {represented by the
constants `I8254_MODE0` (0 << 1) through to `I8254_MODE5` (2 << 1)} ORed
with a BCD/binary flag in bit 0 {represented by the constants
`I8254_BINARY` (0) and `I8254_BCD` (1)}.  The maximum allowed value
ought to be `I8254_MODE5 | I8254_BCD` ((5 << 1) | 1), but is currently
`I8254_MODE5 | I8254_BINARY` ((5 << 1) | 0).  Fix it.

None of the comedi drivers use `I8254_BCD` but some of the low-level
drivers allow user-space to configure the counter mode, so all legal
values ought to be allowed.  However, it's pretty unlikely anyone would
want to set the counters to count in BCD (binary coded decimal) so the
bug is not that significant.

Reported-by: Hartley Sweeten <HartleyS@visionengravers.com>
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Reviewed-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/comedi/drivers/8253.h

index fb2c9d9057238bdd81c3314e1d0b9053734c8e55..5829b46b757b9e959d18ada06f07b17ae09a93fe 100644 (file)
@@ -291,7 +291,7 @@ static inline int i8254_set_mode(unsigned long base_address,
 
        if (counter_number > 2)
                return -1;
-       if (mode > (I8254_MODE5 | I8254_BINARY))
+       if (mode > (I8254_MODE5 | I8254_BCD))
                return -1;
 
        byte = counter_number << 6;
@@ -311,7 +311,7 @@ static inline int i8254_mm_set_mode(void __iomem *base_address,
 
        if (counter_number > 2)
                return -1;
-       if (mode > (I8254_MODE5 | I8254_BINARY))
+       if (mode > (I8254_MODE5 | I8254_BCD))
                return -1;
 
        byte = counter_number << 6;
This page took 0.025669 seconds and 5 git commands to generate.