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

comedi: 8255_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 8255_pci module supports PCI digital I/O devices from various
manufacturers that consist of one or more 8255 Programmable Peripheral
Interface chips (or equivalent hardware) to provide their digital I/O
ports. Some of the devices use port I/O and some 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. Change
`pci_8255_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 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-6-abbotti@mev.co.uk
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Ian Abbott and committed by
Greg Kroah-Hartman
0ccb86a6 90d25675

+10 -1
+10 -1
drivers/comedi/drivers/8255_pci.c
··· 57 57 #include <linux/comedi/comedi_8255.h> 58 58 59 59 enum pci_8255_boardid { 60 + #ifdef CONFIG_HAS_IOPORT 60 61 BOARD_ADLINK_PCI7224, 61 62 BOARD_ADLINK_PCI7248, 62 63 BOARD_ADLINK_PCI7296, ··· 66 65 BOARD_CB_PCIDIO48H_OLD, 67 66 BOARD_CB_PCIDIO48H_NEW, 68 67 BOARD_CB_PCIDIO96H, 68 + #endif /* CONFIG_HAS_IOPORT */ 69 69 BOARD_NI_PCIDIO96, 70 70 BOARD_NI_PCIDIO96B, 71 71 BOARD_NI_PXI6508, ··· 84 82 }; 85 83 86 84 static const struct pci_8255_boardinfo pci_8255_boards[] = { 85 + #ifdef CONFIG_HAS_IOPORT 87 86 [BOARD_ADLINK_PCI7224] = { 88 87 .name = "adl_pci-7224", 89 88 .dio_badr = 2, ··· 125 122 .dio_badr = 2, 126 123 .n_8255 = 4, 127 124 }, 125 + #endif /* CONFIG_HAS_IOPORT */ 128 126 [BOARD_NI_PCIDIO96] = { 129 127 .name = "ni_pci-dio-96", 130 128 .dio_badr = 1, ··· 223 219 dev->mmio = pci_ioremap_bar(pcidev, board->dio_badr); 224 220 if (!dev->mmio) 225 221 return -ENOMEM; 226 - } else { 222 + } else if (IS_ENABLED(CONFIG_HAS_IOPORT)) { 227 223 dev->iobase = pci_resource_start(pcidev, board->dio_badr); 224 + } else { 225 + dev_err(dev->class_dev, "error! need I/O port support\n"); 226 + return -ENXIO; 228 227 } 229 228 230 229 /* ··· 266 259 } 267 260 268 261 static const struct pci_device_id pci_8255_pci_table[] = { 262 + #ifdef CONFIG_HAS_IOPORT 269 263 { PCI_VDEVICE(ADLINK, 0x7224), BOARD_ADLINK_PCI7224 }, 270 264 { PCI_VDEVICE(ADLINK, 0x7248), BOARD_ADLINK_PCI7248 }, 271 265 { PCI_VDEVICE(ADLINK, 0x7296), BOARD_ADLINK_PCI7296 }, ··· 277 269 { PCI_DEVICE_SUB(PCI_VENDOR_ID_CB, 0x000b, PCI_VENDOR_ID_CB, 0x000b), 278 270 .driver_data = BOARD_CB_PCIDIO48H_NEW }, 279 271 { PCI_VDEVICE(CB, 0x0017), BOARD_CB_PCIDIO96H }, 272 + #endif /* CONFIG_HAS_IOPORT */ 280 273 { PCI_VDEVICE(NI, 0x0160), BOARD_NI_PCIDIO96 }, 281 274 { PCI_VDEVICE(NI, 0x1630), BOARD_NI_PCIDIO96B }, 282 275 { PCI_VDEVICE(NI, 0x13c0), BOARD_NI_PXI6508 },