From patchwork Wed May 23 06:34:31 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yinghai Lu X-Patchwork-Id: 160884 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 67548B7003 for ; Wed, 23 May 2012 16:38:34 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752539Ab2EWGiP (ORCPT ); Wed, 23 May 2012 02:38:15 -0400 Received: from rcsinet15.oracle.com ([148.87.113.117]:32494 "EHLO rcsinet15.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965143Ab2EWGez (ORCPT ); Wed, 23 May 2012 02:34:55 -0400 Received: from acsinet21.oracle.com (acsinet21.oracle.com [141.146.126.237]) by rcsinet15.oracle.com (Sentrion-MTA-4.2.2/Sentrion-MTA-4.2.2) with ESMTP id q4N6YplA013234 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 23 May 2012 06:34:51 GMT Received: from acsmt356.oracle.com (acsmt356.oracle.com [141.146.40.156]) by acsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id q4N6Yo2M008191 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 23 May 2012 06:34:51 GMT Received: from abhmt103.oracle.com (abhmt103.oracle.com [141.146.116.55]) by acsmt356.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id q4N6Yo70019970; Wed, 23 May 2012 01:34:50 -0500 Received: from linux-siqj.site (/75.36.246.248) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 22 May 2012 23:34:50 -0700 From: Yinghai Lu To: Bjorn Helgaas Cc: Andrew Morton , Linus Torvalds , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Yinghai Lu Subject: [PATCH 05/11] resources: Split out __allocate_resource() Date: Tue, 22 May 2012 23:34:31 -0700 Message-Id: <1337754877-19759-6-git-send-email-yinghai@kernel.org> X-Mailer: git-send-email 1.7.7 In-Reply-To: <1337754877-19759-1-git-send-email-yinghai@kernel.org> References: <1337754877-19759-1-git-send-email-yinghai@kernel.org> X-Source-IP: acsinet21.oracle.com [141.146.126.237] Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org It will take bool lock, so we could use it in other functions that hold the resource lock. Signed-off-by: Yinghai Lu Cc: Andrew Morton --- kernel/resource.c | 26 +++++++++++++++++++++----- 1 files changed, 21 insertions(+), 5 deletions(-) diff --git a/kernel/resource.c b/kernel/resource.c index 51ade23..41d7050 100644 --- a/kernel/resource.c +++ b/kernel/resource.c @@ -521,14 +521,14 @@ out: * @alignf: alignment function, optional, called if not NULL * @alignf_data: arbitrary data to pass to the @alignf function */ -int allocate_resource(struct resource *root, struct resource *new, +static 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 *, const struct resource *, resource_size_t, resource_size_t), - void *alignf_data) + void *alignf_data, bool lock) { int err; struct resource_constraint constraint; @@ -542,19 +542,35 @@ int allocate_resource(struct resource *root, struct resource *new, constraint.alignf = alignf; constraint.alignf_data = alignf_data; - if ( new->parent ) { + if (new->parent && lock) { /* resource is already allocated, try reallocating with the new constraints */ return reallocate_resource(root, new, size, &constraint); } - write_lock(&resource_lock); + if (lock) + write_lock(&resource_lock); err = find_resource(root, new, size, &constraint); if (err >= 0 && __request_resource(root, new)) err = -EBUSY; - write_unlock(&resource_lock); + if (lock) + write_unlock(&resource_lock); return err; } +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 *, + const struct resource *, + resource_size_t, + resource_size_t), + void *alignf_data) +{ + bool lock = true; + + return __allocate_resource(root, new, size, min, max, align, + alignf, alignf_data, lock); +} EXPORT_SYMBOL(allocate_resource);