]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
comedi: pcl726: Add sanity checks for I/O base address
authorIan Abbott <abbotti@mev.co.uk>
Fri, 30 Jan 2026 16:47:59 +0000 (16:47 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 2 Apr 2026 13:49:39 +0000 (15:49 +0200)
The "pcl726" driver uses an admin-supplied configuration option
(`it->options[0]`) to configure the I/O port base address of various
analog output ISA boards from Advantech (PCL-726/727/728) and ADLINK
(ACL-6126/6128).  (Most of them also have digital I/O.)  It currently
allows any base address to be configured but the hardware only supports
base addresses (configured by on-board DIP switches) from 0 or 0x200 up
to nearly 0x3FF, depending on the model.

Store the minimum and maximum supported I/O address ranges in the static
board information array elements (the required alignment is already
stored in the `io_len` member), and 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-35-abbotti@mev.co.uk
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/comedi/drivers/pcl726.c

index b542896fa0e42777330042dba77bda839ae932ef..d3b1f4388643b47ccbaf3555bd293a9bec98ca53 100644 (file)
@@ -91,7 +91,8 @@ static const struct comedi_lrange *const rangelist_728[] = {
 
 struct pcl726_board {
        const char *name;
-       unsigned long io_len;
+       unsigned int io_len;
+       unsigned int min_io_start;
        unsigned int irq_mask;
        const struct comedi_lrange *const *ao_ranges;
        int ao_num_ranges;
@@ -104,6 +105,7 @@ static const struct pcl726_board pcl726_boards[] = {
        {
                .name           = "pcl726",
                .io_len         = 0x10,
+               .min_io_start   = 0x200,
                .ao_ranges      = &rangelist_726[0],
                .ao_num_ranges  = ARRAY_SIZE(rangelist_726),
                .ao_nchan       = 6,
@@ -111,6 +113,7 @@ static const struct pcl726_board pcl726_boards[] = {
        }, {
                .name           = "pcl727",
                .io_len         = 0x20,
+               .min_io_start   = 0x200,
                .ao_ranges      = &rangelist_727[0],
                .ao_num_ranges  = ARRAY_SIZE(rangelist_727),
                .ao_nchan       = 12,
@@ -119,12 +122,14 @@ static const struct pcl726_board pcl726_boards[] = {
        }, {
                .name           = "pcl728",
                .io_len         = 0x08,
+               .min_io_start   = 0,
                .ao_num_ranges  = ARRAY_SIZE(rangelist_728),
                .ao_ranges      = &rangelist_728[0],
                .ao_nchan       = 2,
        }, {
                .name           = "acl6126",
                .io_len         = 0x10,
+               .min_io_start   = 0x200,
                .irq_mask       = 0x96e8,
                .ao_num_ranges  = ARRAY_SIZE(rangelist_726),
                .ao_ranges      = &rangelist_726[0],
@@ -133,6 +138,7 @@ static const struct pcl726_board pcl726_boards[] = {
        }, {
                .name           = "acl6128",
                .io_len         = 0x08,
+               .min_io_start   = 0,
                .ao_num_ranges  = ARRAY_SIZE(rangelist_728),
                .ao_ranges      = &rangelist_728[0],
                .ao_nchan       = 2,
@@ -316,7 +322,9 @@ static int pcl726_attach(struct comedi_device *dev,
        int ret;
        int i;
 
-       ret = comedi_request_region(dev, it->options[0], board->io_len);
+       ret = comedi_check_request_region(dev, it->options[0], board->io_len,
+                                         board->min_io_start, 0x3ff,
+                                         board->io_len);
        if (ret)
                return ret;