Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

The "pcl730" driver uses an admin-supplied configuration option
(`it->options[0]`) to configure the I/O port base address of various
relay output and digital input ISA board from Advantech, ADLINK, ICP
DAS, and Diamond Systems. It currently allows any base address to be
configured but the hardware devices have restrictions on the base
addresses (configured by on-board DIP switches or jumpers), including
the alignment, which can be larger than the board's I/O register address
span. The Diamond Systems IR104-PBF board is particularly restricted to
4 different base addresses with different sized gaps between the
possible addresses.

Store the minimum supported I/O base addresses and alignment in the
static board information array elements and add a sanity check to ensure
the device is not configured at an unsupported base address. For the
IR104-PBF board, add a special check that the base address is one of the
4 supported base addresses for that board.

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

authored by

Ian Abbott and committed by
Greg Kroah-Hartman
b5218a98 588b6ffa

+47 -2
+47 -2
drivers/comedi/drivers/pcl730.c
··· 101 101 102 102 struct pcl730_board { 103 103 const char *name; 104 - unsigned int io_range; 104 + unsigned short io_range; 105 + unsigned short min_io_start; 106 + unsigned short align_io_start; 105 107 unsigned is_pcl725:1; 106 108 unsigned is_acl7225b:1; 107 109 unsigned is_ir104:1; ··· 119 117 { 120 118 .name = "pcl730", 121 119 .io_range = 0x04, 120 + .min_io_start = 0, 121 + .align_io_start = 0x04, 122 122 .has_ttl_io = 1, 123 123 .n_subdevs = 4, 124 124 .n_iso_out_chan = 16, ··· 129 125 }, { 130 126 .name = "iso730", 131 127 .io_range = 0x04, 128 + .min_io_start = 0, 129 + .align_io_start = 0x04, 132 130 .n_subdevs = 4, 133 131 .n_iso_out_chan = 16, 134 132 .n_iso_in_chan = 16, ··· 138 132 }, { 139 133 .name = "acl7130", 140 134 .io_range = 0x08, 135 + .min_io_start = 0x200, 136 + .align_io_start = 0x08, 141 137 .has_ttl_io = 1, 142 138 .n_subdevs = 4, 143 139 .n_iso_out_chan = 16, ··· 148 140 }, { 149 141 .name = "pcm3730", 150 142 .io_range = 0x04, 143 + .min_io_start = 0, 144 + .align_io_start = 0x04, 151 145 .has_ttl_io = 1, 152 146 .n_subdevs = 4, 153 147 .n_iso_out_chan = 8, ··· 158 148 }, { 159 149 .name = "pcl725", 160 150 .io_range = 0x02, 151 + .min_io_start = 0x200, 152 + .align_io_start = 0x02, 161 153 .is_pcl725 = 1, 162 154 .n_subdevs = 2, 163 155 .n_iso_out_chan = 8, ··· 167 155 }, { 168 156 .name = "p8r8dio", 169 157 .io_range = 0x02, 158 + .min_io_start = 0, 159 + .align_io_start = 0x10, 170 160 .is_pcl725 = 1, 171 161 .has_readback = 1, 172 162 .n_subdevs = 2, ··· 177 163 }, { 178 164 .name = "acl7225b", 179 165 .io_range = 0x08, /* only 4 are used */ 166 + .min_io_start = 0x200, 167 + .align_io_start = 0x08, 180 168 .is_acl7225b = 1, 181 169 .has_readback = 1, 182 170 .n_subdevs = 2, ··· 187 171 }, { 188 172 .name = "p16r16dio", 189 173 .io_range = 0x04, 174 + .min_io_start = 0, 175 + .align_io_start = 0x08, 190 176 .is_acl7225b = 1, 191 177 .has_readback = 1, 192 178 .n_subdevs = 2, ··· 197 179 }, { 198 180 .name = "pcl733", 199 181 .io_range = 0x04, 182 + .min_io_start = 0, 183 + .align_io_start = 0x04, 200 184 .n_subdevs = 1, 201 185 .n_iso_in_chan = 32, 202 186 }, { 203 187 .name = "pcl734", 204 188 .io_range = 0x04, 189 + .min_io_start = 0, 190 + .align_io_start = 0x04, 205 191 .n_subdevs = 1, 206 192 .n_iso_out_chan = 32, 207 193 }, { 208 194 .name = "opmm-1616-xt", 209 195 .io_range = 0x10, 196 + .min_io_start = 0x100, 197 + .align_io_start = 0x10, 210 198 .is_acl7225b = 1, 211 199 .has_readback = 1, 212 200 .n_subdevs = 2, ··· 221 197 }, { 222 198 .name = "pearl-mm-p", 223 199 .io_range = 0x02, 200 + .min_io_start = 0x240, 201 + .align_io_start = 0x40, 224 202 .n_subdevs = 1, 225 203 .n_iso_out_chan = 16, 226 204 }, { 227 205 .name = "ir104-pbf", 228 206 .io_range = 0x08, 207 + .min_io_start = 0x240, 208 + .align_io_start = 0x20, 229 209 .is_ir104 = 1, 230 210 .has_readback = 1, 231 211 .n_iso_out_chan = 20, ··· 294 266 { 295 267 const struct pcl730_board *board = dev->board_ptr; 296 268 struct comedi_subdevice *s; 269 + unsigned int iobase = it->options[0]; 297 270 int subdev; 298 271 int ret; 299 272 300 - ret = comedi_request_region(dev, it->options[0], board->io_range); 273 + if (board->is_ir104) { 274 + switch (iobase) { 275 + case 0x240: 276 + case 0x260: 277 + case 0x280: 278 + case 0x300: 279 + break; 280 + default: 281 + dev_warn(dev->class_dev, 282 + "%s: unsupported I/O base address %#x\n", 283 + dev->board_name, iobase); 284 + return -EINVAL; 285 + } 286 + } 287 + ret = comedi_check_request_region(dev, iobase, board->io_range, 288 + board->min_io_start, 0x3ff, 289 + board->align_io_start); 301 290 if (ret) 302 291 return ret; 303 292