resources: fix call to alignf() in allocate_resource()
Subsystems (12)
Dominik Brodowski
maintainerPATCH 1/1 resources: fix call to alignf() in allocate_resource()
The second parameter to alignf() in allocate_resource() must reflect what new resource is attempted to be allocated, else functions like pcibios_align_resource() (at least on x86) or pcmcia_align() can't work correctly.
Commit 1e5ad9679016275d422e36b12a98b0927d76f556 broke this by setting the "new" resource until we're about to return success. To keep the resource untouched when allocate_resource() fails, a "tmp" resource is introduced.
kernel/resource.c +16 -16
@@ -308,37 +308,37 @@ static int find_resource(struct resource *root, struct resource *new, void *alignf_data) {struct resource *this = root->child; -resource_size_t start, end; +struct resource tmp = *new; - start = root->start; + tmp.start = root->start;/* * Skip past an allocated resource that starts at 0, since the assignment -* of this->start - 1 to new->end below would cause an underflow. +* of this->start - 1 to tmp->end below would cause an underflow. */ if (this && this->start ==0 ) { - start = this->end +1 ; + tmp.start = this->end +1 ; this = this->sibling; }for (;;) {if (this) - end = this->start -1 ; + tmp.end = this->start -1 ;else - end = root->end; -if (start < min) - start = min; -if (end > max) - end = max; - start =ALIGN (start, align); + tmp.end = root->end; +if (tmp.start < min) + tmp.start = min; +if (tmp.end > max) + tmp.end = max; + tmp.start =ALIGN (tmp.start, align);if (alignf) -alignf (alignf_data, new, size, align); -if (start < end && end - start >= size -1 ) { - new->start = start; - new->end = start + size -1 ; +alignf (alignf_data, &tmp, size, align); +if (tmp.start < tmp.end && tmp.end - tmp.start >= size -1 ) { + new->start = tmp.start; + new->end = tmp.start + size -1 ;return 0 ; }if (!this)break ; - start = this->end +1 ; + tmp.start = this->end +1 ; this = this->sibling; }return -EBUSY ;
Quoted 10 lines · Dominik Brodowski
The second parameter to
alignf()inallocate_resource()must reflect what new resource is attempted to be allocated, else functions likepcibios_align_resource()(at least on x86) orpcmcia_align()can't work correctly.Commit
1e5ad9679016275d422e36b12a98b0927d76f556broke this by setting the "new" resource until we're about to return success. To keep the resource untouched whenallocate_resource()fails, a "tmp" resource is introduced.
Ack. That was subtle.
That said, maybe a nicer fix to this would be to actually return 'start' from the 'alignf' macro. That "modify the resource inside the alignment function" thing was always pretty ugly.
And then we'd pass in 'start' instead of 'size' (I have _no_ idea why we pass in 'size' to the alignment function, but whatever).
We'd still need to pass in the 'struct resource', but that would be so that it can figure out 'flags' (and 'size' if it really needs it) from it, but now it would be for reading only. So we could mark it 'const'.
Comments?
But Dominik's patch is ok too - the problem is not his patch, it's our longstanding horrible sh*t-for-brains calling convention (for which you can probably blame me - mea culpa).
Linus
Quoted 19 lines · Linus Torvalds
Quoted 10 lines · Dominik Brodowski
The second parameter to
alignf()inallocate_resource()must reflect what new resource is attempted to be allocated, else functions likepcibios_align_resource()(at least on x86) orpcmcia_align()can't work correctly.Commit
1e5ad9679016275d422e36b12a98b0927d76f556broke this by setting the "new" resource until we're about to return success. To keep the resource untouched whenallocate_resource()fails, a "tmp" resource is introduced.Ack. That was subtle.
That said, maybe a nicer fix to this would be to actually return 'start' from the 'alignf' macro. That "modify the resource inside the alignment function" thing was always pretty ugly.
Quoted 6 lines
And then we'd pass in 'start' instead of 'size' (I have _no_ idea why we pass in 'size' to the alignment function, but whatever).
We'd still need to pass in the 'struct resource', but that would be so that it can figure out 'flags' (and 'size' if it really needs it) from it, but now it would be for reading only. So we could mark it 'const'.
Ouch, sorry about that, I should have noticed that alignf() can modify 'new' before we know whether we're going to succeed.
Linus' proposal requires more code change, but has the advantage that future similar mistakes would be less likely.
Bjorn
Dominik Brodowski
maintainerQuoted 14 lines · Linus Torvalds
Quoted 10 lines · Dominik Brodowski
The second parameter to
alignf()inallocate_resource()must reflect what new resource is attempted to be allocated, else functions likepcibios_align_resource()(at least on x86) orpcmcia_align()can't work correctly.Commit
1e5ad9679016275d422e36b12a98b0927d76f556broke this by setting the "new" resource until we're about to return success. To keep the resource untouched whenallocate_resource()fails, a "tmp" resource is introduced.
Quoted 8 lines
Ack. That was subtle.
That said, maybe a nicer fix to this would be to actually return 'start' from the 'alignf' macro. That "modify the resource inside the alignment function" thing was always pretty ugly.
And then we'd pass in 'start' instead of 'size' (I have _no_ idea why we pass in 'size' to the alignment function, but whatever).
At least the PCMCIA "align" function makes excessive use of the "size" parameter, so we'd still need this.
Quoted 3 lines
We'd still need to pass in the 'struct resource', but that would be so that it can figure out 'flags' (and 'size' if it really needs it) from it, but now it would be for reading only. So we could mark it 'const'.
AFAICS, you can't determine the size out of "struct resource" as "start + size" may be less than "end" (else we couldn't align anything, couldn't we?).
Quoted 3 lines
But Dominik's patch is ok too - the problem is not his patch, it's our longstanding horrible sh*t-for-brains calling convention (for which you can probably blame me - mea culpa).
What about taking my patch for 2.6.33, and deferring the change to the calling convention to the 2.6.34 merge window? (I'll try to cook something up and get it into linux-next during the next few weeks).
Best,
Dominik
Quoted 3 lines · Dominik Brodowski
At least the PCMCIA "align" function makes excessive use of the "size" parameter, so we'd still need this.
I noticed that it also uses 'res->end' (in the meaning "skip this one as unacceptable").
Quoted 3 lines
What about taking my patch for 2.6.33, and deferring the change to the calling convention to the 2.6.34 merge window? (I'll try to cook something up and get it into linux-next during the next few weeks).
Sounds like a plan,
Linus
Dominik Brodowski
maintainer[RFC] improve alignf() calling convention in allocate_resource()
Quoted 3 lines · Linus Torvalds
Quoted 3 lines
What about taking my patch for 2.6.33, and deferring the change to the calling convention to the 2.6.34 merge window? (I'll try to cook something up and get it into linux-next during the next few weeks).
Based on the previous discussion, I've prepared two patches which change the calling convention of alignf() to
resource_size_t (*alignf)(void *data,
const struct resource *new, resource_size_t size, resource_size_t align)
. Any feedback is welcome.
arch/alpha/kernel/pci.c | 6 +++--- arch/arm/kernel/bios32.c | 8 +++++--- arch/cris/arch-v32/drivers/pci/bios.c | 16 +++++++--------- arch/frv/mb93090-mb00/pci-frv.c | 16 +++++++--------- arch/ia64/pci/pci.c | 5 +++-- arch/mips/pci/pci.c | 6 +++--- arch/mips/pmc-sierra/yosemite/ht.c | 10 +++++----- arch/mn10300/unit-asb2305/pci-asb2305.c | 16 +++++++--------- arch/parisc/kernel/pci.c | 10 +++++----- arch/powerpc/kernel/pci-common.c | 13 ++++++------- arch/sh/drivers/pci/pci.c | 6 +++--- arch/sparc/kernel/pci.c | 5 +++-- arch/sparc/kernel/pcic.c | 5 +++-- arch/x86/pci/i386.c | 14 ++++++-------- arch/xtensa/kernel/pci.c | 15 +++++++-------- drivers/pci/bus.c | 6 ++++-- drivers/pcmcia/rsrc_mgr.c | 13 +++++++------ drivers/pcmcia/rsrc_nonstatic.c | 22 ++++++++++++---------- include/linux/ioport.h | 6 ++++-- include/linux/pci.h | 9 ++++++--- kernel/resource.c | 14 +++++++++----- 21 files changed, 115 insertions(+), 106 deletions(-)
Best,
Dominik
Dominik Brodowski
maintainerPATCH 1/2 resource: align functions now return start of resource
As suggested by Linus, align functions should return the start of a resource, not void. An update of "res->start" is no longer necessary.
--- arch/alpha/kernel/pci.c | 4 ++-- arch/arm/kernel/bios32.c | 8 +++++--- arch/cris/arch-v32/drivers/pci/bios.c | 14 ++++++-------- arch/frv/mb93090-mb00/pci-frv.c | 14 ++++++-------- arch/ia64/pci/pci.c | 3 ++- arch/mips/pci/pci.c | 4 ++-- arch/mips/pmc-sierra/yosemite/ht.c | 10 +++++----- arch/mn10300/unit-asb2305/pci-asb2305.c | 16 +++++++--------- arch/parisc/kernel/pci.c | 10 +++++----- arch/powerpc/kernel/pci-common.c | 13 ++++++------- arch/sh/drivers/pci/pci.c | 6 +++--- arch/sparc/kernel/pci.c | 5 +++-- arch/sparc/kernel/pcic.c | 5 +++-- arch/x86/pci/i386.c | 12 +++++------- arch/xtensa/kernel/pci.c | 11 +++++------ drivers/pci/bus.c | 6 ++++-- drivers/pcmcia/rsrc_mgr.c | 12 ++++++------ drivers/pcmcia/rsrc_nonstatic.c | 16 +++++++++------- include/linux/ioport.h | 6 ++++-- include/linux/pci.h | 8 +++++--- kernel/resource.c | 14 +++++++++----- 21 files changed, 102 insertions(+), 95 deletions(-)
arch/alpha/kernel/pci.c +2 -2
@@ -126,7 +126,7 @@ DECLARE_PCI_FIXUP_FINAL(PCI_ANY_ID, PCI_ANY_ID, pcibios_fixup_final);#define MB (1024*KB)#define GB (1024*MB) -void +resource_size_t pcibios_align_resource (void *data,struct resource *res,resource_size_t size,resource_size_t align) {
@@ -184,7 +184,7 @@ pcibios_align_resource(void *data, struct resource *res, } } - res->start = start; +return start; }#undef KB#undef MB
arch/arm/kernel/bios32.c +5 -3
@@ -616,15 +616,17 @@ char * __init pcibios_setup(char *str)* but we want to try to avoid allocating at 0x2900-0x2bff * which might be mirrored at 0x0100-0x03ff.. */ -void pcibios_align_resource (void *data,struct resource *res, -resource_size_t size,resource_size_t align) +resource_size_t pcibios_align_resource (void *data,struct resource *res, +resource_size_t size,resource_size_t align) {resource_size_t start = res->start;if (res->flags &IORESOURCE_IO && start &0x300 ) start = (start +0x3ff ) & ~0x3ff ; - res->start = (start + align -1 ) & ~(align -1 ); + start = (start + align -1 ) & ~(align -1 ); + +return start; }/**
arch/cris/arch-v32/drivers/pci/bios.c +6 -8
@@ -41,18 +41,16 @@ int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,return 0 ; } -void +resource_size_t pcibios_align_resource (void *data,struct resource *res,resource_size_t size,resource_size_t align) { -if (res->flags &IORESOURCE_IO ) { -resource_size_t start = res->start; +resource_size_t start = res->start; -if (start &0x300 ) { - start = (start +0x3ff ) & ~0x3ff ; - res->start = start; - } - } +if ((res->flags &IORESOURCE_IO ) && (start &0x300 )) + start = (start +0x3ff ) & ~0x3ff ; + + return start }int pcibios_enable_resources (struct pci_dev *dev,int mask)
arch/frv/mb93090-mb00/pci-frv.c +6 -8
@@ -32,18 +32,16 @@* but we want to try to avoid allocating at 0x2900-0x2bff * which might have be mirrored at 0x0100-0x03ff.. */ -void +resource_size_t pcibios_align_resource (void *data,struct resource *res,resource_size_t size,resource_size_t align) { -if (res->flags &IORESOURCE_IO ) { -resource_size_t start = res->start; +resource_size_t start = res->start; -if (start &0x300 ) { - start = (start +0x3ff ) & ~0x3ff ; - res->start = start; - } - } +if ((res->flags &IORESOURCE_IO ) && (start &0x300 )) + start = (start +0x3ff ) & ~0x3ff ; + + return start }
arch/ia64/pci/pci.c +2 -1
@@ -547,10 +547,11 @@ pcibios_disable_device (struct pci_dev *dev)acpi_pci_irq_disable (dev); } -void +resource_size_t pcibios_align_resource (void *data,struct resource *res,resource_size_t size,resource_size_t align) { +return res->start; }/*
arch/mips/pci/pci.c +2 -2
@@ -49,7 +49,7 @@ static int pci_initialized;* but we want to try to avoid allocating at 0x2900-0x2bff * which might have be mirrored at 0x0100-0x03ff.. */ -void +resource_size_t pcibios_align_resource (void *data,struct resource *res,resource_size_t size,resource_size_t align) {
@@ -73,7 +73,7 @@ pcibios_align_resource(void *data, struct resource *res, start =PCIBIOS_MIN_MEM + hose->mem_resource->start; } - res->start = start; +return start; }static void __devinit pcibios_scanbus (struct pci_controller *hose)
arch/mips/pmc-sierra/yosemite/ht.c +5 -5
@@ -345,14 +345,13 @@ int pcibios_enable_device(struct pci_dev *dev, int mask)return pcibios_enable_resources (dev); } -void pcibios_align_resource (void *data,struct resource *res, -resource_size_t size,resource_size_t align) +resource_size_t pcibios_align_resource (void *data,struct resource *res, +resource_size_t size,resource_size_t align) {struct pci_dev *dev = data; +resource_size_t start = res->start;if (res->flags &IORESOURCE_IO ) { -resource_size_t start = res->start; -/* We need to avoid collisions with `mirrored' VGA ports and other strange ISA hardware, so we always want the addresses kilobyte aligned. */
@@ -363,8 +362,9 @@ void pcibios_align_resource(void *data, struct resource *res, } start = (start +1024 -1 ) & ~(1024 -1 ); - res->start = start; } + +return start; }struct pci_ops titan_pci_ops = {
arch/mn10300/unit-asb2305/pci-asb2305.c +7 -9
@@ -31,9 +31,11 @@* but we want to try to avoid allocating at 0x2900-0x2bff * which might have be mirrored at 0x0100-0x03ff.. */ -void pcibios_align_resource (void *data,struct resource *res, -resource_size_t size,resource_size_t align) +resource_size_t pcibios_align_resource (void *data,struct resource *res, +resource_size_t size,resource_size_t align) { +resource_size_t start = res->start; +#if 0 struct pci_dev *dev = data;
@@ -47,14 +49,10 @@ void pcibios_align_resource(void *data, struct resource *res, );#endif -if (res->flags &IORESOURCE_IO ) { -unsigned long start = res->start; +if ((res->flags &IORESOURCE_IO ) && (start &0x300 )) + start = (start +0x3ff ) & ~0x3ff ; -if (start &0x300 ) { - start = (start +0x3ff ) & ~0x3ff ; - res->start = start; - } - } +return start; }
arch/parisc/kernel/pci.c +5 -5
@@ -254,10 +254,10 @@ EXPORT_SYMBOL(pcibios_bus_to_resource);* Since we are just checking candidates, don't use any fields other * than res->start. */ -void pcibios_align_resource (void *data,struct resource *res, +resource_size_t pcibios_align_resource (void *data,struct resource *res,resource_size_t size,resource_size_t alignment) { -resource_size_t mask, align; +resource_size_t mask, align, start = res->start; DBG_RES("pcibios_align_resource(%s, (%p) [%lx,%lx]/%x, 0x%lx, 0x%lx)\n", pci_name(((struct pci_dev *) data)),
@@ -269,10 +269,10 @@ void pcibios_align_resource(void *data, struct resource *res,/* Align to largest of MIN or input size */ mask =max (alignment, align) -1 ; - res->start += mask; - res->start &= ~mask; + start += mask; + start &= ~mask; -/* The caller updates the end field, we don't. */ +return start; }
arch/powerpc/kernel/pci-common.c +6 -7
@@ -1168,21 +1168,20 @@ static int skip_isa_ioresource_align(struct pci_dev *dev)* but we want to try to avoid allocating at 0x2900-0x2bff * which might have be mirrored at 0x0100-0x03ff.. */ -void pcibios_align_resource (void *data,struct resource *res, +resource_size_t pcibios_align_resource (void *data,struct resource *res,resource_size_t size,resource_size_t align) {struct pci_dev *dev = data; +resource_size_t start = res->start;if (res->flags &IORESOURCE_IO ) { -resource_size_t start = res->start; -if (skip_isa_ioresource_align (dev)) -return ; -if (start &0x300 ) { +return start; +if (start &0x300 ) start = (start +0x3ff ) & ~0x3ff ; - res->start = start; - } } + +return start; }EXPORT_SYMBOL (pcibios_align_resource);
arch/sh/drivers/pci/pci.c +3 -3
@@ -148,8 +148,8 @@ void __devinit pcibios_fixup_bus(struct pci_bus *bus)* addresses to be allocated in the 0x000-0x0ff region * modulo 0x400. */ -void pcibios_align_resource (void *data,struct resource *res, -resource_size_t size,resource_size_t align) +resource_size_t pcibios_align_resource (void *data,struct resource *res, +resource_size_t size,resource_size_t align) {struct pci_dev *dev = data;struct pci_channel *chan = dev->sysdata;
@@ -171,7 +171,7 @@ void pcibios_align_resource(void *data, struct resource *res, start =PCIBIOS_MIN_MEM + chan->mem_resource->start; } - res->start = start; +return start; } void pcibios_resource_to_bus(struct pci_dev *dev, struct pci_bus_region *region,
arch/sparc/kernel/pci.c +3 -2
@@ -715,9 +715,10 @@ void pcibios_update_irq(struct pci_dev *pdev, int irq) { } -void pcibios_align_resource (void *data,struct resource *res, -resource_size_t size,resource_size_t align) +resource_size_t pcibios_align_resource (void *data,struct resource *res, +resource_size_t size,resource_size_t align) { +return res->start; }int pcibios_enable_device (struct pci_dev *dev,int mask)
arch/sparc/kernel/pcic.c +3 -2
@@ -839,9 +839,10 @@ char * __devinit pcibios_setup(char *str)return str; } -void pcibios_align_resource (void *data,struct resource *res, -resource_size_t size,resource_size_t align) +resource_size_t pcibios_align_resource (void *data,struct resource *res, +resource_size_t size,resource_size_t align) { +return res->start; }int pcibios_enable_device (struct pci_dev *pdev,int mask)
arch/x86/pci/i386.c +5 -7
@@ -60,22 +60,20 @@ skip_isa_ioresource_align(struct pci_dev *dev) {* but we want to try to avoid allocating at 0x2900-0x2bff * which might have be mirrored at 0x0100-0x03ff.. */ -void +resource_size_t pcibios_align_resource (void *data,struct resource *res,resource_size_t size,resource_size_t align) {struct pci_dev *dev = data; +resource_size_t start = res->start;if (res->flags &IORESOURCE_IO ) { -resource_size_t start = res->start; -if (skip_isa_ioresource_align (dev)) -return ; -if (start &0x300 ) { +return start; +if (start &0x300 ) start = (start +0x3ff ) & ~0x3ff ; - res->start = start; - } } +return start; }EXPORT_SYMBOL (pcibios_align_resource);
arch/xtensa/kernel/pci.c +5 -6
@@ -69,26 +69,25 @@ static int pci_bus_count;* but we want to try to avoid allocating at 0x2900-0x2bff * which might have be mirrored at 0x0100-0x03ff.. */ -void +resource_size_t pcibios_align_resource (void *data,struct resource *res,resource_size_t size,resource_size_t align) {struct pci_dev *dev = data; +resource_size_t start = res->start;if (res->flags &IORESOURCE_IO ) { -resource_size_t start = res->start; -if (size >0x100 ) {printk (KERN_ERR "PCI: I/O Region %s/%d too large" " (%ld bytes)\n" ,pci_name (dev), dev->resource - res, size); } -if (start &0x300 ) { +if (start &0x300 ) start = (start +0x3ff ) & ~0x3ff ; - res->start = start; - } } + +return start; }int
drivers/pci/bus.c +4 -2
@@ -36,8 +36,10 @@ int pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res, resource_size_t size, resource_size_t align, resource_size_t min, unsigned int type_mask, - void (*alignf)(void *, struct resource *, resource_size_t, - resource_size_t), + resource_size_t (*alignf)(void *, +struct resource *, + resource_size_t, + resource_size_t), void *alignf_data) { int i, ret = -ENOMEM;
drivers/pcmcia/rsrc_mgr.c +6 -6
@@ -114,22 +114,20 @@ struct pcmcia_align_data {unsigned long offset; }; -static void pcmcia_align (void *align_data,struct resource *res, -unsigned long size,unsigned long align) +static resource_size_t pcmcia_align (void *align_data,struct resource *res, +resource_size_t size,resource_size_t align) {struct pcmcia_align_data *data = align_data; -unsigned long start; +resource_size_t start; start = (res->start & ~data->mask) + data->offset;if (start < res->start) start += data->mask +1 ; - res->start = start;#ifdef CONFIG_X86 if (res->flags &IORESOURCE_IO ) {if (start &0x300 ) { start = (start +0x3ff ) & ~0x3ff ; - res->start = start; } }#endif
@@ -137,9 +135,11 @@ static void pcmcia_align(void *align_data, struct resource *res,#ifdef CONFIG_M68K if (res->flags &IORESOURCE_IO ) {if ((res->start + size -1 ) >=1024 ) - res->start = res->end; + start = res->end; }#endif + +return start; }
drivers/pcmcia/rsrc_nonstatic.c +9 -7
@@ -533,7 +533,7 @@ struct pcmcia_align_data {struct resource_map *map; }; -static void +static resource_size_t pcmcia_common_align (void *align_data,struct resource *res,resource_size_t size,resource_size_t align) {
@@ -545,17 +545,18 @@ pcmcia_common_align(void *align_data, struct resource *res, start = (res->start & ~data->mask) + data->offset;if (start < res->start) start += data->mask +1 ; - res->start = start; +return start; } -static void +static resource_size_t pcmcia_align (void *align_data,struct resource *res,resource_size_t size,resource_size_t align) {struct pcmcia_align_data *data = align_data;struct resource_map *m; +resource_size_t start; -pcmcia_common_align (data, res, size, align); + start =pcmcia_common_align (data, res, size, align);for (m = data->map->next; m != data->map; m = m->next) {unsigned long start = m->base;
@@ -567,8 +568,7 @@ pcmcia_align(void *align_data, struct resource *res, resource_size_t size,* fit here. */ if (res->start < start) { - res->start = start; -pcmcia_common_align (data, res, size, align); + start =pcmcia_common_align (data, res, size, align); }/*
@@ -586,7 +586,9 @@ pcmcia_align(void *align_data, struct resource *res, resource_size_t size,* If we failed to find something suitable, ensure we fail. */ if (m == data->map) - res->start = res->end; + start = res->end; + +return start; }/*
include/linux/ioport.h +4 -2
@@ -120,8 +120,10 @@ extern void insert_resource_expand_to_fit(struct resource *root, struct resourceextern int allocate_resource (struct resource *root,struct resource *new,resource_size_t size,resource_size_t min,resource_size_t max,resource_size_t align, -void (*alignf)(void *,struct resource *, -resource_size_t ,resource_size_t ), +resource_size_t (*alignf)(void *, +struct resource *, +resource_size_t , +resource_size_t ),void *alignf_data);int adjust_resource (struct resource *res,resource_size_t start,resource_size_t size);
include/linux/pci.h +5 -3
@@ -562,7 +562,8 @@ int __must_check pcibios_enable_device(struct pci_dev *, int mask);char *pcibios_setup (char *str);/* Used only when drivers/pci/setup.c is used */ -void pcibios_align_resource (void *,struct resource *,resource_size_t , +resource_size_t pcibios_align_resource (void *,struct resource *, +resource_size_t ,resource_size_t );void pcibios_update_irq (struct pci_dev *,int irq);
@@ -789,8 +790,9 @@ int __must_check pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res, resource_size_t size, resource_size_t align, resource_size_t min, unsigned int type_mask, - void (*alignf)(void *, struct resource *, -resource_size_t ,resource_size_t ), + resource_size_t (*alignf)(void *, struct resource *, +resource_size_t , +resource_size_t ), void *alignf_data);void pci_enable_bridges (struct pci_bus *bus);
kernel/resource.c +9 -5
@@ -303,8 +303,10 @@ int walk_system_ram_range(unsigned long start_pfn, unsigned long nr_pages,static int find_resource (struct resource *root,struct resource *new,resource_size_t size,resource_size_t min,resource_size_t max,resource_size_t align, -void (*alignf)(void *,struct resource *, -resource_size_t ,resource_size_t ), +resource_size_t (*alignf)(void *, +struct resource *, +resource_size_t , +resource_size_t ),void *alignf_data) {struct resource *this = root->child;
@@ -330,7 +332,7 @@ static int find_resource(struct resource *root, struct resource *new, tmp.end = max; tmp.start =ALIGN (tmp.start, align);if (alignf) -alignf (alignf_data, &tmp, size, align); + tmp.start =alignf (alignf_data, &tmp, size, align);if (tmp.start < tmp.end && tmp.end - tmp.start >= size -1 ) { new->start = tmp.start; new->end = tmp.start + size -1 ;
@@ -358,8 +360,10 @@ static int find_resource(struct resource *root, struct resource *new,int allocate_resource (struct resource *root,struct resource *new,resource_size_t size,resource_size_t min,resource_size_t max,resource_size_t align, -void (*alignf)(void *,struct resource *, -resource_size_t ,resource_size_t ), +resource_size_t (*alignf)(void *, +struct resource *, +resource_size_t , +resource_size_t ),void *alignf_data) {int err;
Signature · 1 line
1.6.3.3
Re: [PATCH 1/2] resource: align functions now return start of resource
Quoted 95 lines · Dominik Brodowski
As suggested by Linus, align functions should return the start of a resource, not void. An update of "
res->start" is no longer necessary.Cc Bjorn Helgaas <[email protected]>Cc Yinghai Lu <[email protected]>Cc Jesse Barnes <[email protected]>Signed-off-by Dominik Brodowski <[email protected]>---
arch/alpha/kernel/pci.c | 4 ++--arch/arm/kernel/bios32.c| 8 +++++---arch/cris/arch-v32/drivers/pci/bios.c| 14 ++++++--------arch/frv/mb93090-mb00/pci-frv.c| 14 ++++++--------arch/ia64/pci/pci.c| 3 ++-arch/mips/pci/pci.c| 4 ++--arch/mips/pmc-sierra/yosemite/ht.c| 10 +++++-----arch/mn10300/unit-asb2305/pci-asb2305.c| 16 +++++++---------arch/parisc/kernel/pci.c| 10 +++++-----arch/powerpc/kernel/pci-common.c| 13 ++++++-------arch/sh/drivers/pci/pci.c| 6 +++---arch/sparc/kernel/pci.c| 5 +++--arch/sparc/kernel/pcic.c| 5 +++--arch/x86/pci/i386.c| 12 +++++-------arch/xtensa/kernel/pci.c| 11 +++++------drivers/pci/bus.c| 6 ++++--drivers/pcmcia/rsrc_mgr.c| 12 ++++++------drivers/pcmcia/rsrc_nonstatic.c| 16 +++++++++-------include/linux/ioport.h| 6 ++++--include/linux/pci.h| 8 +++++---kernel/resource.c| 14 +++++++++-----21 files changed, 102 insertions(+), 95 deletions(-)arch/alpha/kernel/pci.c +2
-2@@ -126,7 +126,7 @@ DECLARE_PCI_FIXUP_FINAL(PCI_ANY_ID, PCI_ANY_ID, pcibios_fixup_final); #define MB (1024*KB) #define GB (1024*MB) -void +resource_size_t pcibios_align_resource(void *data, struct resource *res, resource_size_t size, resource_size_t align) {@@ -184,7 +184,7 @@ pcibios_align_resource(void *data, struct resource *res, } } - res->start = start; + return start; } #undef KB #undef MBarch/arm/kernel/bios32.c +5
-3@@ -616,15 +616,17 @@ char * __init pcibios_setup(char *str)* but we want to try to avoid allocating at 0x2900-0x2bff * which might be mirrored at 0x0100-0x03ff.. */ -void pcibios_align_resource (void *data,struct resource *res, - resource_size_t size, resource_size_t align) +resource_size_t pcibios_align_resource (void *data,struct resource *res, + resource_size_t size, resource_size_t align) { resource_size_t start = res->start; if (res->flags & IORESOURCE_IO && start & 0x300) start = (start + 0x3ff) & ~0x3ff; - res->start = (start + align - 1) & ~(align - 1); + start = (start + align - 1) & ~(align - 1); + + return start; } /**arch/cris/arch-v32/drivers/pci/bios.c +2
-3@@ -41,18 +41,16 @@ int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma, return 0; } -void +resource_size_t pcibios_align_resource(void *data, struct resource *res, resource_size_t size, resource_size_t align) { - if (res->flags & IORESOURCE_IO) { - resource_size_t start = res->start; + resource_size_t start = res->start;
arch/cris/arch-v32/drivers/pci/bios.c int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma, · line 53
Quoted 10 lines
arch/cris/arch-v32/drivers/pci/bios.c +4
-5- if (start & 0x300) { - start = (start + 0x3ff) & ~0x3ff; - res->start = start; - } - } + if ((res->flags & IORESOURCE_IO) && (start & 0x300)) + start = (start + 0x3ff) & ~0x3ff; + + return start
missed ; here?
YH
Dominik Brodowski
maintainerRe: [PATCH 1/2] resource: align functions now return start of resource
Hey,
Quoted 9 lines · Yinghai Lu
Quoted 7 lines
-
res->start= start;
- }
- }
+ if ((res->flags&IORESOURCE_IO) && (start &0x300))
+ start = (start +0x3ff) & ~0x3ff; +
+ return startmissed ; here?
Indeed -- thanks for the hint.
Best,
Dominik
Jesse Barnes
AppliedRe: [PATCH 1/2] resource: align functions now return start of resource
In reply to Dominik BrodowskiQuoted 3 lines · On Fri, 1 Jan 2010 17:40:49 +0100 Dominik Brodowski…
As suggested by Linus, align functions should return the start of a resource, not void. An update of "
res->start" is no longer necessary.
Applied these two to my linux-next branch, thanks Dominik.
Signature · 1 line
Jesse Barnes, Intel Open Source Technology Center
Dominik Brodowski
maintainerPATCH 2/2 resource: mark struct resource as const
In reply to Dominik BrodowskiNow that we return the new resource start position, there is no need to update "struct resource" inside the align function. Therefore, mark the struct resource as const.
--- arch/alpha/kernel/pci.c | 2 +- arch/arm/kernel/bios32.c | 2 +- arch/cris/arch-v32/drivers/pci/bios.c | 2 +- arch/frv/mb93090-mb00/pci-frv.c | 2 +- arch/ia64/pci/pci.c | 2 +- arch/mips/pci/pci.c | 2 +- arch/mips/pmc-sierra/yosemite/ht.c | 2 +- arch/mn10300/unit-asb2305/pci-asb2305.c | 2 +- arch/parisc/kernel/pci.c | 2 +- arch/powerpc/kernel/pci-common.c | 2 +- arch/sh/drivers/pci/pci.c | 2 +- arch/sparc/kernel/pci.c | 2 +- arch/sparc/kernel/pcic.c | 2 +- arch/x86/pci/i386.c | 2 +- arch/xtensa/kernel/pci.c | 4 ++-- drivers/pci/bus.c | 2 +- drivers/pcmcia/rsrc_mgr.c | 3 ++- drivers/pcmcia/rsrc_nonstatic.c | 6 +++--- include/linux/ioport.h | 2 +- include/linux/pci.h | 5 +++-- kernel/resource.c | 4 ++-- 21 files changed, 28 insertions(+), 26 deletions(-)
arch/alpha/kernel/pci.c +1 -1
@@ -127,7 +127,7 @@ DECLARE_PCI_FIXUP_FINAL(PCI_ANY_ID, PCI_ANY_ID, pcibios_fixup_final);#define GB (1024*MB)resource_size_t -pcibios_align_resource (void *data,struct resource *res, +pcibios_align_resource (void *data,const struct resource *res,resource_size_t size,resource_size_t align) {struct pci_dev *dev = data;
arch/arm/kernel/bios32.c +1 -1
@@ -616,7 +616,7 @@ char * __init pcibios_setup(char *str)* but we want to try to avoid allocating at 0x2900-0x2bff * which might be mirrored at 0x0100-0x03ff.. */ -resource_size_t pcibios_align_resource (void *data,struct resource *res, +resource_size_t pcibios_align_resource (void *data,const struct resource *res,resource_size_t size,resource_size_t align) {resource_size_t start = res->start;
arch/cris/arch-v32/drivers/pci/bios.c +1 -1
@@ -42,7 +42,7 @@ int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma, }resource_size_t -pcibios_align_resource (void *data,struct resource *res, +pcibios_align_resource (void *data,const struct resource *res,resource_size_t size,resource_size_t align) {resource_size_t start = res->start;
arch/frv/mb93090-mb00/pci-frv.c +1 -1
@@ -33,7 +33,7 @@* which might have be mirrored at 0x0100-0x03ff.. */ resource_size_t -pcibios_align_resource (void *data,struct resource *res, +pcibios_align_resource (void *data,const struct resource *res,resource_size_t size,resource_size_t align) {resource_size_t start = res->start;
arch/ia64/pci/pci.c +1 -1
@@ -548,7 +548,7 @@ pcibios_disable_device (struct pci_dev *dev) }resource_size_t -pcibios_align_resource (void *data,struct resource *res, +pcibios_align_resource (void *data,const struct resource *res,resource_size_t size,resource_size_t align) {return res->start;
arch/mips/pci/pci.c +1 -1
@@ -50,7 +50,7 @@ static int pci_initialized;* which might have be mirrored at 0x0100-0x03ff.. */ resource_size_t -pcibios_align_resource (void *data,struct resource *res, +pcibios_align_resource (void *data,const struct resource *res,resource_size_t size,resource_size_t align) {struct pci_dev *dev = data;
arch/mips/pmc-sierra/yosemite/ht.c +1 -1
@@ -345,7 +345,7 @@ int pcibios_enable_device(struct pci_dev *dev, int mask)return pcibios_enable_resources (dev); } -resource_size_t pcibios_align_resource (void *data,struct resource *res, +resource_size_t pcibios_align_resource (void *data,const struct resource *res,resource_size_t size,resource_size_t align) {struct pci_dev *dev = data;
arch/mn10300/unit-asb2305/pci-asb2305.c +1 -1
@@ -31,7 +31,7 @@* but we want to try to avoid allocating at 0x2900-0x2bff * which might have be mirrored at 0x0100-0x03ff.. */ -resource_size_t pcibios_align_resource (void *data,struct resource *res, +resource_size_t pcibios_align_resource (void *data,const struct resource *res,resource_size_t size,resource_size_t align) {resource_size_t start = res->start;
arch/parisc/kernel/pci.c +1 -1
@@ -254,7 +254,7 @@ EXPORT_SYMBOL(pcibios_bus_to_resource);* Since we are just checking candidates, don't use any fields other * than res->start. */ -resource_size_t pcibios_align_resource (void *data,struct resource *res, +resource_size_t pcibios_align_resource (void *data,const struct resource *res,resource_size_t size,resource_size_t alignment) {resource_size_t mask, align, start = res->start;
arch/powerpc/kernel/pci-common.c +1 -1
@@ -1168,7 +1168,7 @@ static int skip_isa_ioresource_align(struct pci_dev *dev)* but we want to try to avoid allocating at 0x2900-0x2bff * which might have be mirrored at 0x0100-0x03ff.. */ -resource_size_t pcibios_align_resource (void *data,struct resource *res, +resource_size_t pcibios_align_resource (void *data,const struct resource *res,resource_size_t size,resource_size_t align) {struct pci_dev *dev = data;
arch/sh/drivers/pci/pci.c +1 -1
@@ -148,7 +148,7 @@ void __devinit pcibios_fixup_bus(struct pci_bus *bus)* addresses to be allocated in the 0x000-0x0ff region * modulo 0x400. */ -resource_size_t pcibios_align_resource (void *data,struct resource *res, +resource_size_t pcibios_align_resource (void *data,const struct resource *res,resource_size_t size,resource_size_t align) {struct pci_dev *dev = data;
arch/sparc/kernel/pci.c +1 -1
@@ -715,7 +715,7 @@ void pcibios_update_irq(struct pci_dev *pdev, int irq) { } -resource_size_t pcibios_align_resource (void *data,struct resource *res, +resource_size_t pcibios_align_resource (void *data,const struct resource *res,resource_size_t size,resource_size_t align) {return res->start;
arch/sparc/kernel/pcic.c +1 -1
@@ -839,7 +839,7 @@ char * __devinit pcibios_setup(char *str)return str; } -resource_size_t pcibios_align_resource (void *data,struct resource *res, +resource_size_t pcibios_align_resource (void *data,const struct resource *res,resource_size_t size,resource_size_t align) {return res->start;
arch/x86/pci/i386.c +1 -1
@@ -61,7 +61,7 @@ skip_isa_ioresource_align(struct pci_dev *dev) {* which might have be mirrored at 0x0100-0x03ff.. */ resource_size_t -pcibios_align_resource (void *data,struct resource *res, +pcibios_align_resource (void *data,const struct resource *res,resource_size_t size,resource_size_t align) {struct pci_dev *dev = data;
arch/xtensa/kernel/pci.c +2 -2
@@ -70,8 +70,8 @@ static int pci_bus_count;* which might have be mirrored at 0x0100-0x03ff.. */ resource_size_t -pcibios_align_resource (void *data,struct resource *res,resource_size_t size, -resource_size_t align) +pcibios_align_resource (void *data,const struct resource *res, +resource_size_t size,resource_size_t align) {struct pci_dev *dev = data;resource_size_t start = res->start;
drivers/pci/bus.c +1 -1
@@ -37,7 +37,7 @@ pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res, resource_size_t size, resource_size_t align, resource_size_t min, unsigned int type_mask, resource_size_t (*alignf)(void *, -struct resource *, +const struct resource *,resource_size_t ,resource_size_t ), void *alignf_data)
drivers/pcmcia/rsrc_mgr.c +2 -1
@@ -114,7 +114,8 @@ struct pcmcia_align_data {unsigned long offset; }; -static resource_size_t pcmcia_align (void *align_data,struct resource *res, +static resource_size_t pcmcia_align (void *align_data, +const struct resource *res,resource_size_t size,resource_size_t align) {struct pcmcia_align_data *data = align_data;
drivers/pcmcia/rsrc_nonstatic.c +3 -3
@@ -534,7 +534,7 @@ struct pcmcia_align_data { };static resource_size_t -pcmcia_common_align (void *align_data,struct resource *res, +pcmcia_common_align (void *align_data,const struct resource *res,resource_size_t size,resource_size_t align) {struct pcmcia_align_data *data = align_data;
@@ -549,8 +549,8 @@ pcmcia_common_align(void *align_data, struct resource *res, }static resource_size_t -pcmcia_align (void *align_data,struct resource *res,resource_size_t size, -resource_size_t align) +pcmcia_align (void *align_data,const struct resource *res, +resource_size_t size,resource_size_t align) {struct pcmcia_align_data *data = align_data;struct resource_map *m;
include/linux/ioport.h +1 -1
@@ -121,7 +121,7 @@ extern int allocate_resource(struct resource *root, struct resource *new, resource_size_t size, resource_size_t min, resource_size_t max, resource_size_t align, resource_size_t (*alignf)(void *, -struct resource *, +const struct resource *,resource_size_t ,resource_size_t ), void *alignf_data);
include/linux/pci.h +3 -2
@@ -562,7 +562,7 @@ int __must_check pcibios_enable_device(struct pci_dev *, int mask);char *pcibios_setup (char *str);/* Used only when drivers/pci/setup.c is used */ -resource_size_t pcibios_align_resource (void *,struct resource *, +resource_size_t pcibios_align_resource (void *,const struct resource *,resource_size_t ,resource_size_t );void pcibios_update_irq (struct pci_dev *,int irq);
@@ -790,7 +790,8 @@ int __must_check pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res, resource_size_t size, resource_size_t align, resource_size_t min, unsigned int type_mask, - resource_size_t (*alignf)(void *, struct resource *, + resource_size_t (*alignf)(void *, +const struct resource *,resource_size_t ,resource_size_t ), void *alignf_data);
kernel/resource.c +2 -2
@@ -304,7 +304,7 @@ static int find_resource(struct resource *root, struct resource *new, resource_size_t size, resource_size_t min, resource_size_t max, resource_size_t align, resource_size_t (*alignf)(void *, -struct resource *, +const struct resource *,resource_size_t ,resource_size_t ), void *alignf_data)
@@ -361,7 +361,7 @@ int allocate_resource(struct resource *root, struct resource *new, resource_size_t size, resource_size_t min, resource_size_t max, resource_size_t align, resource_size_t (*alignf)(void *, -struct resource *, +const struct resource *,resource_size_t ,resource_size_t ), void *alignf_data)
Signature · 1 line
1.6.3.3
why can not receive kernel mail anymore?
In reply to Linus Torvaldshi,all;
addr: [email protected]
Best regards.
goldenwang1979
2010-01-14
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
�����������������������������������������������������������岫���'龶鼩唺�r��:.炈洷殊m珉a娚b策靭wm呴b濓顬藳笔鈓閎烄�戧鐉_鉃豝n噐■�侂h櫒璀�&{鄗夸z罐楘+€�+zf"穐殘啳嗃i��飦�戧鐉_璁鎗:+v墾�)撸鴐歋鍄�澏�瓎踚��鹈砘璁鍜i