spin_unlock_irqrestore(&dev->keylock, flags);
 }
 
+static unsigned int repeat_period(int protocol)
+{
+       if (protocol >= ARRAY_SIZE(protocols))
+               return 100;
+
+       return protocols[protocol].repeat_period;
+}
+
 /**
  * rc_repeat() - signals that a key is still pressed
  * @dev:       the struct rc_dev descriptor of the device
 {
        unsigned long flags;
        unsigned int timeout = nsecs_to_jiffies(dev->timeout) +
-               msecs_to_jiffies(protocols[dev->last_protocol].repeat_period);
+               msecs_to_jiffies(repeat_period(dev->last_protocol));
        struct lirc_scancode sc = {
                .scancode = dev->last_scancode, .rc_proto = dev->last_protocol,
                .keycode = dev->keypressed ? dev->last_keycode : KEY_RESERVED,
 
        if (dev->keypressed) {
                dev->keyup_jiffies = jiffies + nsecs_to_jiffies(dev->timeout) +
-                       msecs_to_jiffies(protocols[protocol].repeat_period);
+                       msecs_to_jiffies(repeat_period(protocol));
                mod_timer(&dev->timer_keyup, dev->keyup_jiffies);
        }
        spin_unlock_irqrestore(&dev->keylock, flags);