comedi: pcl726: Add sanity checks for I/O base address

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>
This commit is contained in:
Ian Abbott
2026-01-30 16:47:59 +00:00
committed by Greg Kroah-Hartman
parent b9723ebe04
commit 588b6ffa77

View 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;