PNP used to have a fixed-size pnp_resource_table for tracking the
resources used by a device. This table often overflowed, so we've
had to increase the table size, which wastes memory because most
devices have very few resources.
This patch replaces the table with a linked list of resources where
the entries are allocated on demand.
static void pnp_clean_resource_table(struct pnp_dev *dev)
{
- struct resource *res;
- int idx;
+ struct pnp_resource *pnp_res, *tmp;
- for (idx = 0; idx < PNP_MAX_IRQ; idx++) {
- res = &dev->res->irq[idx].res;
- if (res->flags & IORESOURCE_AUTO) {
- res->flags = IORESOURCE_IRQ;
- pnp_init_resource(res);
- }
- }
- for (idx = 0; idx < PNP_MAX_DMA; idx++) {
- res = &dev->res->dma[idx].res;
- if (res->flags & IORESOURCE_AUTO) {
- res->flags = IORESOURCE_DMA;
- pnp_init_resource(res);
- }
- }
- for (idx = 0; idx < PNP_MAX_PORT; idx++) {
- res = &dev->res->port[idx].res;
- if (res->flags & IORESOURCE_AUTO) {
- res->flags = IORESOURCE_IO;
- pnp_init_resource(res);
- }
- }
- for (idx = 0; idx < PNP_MAX_MEM; idx++) {
- res = &dev->res->mem[idx].res;
- if (res->flags & IORESOURCE_AUTO) {
- res->flags = IORESOURCE_MEM;
- pnp_init_resource(res);
- }
+ list_for_each_entry_safe(pnp_res, tmp, &dev->resources, list) {
+ if (pnp_res->res.flags & IORESOURCE_AUTO)
+ pnp_free_resource(pnp_res);
}
}