From patchwork Fri Sep 17 22:32:22 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 189242 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 o8HMXB7R003030 for ; Fri, 17 Sep 2010 22:33:11 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755311Ab0IQWc3 (ORCPT ); Fri, 17 Sep 2010 18:32:29 -0400 Received: from g1t0029.austin.hp.com ([15.216.28.36]:9229 "EHLO g1t0029.austin.hp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755293Ab0IQWc0 (ORCPT ); Fri, 17 Sep 2010 18:32:26 -0400 Received: from g1t0039.austin.hp.com (g1t0039.austin.hp.com [16.236.32.45]) by g1t0029.austin.hp.com (Postfix) with ESMTP id 6D21F381BB; Fri, 17 Sep 2010 22:32:25 +0000 (UTC) Received: from ldl (ldl.fc.hp.com [15.11.146.30]) by g1t0039.austin.hp.com (Postfix) with ESMTP id 9094134042; Fri, 17 Sep 2010 22:32:23 +0000 (UTC) Received: from localhost (ldl.fc.hp.com [127.0.0.1]) by ldl (Postfix) with ESMTP id 1E254CF004E; Fri, 17 Sep 2010 16:32:23 -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 9LyYq-lZfXgj; Fri, 17 Sep 2010 16:32:23 -0600 (MDT) Received: from eh.fc.hp.com (eh.fc.hp.com [15.11.146.105]) by ldl (Postfix) with ESMTP id 05F18CF004A; Fri, 17 Sep 2010 16:32:23 -0600 (MDT) Received: from bob.kio (localhost [127.0.0.1]) by eh.fc.hp.com (Postfix) with ESMTP id EDEAB2618A; Fri, 17 Sep 2010 16:32:22 -0600 (MDT) Subject: [PATCH v2 3/4] 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: Fri, 17 Sep 2010 16:32:22 -0600 Message-ID: <20100917223222.24687.6486.stgit@bob.kio> In-Reply-To: <20100917223109.24687.17697.stgit@bob.kio> References: <20100917223109.24687.17697.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]); Fri, 17 Sep 2010 22:33:11 +0000 (UTC) diff --git a/kernel/resource.c b/kernel/resource.c index ace2269..1a2a40e 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,24 +383,18 @@ 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; resource_size_t start; - 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) @@ -404,10 +412,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; }