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

comedi: amplc_dio200_pci: Conditionally remove devices that use port I/O

In a future patch, the port I/O functions (`inb()`, `outb()`, and
friends will only be declared in the `HAS_IOPORT` configuration option
is enabled.

The amplc_dio200_pci module supports various Amplicon PCI and PCI
Express devices. Some of the supported devices (the PCI ones) use port
I/O, and some of them (the PCIe ones) only use memory-mapped I/O.

Conditionally compile in support for the devices that need port I/O if
and only if the `CONFIG_HAS_IOPORT` macro is defined.

Add a run-time check in `dio200_pci_auto_attach()` to return an error if
the device actually requires port I/O (based on the PCI BAR resource
flags) but the `HAS_IOPORT` configuration option is not enabled.

Cc: Arnd Bergmann <arnd@kernel.org>
Cc: Niklas Schnelle <schnelle@linux.ibm.com>
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Link: https://lore.kernel.org/r/20230913170712.111719-11-abbotti@mev.co.uk
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Ian Abbott and committed by
Greg Kroah-Hartman
772dcada 4e1bd672

+11 -1
+11 -1
drivers/comedi/drivers/amplc_dio200_pci.c
··· 223 223 */ 224 224 225 225 enum dio200_pci_model { 226 + #ifdef CONFIG_HAS_IOPORT 226 227 pci215_model, 227 228 pci272_model, 229 + #endif /* CONFIG_HAS_IOPORT */ 228 230 pcie215_model, 229 231 pcie236_model, 230 232 pcie296_model 231 233 }; 232 234 233 235 static const struct dio200_board dio200_pci_boards[] = { 236 + #ifdef CONFIG_HAS_IOPORT 234 237 [pci215_model] = { 235 238 .name = "pci215", 236 239 .mainbar = 2, ··· 255 252 .sdinfo = { 0x00, 0x08, 0x10, 0x3f }, 256 253 .has_int_sce = true, 257 254 }, 255 + #endif /* CONFIG_HAS_IOPORT */ 258 256 [pcie215_model] = { 259 257 .name = "pcie215", 260 258 .mainbar = 1, ··· 368 364 "error! cannot remap registers\n"); 369 365 return -ENOMEM; 370 366 } 371 - } else { 367 + } else if (IS_ENABLED(CONFIG_HAS_IOPORT)) { 372 368 dev->iobase = pci_resource_start(pci_dev, bar); 369 + } else { 370 + dev_err(dev->class_dev, 371 + "error! need I/O port support\n"); 372 + return -ENXIO; 373 373 } 374 374 375 375 if (board->is_pcie) { ··· 393 385 }; 394 386 395 387 static const struct pci_device_id dio200_pci_table[] = { 388 + #ifdef CONFIG_HAS_IOPORT 396 389 { PCI_VDEVICE(AMPLICON, 0x000b), pci215_model }, 397 390 { PCI_VDEVICE(AMPLICON, 0x000a), pci272_model }, 391 + #endif /* CONFIG_HAS_IOPORT */ 398 392 { PCI_VDEVICE(AMPLICON, 0x0011), pcie236_model }, 399 393 { PCI_VDEVICE(AMPLICON, 0x0012), pcie215_model }, 400 394 { PCI_VDEVICE(AMPLICON, 0x0014), pcie296_model },