diff --git a/drivers/comedi/drivers/multiq3.c b/drivers/comedi/drivers/multiq3.c index 467587b0b250..dc27651e0ace 100644 --- a/drivers/comedi/drivers/multiq3.c +++ b/drivers/comedi/drivers/multiq3.c @@ -67,6 +67,11 @@ #define MULTIQ3_TRSFRCNTR_OL 0x10 /* xfer CNTR to OL (x and y) */ #define MULTIQ3_EFLAG_RESET 0x06 /* reset E bit of flag reg */ +/* + * Semi-arbitrary limit on the number of optional encoder chips + */ +#define MULTIQ3_MAX_ENC_CHIPS 16 + static void multiq3_set_ctrl(struct comedi_device *dev, unsigned int bits) { /* @@ -314,6 +319,11 @@ static int multiq3_attach(struct comedi_device *dev, /* Encoder (Counter) subdevice */ s = &dev->subdevices[4]; + + /* sanity check for number of optional encoders */ + if (it->options[2] > MULTIQ3_MAX_ENC_CHIPS) + it->options[2] = MULTIQ3_MAX_ENC_CHIPS; + s->type = COMEDI_SUBD_COUNTER; s->subdev_flags = SDF_READABLE | SDF_LSAMPL; s->n_chan = it->options[2] * 2;