Re: 2.3.37 compile breaks in isapnp.o

From: Martin Mares (mj@suse.cz)
Date: Fri Jan 07 2000 - 03:21:33 EST


Hello,

> In 2.3.37, the PCI changes broke drivers/block/cy*693.c and
> drivers/pnp/isapnp.c at least, if not other modules. They are all
> looking for 'next' member...

Here is a patch which fixes (well, at least attempts to fix) cy82c693,
isapnp and matroxfb plus does several minor simplifications.

> Would you consider adding a pci_device_next() helper to ease driver
> migration and future use?

Except for very unusual circumstances, driver should NOT rely on the
structure of the device list for scanning of secondary channels and
similar reasons, therefore there will be no pci_device_next(). Drivers
requiring inspecting each PCI device themselves can now use pci_for_each_dev().

                                Have a nice fortnight

-- 
Martin `MJ' Mares <mj@ucw.cz> <mj@suse.cz> http://atrey.karlin.mff.cuni.cz/~mj/
"Nothing is smiple enough to be not screwed up."

--- include/linux/pci.h.mj Fri Jan 7 09:02:04 2000 +++ include/linux/pci.h Fri Jan 7 09:02:04 2000 @@ -487,10 +487,8 @@ int pci_set_power_state(struct pci_dev *dev, int state); int pci_assign_resource(struct pci_dev *dev, int i); -#define __pcidev(entry) list_entry(entry, struct pci_dev, global_list) - #define pci_for_each_dev(dev) \ - for(dev = __pcidev(pci_devices.next); dev != __pcidev(&pci_devices); dev = __pcidev(dev->global_list.next)) + for(dev = pci_dev_g(pci_devices.next); dev != pci_dev_g(&pci_devices); dev = pci_dev_g(dev->global_list.next)) /* Helper functions for low-level code (drivers/pci/setup.c) */ --- drivers/block/cy82c693.c.mj Fri Jan 7 08:59:57 2000 +++ drivers/block/cy82c693.c Fri Jan 7 08:59:57 2000 @@ -274,8 +274,13 @@ unsigned int addrCtrl; /* select primary or secondary channel */ - if (hwif->index > 0) /* drive is on the secondary channel */ - dev = dev->next; + if (hwif->index > 0) { /* drive is on the secondary channel */ + dev = pci_find_slot(dev, dev->devfn+1); + if (!dev) { + printk(KERN_ERR "%s: tune_drive: Cannot find secondary interface!\n"); + return; + } + } #if CY82C693_DEBUG_LOGS /* for debug let's show the register values */ --- drivers/pci/compat.c.mj Fri Jan 7 09:06:31 2000 +++ drivers/pci/compat.c Fri Jan 7 09:06:31 2000 @@ -13,7 +13,7 @@ int pcibios_present(void) { - return pci_devices.next != &pci_devices; + return !list_empty(&pci_devices); } int --- drivers/pnp/isapnp.c.mj Fri Jan 7 09:08:50 2000 +++ drivers/pnp/isapnp.c Fri Jan 7 09:16:21 2000 @@ -42,6 +42,12 @@ LIST_HEAD(isapnp_cards); LIST_HEAD(isapnp_devices); +#define isapnp_for_each_card(card) \ + for(card = pci_bus_b(isapnp_cards.next); card != pci_bus_b(&isapnp_cards); card = pci_bus_b(card->node.next)) +#define isapnp_for_each_dev(dev) \ + for(dev = pci_dev_g(isapnp_devices.next); dev != pci_dev_g(&isapnp_devices); dev = pci_dev_g(dev->global_list.next)) + + #ifdef CONFIG_PROC_FS #include "isapnp_proc.c" #endif @@ -1147,7 +1153,7 @@ list = from->node.next; while (list != &isapnp_cards) { - struct pci_bus *card = list_entry(list, struct pci_bus, node); + struct pci_bus *card = pci_bus_b(list); if (card->vendor == vendor && card->device == device) return card; list = list->next; @@ -1169,7 +1175,7 @@ while (list != &isapnp_devices) { int idx; - struct pci_dev *dev = list_entry(list, struct pci_dev, global_list); + struct pci_dev *dev = pci_dev_g(list); if (dev->vendor == vendor && dev->device == function) return dev; @@ -1189,7 +1195,7 @@ return NULL; while (list != &card->devices) { int idx; - struct pci_dev *dev = list_entry(list, struct pci_dev, bus_list); + struct pci_dev *dev = pci_dev_b(list); if (dev->vendor == vendor && dev->device == function) return dev; @@ -1437,7 +1443,7 @@ { int i, tmp, rport, rsize; struct isapnp_port *xport; - struct list_head *list; + struct pci_dev *dev; if (check_region(port, size)) return 1; @@ -1450,8 +1456,7 @@ return 1; } - for (list = isapnp_devices.next; list != &isapnp_devices ; list = list->next) { - struct pci_dev *dev = list_entry(list, struct pci_dev, global_list); + isapnp_for_each_dev(dev) { if (dev->active) { for (tmp = 0; tmp < 8; tmp++) { if (dev->resource[tmp].flags) { @@ -1540,7 +1545,7 @@ static int isapnp_check_interrupt(struct isapnp_cfgtmp *cfg, int irq, int idx) { int i; - struct list_head *list; + struct pci_dev *dev; if (irq < 0 || irq > 15) return 1; @@ -1548,8 +1553,7 @@ if (isapnp_reserve_irq[i] == irq) return 1; } - for (list = isapnp_devices.next; list != &isapnp_devices; list = list->next) { - struct pci_dev *dev = list_entry(list, struct pci_dev, global_list); + isapnp_for_each_dev(dev) { if (dev->active) { if (dev->irq_resource[0].start == irq || dev->irq_resource[1].start == irq) @@ -1620,7 +1624,7 @@ static int isapnp_check_dma(struct isapnp_cfgtmp *cfg, int dma, int idx) { int i; - struct list_head *list; + struct pci_dev *dev; if (dma < 0 || dma == 4 || dma > 7) return 1; @@ -1628,8 +1632,7 @@ if (isapnp_reserve_dma[i] == dma) return 1; } - for (list = isapnp_devices.next; list != &isapnp_devices ; list = list->next) { - struct pci_dev *dev = list_entry(list, struct pci_dev, global_list); + isapnp_for_each_dev(dev) { if (dev->active) { if (dev->dma_resource[0].start == dma || dev->dma_resource[1].start == dma) return 1; @@ -1695,7 +1698,7 @@ int i, tmp; unsigned int raddr, rsize; struct isapnp_mem *xmem; - struct list_head *list; + struct pci_dev *dev; for (i = 0; i < 8; i++) { raddr = (unsigned int)isapnp_reserve_mem[i << 1]; @@ -1707,8 +1710,7 @@ if (__check_region(&iomem_resource, addr, size)) return 1; } - for (list = isapnp_devices.next; list != &isapnp_devices ; list = list->next) { - struct pci_dev *dev = list_entry(list, struct pci_dev, global_list); + isapnp_for_each_dev(dev) { if (dev->active) { for (tmp = 0; tmp < 4; tmp++) { if (dev->resource[tmp].flags) { @@ -1988,26 +1990,22 @@ } } -static void isapnp_free_device(struct pci_dev *dev) +static void isapnp_free_card(struct pci_bus *card) { - struct pci_dev *next; - - while (dev) { - next = dev->sibling; + while (!list_empty(&card->devices)) { + struct list_head *list = card->devices.next; + struct pci_dev *dev = pci_dev_b(list); + list_del(list); isapnp_free_resources((struct isapnp_resources *)dev->sysdata, 0); kfree(dev); - dev = next; } + kfree(card); } #endif /* MODULE */ static void isapnp_free_all_resources(void) { -#ifdef MODULE - struct pci_bus *card, *cardnext; -#endif - #ifdef ISAPNP_REGION_OK release_resource(pidxr_res); #endif @@ -2015,10 +2013,10 @@ if (isapnp_rdp >= 0x203 && isapnp_rdp <= 0x3ff) release_resource(isapnp_rdp_res); #ifdef MODULE - for (card = isapnp_cards; card; card = cardnext) { - cardnext = card->next; - isapnp_free_device(card->devices); - kfree(card); + while (!list_empty(&isapnp_cards)) { + struct list_head *list = isapnp_cards.next; + list_del(list); + isapnp_free_card(pci_bus_b(list)); } #ifdef CONFIG_PROC_FS isapnp_proc_done(); @@ -2085,7 +2083,7 @@ int __init isapnp_init(void) { int cards; - struct list_head *list; + struct pci_bus *card; if (isapnp_disable) { isapnp_detected = 0; @@ -2135,9 +2133,7 @@ isapnp_build_device_list(); cards = 0; - for (list = isapnp_cards.next; list != &isapnp_cards; list=list->next) { - struct pci_bus *card = list_entry(list, struct pci_bus, node); - + isapnp_for_each_card(card) { cards++; if (isapnp_verbose) { struct list_head *devlist; @@ -2145,7 +2141,7 @@ if (isapnp_verbose < 2) continue; for (devlist = card->devices.next; devlist != &card->devices; devlist = devlist->next) { - struct pci_dev *dev = list_entry(list, struct pci_dev, bus_list); + struct pci_dev *dev = pci_dev_b(devlist); printk("isapnp: Device '%s'\n", dev->name[0]?card->name:"Unknown"); } } --- drivers/video/matroxfb.c.mj Fri Jan 7 09:17:00 2000 +++ drivers/video/matroxfb.c Fri Jan 7 09:17:00 2000 @@ -6020,8 +6020,8 @@ u_int16_t sid; pci_read_config_byte(pdev, PCI_REVISION_ID, &rev); - svid = dev->subsystem_vendor; - sid = dev->subsystem_device; + svid = pdev->subsystem_vendor; + sid = pdev->subsystem_device; for (b = dev_list; b->vendor; b++) { if ((b->vendor != pdev->vendor) || (b->device != pdev->device) || (b->rev < rev)) continue; if (b->svid)

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Fri Jan 07 2000 - 21:00:08 EST