]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
comedi: dmm32at: Add sanity check for I/O base address
authorIan Abbott <abbotti@mev.co.uk>
Fri, 30 Jan 2026 16:47:43 +0000 (16:47 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 2 Apr 2026 13:49:38 +0000 (15:49 +0200)
The "dmm32at" driver uses an admin-supplied configuration option
(`it->options[0]`) to configure the I/O port base address of a
Diamond-MM-32-AT board.  It currently allows any base address to be
configured but the hardware only supports 8 possible base addresses
(selected by 3 on-board jumpers).  These are 0x100, 0x140, 0x180, 0x200,
0x280, 0x300, 0x340, and 0x380.

Add a sanity check to ensure the device is not configured at an
unsupported base address.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Link: https://patch.msgid.link/20260130170416.49994-19-abbotti@mev.co.uk
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/comedi/drivers/dmm32at.c

index 910cd24b1bed57d210df3e6db884249958fad7bd..d1d9f75e168f2712ca52b99a4a7917942c3e7bce 100644 (file)
@@ -572,11 +572,27 @@ static int dmm32at_attach(struct comedi_device *dev,
                          struct comedi_devconfig *it)
 {
        struct comedi_subdevice *s;
+       unsigned int iobase = it->options[0];
        int ret;
 
-       ret = comedi_request_region(dev, it->options[0], 0x10);
-       if (ret)
-               return ret;
+       switch (iobase) {
+       case 0x100:
+       case 0x140:
+       case 0x180:
+       case 0x200:
+       case 0x280:
+       case 0x300:
+       case 0x340:
+       case 0x380:
+               ret = comedi_request_region(dev, iobase, 0x10);
+               if (ret)
+                       return ret;
+               break;
+       default:
+               dev_err(dev->class_dev, "unsupported base address %#x\n",
+                       iobase);
+               return -EINVAL;
+       }
 
        ret = dmm32at_reset(dev);
        if (ret) {