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.
CC: Linus Torvalds <torv...@linux-foundation.org>
CC: Yinghai Lu <yhlu....@gmail.com>
CC: Bjorn Helgaas <bjorn....@hp.com>
CC: Jesse Barnes <jba...@virtuousgeek.org>
Signed-off-by: Dominik Brodowski <li...@dominikbrodowski.net>
diff --git a/kernel/resource.c b/kernel/resource.c
index dc15686..af96c1e 100644
--- a/kernel/resource.c
+++ b/kernel/resource.c
@@ -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;
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majo...@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
On Sun, 20 Dec 2009, Dominik Brodowski wrote:
>
> 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.
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
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
At least the PCMCIA "align" function makes excessive use of the "size"
parameter, so we'd still need this.
> 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?).
> 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
On Mon, 21 Dec 2009, Dominik Brodowski wrote:
>
> 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").
> 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
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