From patchwork Tue Oct 26 21:41:13 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 284082 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 o9QLh9Pt010733 for ; Tue, 26 Oct 2010 21:43:14 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760480Ab0JZVlT (ORCPT ); Tue, 26 Oct 2010 17:41:19 -0400 Received: from g6t0186.atlanta.hp.com ([15.193.32.63]:20317 "EHLO g6t0186.atlanta.hp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760386Ab0JZVlR (ORCPT ); Tue, 26 Oct 2010 17:41:17 -0400 Received: from g5t0029.atlanta.hp.com (g5t0029.atlanta.hp.com [16.228.8.141]) by g6t0186.atlanta.hp.com (Postfix) with ESMTP id B970B2C240; Tue, 26 Oct 2010 21:41:15 +0000 (UTC) Received: from ldl (ldl.usa.hp.com [16.125.112.222]) by g5t0029.atlanta.hp.com (Postfix) with ESMTP id E0F0F200D8; Tue, 26 Oct 2010 21:41:13 +0000 (UTC) Received: from localhost (ldl.fc.hp.com [127.0.0.1]) by ldl (Postfix) with ESMTP id 7867ACF0013; Tue, 26 Oct 2010 15:41:13 -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 jtJzKDoK-3TI; Tue, 26 Oct 2010 15:41:13 -0600 (MDT) Received: from eh.fc.hp.com (bob.lnx.usa.hp.com [16.125.112.218]) by ldl (Postfix) with ESMTP id 5BEE3CF0012; Tue, 26 Oct 2010 15:41:13 -0600 (MDT) Received: from bob.kio (localhost [127.0.0.1]) by eh.fc.hp.com (Postfix) with ESMTP id 447E4260EB; Tue, 26 Oct 2010 15:41:13 -0600 (MDT) Subject: [PATCH v5 1/9] resources: add a default alignf to simplify find_resource() To: Jesse Barnes From: Bjorn Helgaas Cc: Bob Picco , Brian Bloniarz , Charles Butterfield , Denys Vlasenko , Ingo Molnar , linux-pci@vger.kernel.org, "Horst H. von Brand" , "H. Peter Anvin" , linux-kernel@vger.kernel.org, Stefan Becker , Chuck Ebbert , Fabrice Bellet , Yinghai Lu , Leann Ogasawara , Linus Torvalds , Thomas Gleixner Date: Tue, 26 Oct 2010 15:41:13 -0600 Message-ID: <20101026214113.29808.49847.stgit@bob.kio> In-Reply-To: <20101026214033.29808.15272.stgit@bob.kio> References: <20101026214033.29808.15272.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]); Tue, 26 Oct 2010 21:43:14 +0000 (UTC) diff --git a/kernel/resource.c b/kernel/resource.c index 7b36976..7dc8ad2 100644 --- a/kernel/resource.c +++ b/kernel/resource.c @@ -357,6 +357,14 @@ int __weak page_is_ram(unsigned long pfn) return walk_system_ram_range(pfn, 1, NULL, __is_ram) == 1; } +static resource_size_t simple_align_resource(void *data, + const struct resource *avail, + resource_size_t size, + resource_size_t align) +{ + return avail->start; +} + /* * Find empty slot in the resource tree given range and alignment. */ @@ -391,8 +399,8 @@ static int find_resource(struct resource *root, struct resource *new, if (tmp.end > max) tmp.end = max; tmp.start = ALIGN(tmp.start, align); - if (alignf) - tmp.start = 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; @@ -428,6 +436,9 @@ int allocate_resource(struct resource *root, struct resource *new, { int err; + if (!alignf) + alignf = simple_align_resource; + write_lock(&resource_lock); err = find_resource(root, new, size, min, max, align, alignf, alignf_data); if (err >= 0 && __request_resource(root, new))