From patchwork Wed Sep 15 21:09:07 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 183562 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id o8FLAAA7003838 for ; Wed, 15 Sep 2010 21:10:10 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754440Ab0IOVJN (ORCPT ); Wed, 15 Sep 2010 17:09:13 -0400 Received: from g5t0008.atlanta.hp.com ([15.192.0.45]:35388 "EHLO g5t0008.atlanta.hp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754699Ab0IOVJK (ORCPT ); Wed, 15 Sep 2010 17:09:10 -0400 Received: from g5t0029.atlanta.hp.com (g5t0029.atlanta.hp.com [16.228.8.141]) by g5t0008.atlanta.hp.com (Postfix) with ESMTP id 7574C2407B; Wed, 15 Sep 2010 21:09:09 +0000 (UTC) Received: from ldl (ldl.fc.hp.com [15.11.146.30]) by g5t0029.atlanta.hp.com (Postfix) with ESMTP id 640B220237; Wed, 15 Sep 2010 21:09:08 +0000 (UTC) Received: from localhost (ldl.fc.hp.com [127.0.0.1]) by ldl (Postfix) with ESMTP id 0BD77CF0043; Wed, 15 Sep 2010 15:09:08 -0600 (MDT) Received: from ldl ([127.0.0.1]) by localhost (ldl.fc.hp.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id U2fBHqO9k8O6; Wed, 15 Sep 2010 15:09:07 -0600 (MDT) Received: from eh.fc.hp.com (eh.fc.hp.com [15.11.146.105]) by ldl (Postfix) with ESMTP id E565ECF0010; Wed, 15 Sep 2010 15:09:07 -0600 (MDT) Received: from bob.kio (localhost [127.0.0.1]) by eh.fc.hp.com (Postfix) with ESMTP id D279526108; Wed, 15 Sep 2010 15:09:07 -0600 (MDT) Subject: [PATCH 2/3] resources: allocate space within a region from the top down To: Jesse Barnes From: Bjorn Helgaas Cc: Brian Bloniarz , Charles Butterfield , Denys Vlasenko , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Stefan Becker , "H. Peter Anvin" , Yinghai Lu , Thomas Gleixner , Linus Torvalds , Ingo Molnar Date: Wed, 15 Sep 2010 15:09:07 -0600 Message-ID: <20100915210907.12365.81888.stgit@bob.kio> In-Reply-To: <20100915210818.12365.58732.stgit@bob.kio> References: <20100915210818.12365.58732.stgit@bob.kio> User-Agent: StGit/0.15 MIME-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Wed, 15 Sep 2010 21:10:10 +0000 (UTC) diff --git a/kernel/resource.c b/kernel/resource.c index 7b36976..e83ff7c 100644 --- a/kernel/resource.c +++ b/kernel/resource.c @@ -358,6 +358,20 @@ int __weak page_is_ram(unsigned long pfn) } /* + * Find the resource before "child" in the sibling list of "root" children. + */ +static struct resource *find_sibling_prev(struct resource *root, struct resource *child) +{ + struct resource *this; + + for (this = root->child; this; this = this->sibling) + if (this->sibling == child) + return this; + + return NULL; +} + +/* * Find empty slot in the resource tree given range and alignment. */ static int find_resource(struct resource *root, struct resource *new, @@ -369,23 +383,17 @@ static int find_resource(struct resource *root, struct resource *new, resource_size_t), void *alignf_data) { - struct resource *this = root->child; + struct resource *this; struct resource tmp = *new; - tmp.start = root->start; - /* - * Skip past an allocated resource that starts at 0, since the assignment - * of this->start - 1 to tmp->end below would cause an underflow. - */ - if (this && this->start == 0) { - tmp.start = this->end + 1; - this = this->sibling; - } - for(;;) { + tmp.end = root->end; + + this = find_sibling_prev(root, NULL); + for (;;) { if (this) - tmp.end = this->start - 1; + tmp.start = this->end + 1; else - tmp.end = root->end; + tmp.start = root->start; if (tmp.start < min) tmp.start = min; if (tmp.end > max) @@ -398,10 +406,10 @@ static int find_resource(struct resource *root, struct resource *new, new->end = tmp.start + size - 1; return 0; } - if (!this) + if (!this || this->start == root->start) break; - tmp.start = this->end + 1; - this = this->sibling; + tmp.end = this->start - 1; + this = find_sibling_prev(root, this); } return -EBUSY; }