clocksource: timer-ti-dm: Check prescaler value
authorLadislav Michl <ladis@linux-mips.org>
Fri, 23 Feb 2018 10:15:01 +0000 (11:15 +0100)
committerTony Lindgren <tony@atomide.com>
Wed, 28 Feb 2018 21:41:30 +0000 (13:41 -0800)
Invalid value silently disables use of the prescaler.
Use -1 explicitely for that purpose and error out on
invalid value.

Signed-off-by: Ladislav Michl <ladis@linux-mips.org>
Signed-off-by: Tony Lindgren <tony@atomide.com>
drivers/clocksource/timer-ti-dm.c

index 6abe5ab553ce206391a51618f4fd4e0992a52c28..4cce6b224b87c1104daecfe0f4769344853b8dbf 100644 (file)
@@ -663,13 +663,13 @@ static int omap_dm_timer_set_prescaler(struct omap_dm_timer *timer,
 {
        u32 l;
 
-       if (unlikely(!timer))
+       if (unlikely(!timer) || prescaler < -1 || prescaler > 7)
                return -EINVAL;
 
        omap_dm_timer_enable(timer);
        l = omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG);
        l &= ~(OMAP_TIMER_CTRL_PRE | (0x07 << 2));
-       if (prescaler >= 0x00 && prescaler <= 0x07) {
+       if (prescaler >= 0) {
                l |= OMAP_TIMER_CTRL_PRE;
                l |= prescaler << 2;
        }