Commit 7529d8a4 authored by Russell King's avatar Russell King

[PCMCIA] Fix a couple of resource bugs.

Fix resource database bug where base + num wraps to zero.  Also,
ensure that we always take the resource semaphore whenever we
allocate a resource.
parent 08be072b
...@@ -550,7 +550,7 @@ pcmcia_align(void *align_data, struct resource *res, ...@@ -550,7 +550,7 @@ pcmcia_align(void *align_data, struct resource *res,
for (m = data->map->next; m != data->map; m = m->next) { for (m = data->map->next; m != data->map; m = m->next) {
unsigned long start = m->base; unsigned long start = m->base;
unsigned long end = m->base + m->num; unsigned long end = m->base + m->num - 1;
/* /*
* If the lower resources are not available, try aligning * If the lower resources are not available, try aligning
...@@ -569,7 +569,7 @@ pcmcia_align(void *align_data, struct resource *res, ...@@ -569,7 +569,7 @@ pcmcia_align(void *align_data, struct resource *res,
if (res->start >= res->end) if (res->start >= res->end)
break; break;
if ((res->start + size) <= end) if ((res->start + size - 1) <= end)
break; break;
} }
...@@ -608,18 +608,16 @@ int find_io_region(ioaddr_t *base, ioaddr_t num, unsigned long align, ...@@ -608,18 +608,16 @@ int find_io_region(ioaddr_t *base, ioaddr_t num, unsigned long align,
data.offset = *base & data.mask; data.offset = *base & data.mask;
data.map = &io_db; data.map = &io_db;
down(&rsrc_sem);
#ifdef CONFIG_PCI #ifdef CONFIG_PCI
if (s->cb_dev) { if (s->cb_dev) {
ret = pci_bus_alloc_resource(s->cb_dev->bus, res, num, 1, ret = pci_bus_alloc_resource(s->cb_dev->bus, res, num, 1,
min, 0, pcmcia_align, &data); min, 0, pcmcia_align, &data);
} else } else
#endif #endif
{
down(&rsrc_sem);
ret = allocate_resource(&ioport_resource, res, num, min, ~0UL, 0, ret = allocate_resource(&ioport_resource, res, num, min, ~0UL, 0,
pcmcia_align, &data); pcmcia_align, &data);
up(&rsrc_sem); up(&rsrc_sem);
}
if (ret != 0) { if (ret != 0) {
kfree(res); kfree(res);
...@@ -652,6 +650,7 @@ int find_mem_region(u_long *base, u_long num, u_long align, ...@@ -652,6 +650,7 @@ int find_mem_region(u_long *base, u_long num, u_long align,
min = 0x100000UL + *base; min = 0x100000UL + *base;
} }
down(&rsrc_sem);
#ifdef CONFIG_PCI #ifdef CONFIG_PCI
if (s->cb_dev) { if (s->cb_dev) {
ret = pci_bus_alloc_resource(s->cb_dev->bus, res, num, ret = pci_bus_alloc_resource(s->cb_dev->bus, res, num,
...@@ -659,12 +658,9 @@ int find_mem_region(u_long *base, u_long num, u_long align, ...@@ -659,12 +658,9 @@ int find_mem_region(u_long *base, u_long num, u_long align,
pcmcia_align, &data); pcmcia_align, &data);
} else } else
#endif #endif
{
down(&rsrc_sem);
ret = allocate_resource(&iomem_resource, res, num, min, ret = allocate_resource(&iomem_resource, res, num, min,
max, 0, pcmcia_align, &data); max, 0, pcmcia_align, &data);
up(&rsrc_sem); up(&rsrc_sem);
}
if (ret == 0 || low) if (ret == 0 || low)
break; break;
low = 1; low = 1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment