diff options
author | Yinghai Lu <yinghai@kernel.org> | 2012-09-17 22:24:27 -0700 |
---|---|---|
committer | Yinghai Lu <yinghai@kernel.org> | 2012-09-17 22:24:27 -0700 |
commit | a14ecf213306bb3d728e52d37892fe956b6e3ce6 (patch) | |
tree | 126017cda101a8ad49b33d6b99165ee9128d8824 | |
parent | 8f63fa4ebb44ca6f8a7dde5f43acf3edbdc49488 (diff) | |
download | linux-yinghai-a14ecf213306bb3d728e52d37892fe956b6e3ce6.tar.gz |
resources: Split out __allocate_resource()
It will not hold lock, so we could use it in other functions that
hold the resource lock already.
-v2: according to Linus, using "bool lock" as parameter
aka "conditionally take lock" is *wrong*.
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
-rw-r--r-- | kernel/resource.c | 41 |
1 files changed, 33 insertions, 8 deletions
diff --git a/kernel/resource.c b/kernel/resource.c index 34d45886ee8429..28ebbeb1fbcf83 100644 --- a/kernel/resource.c +++ b/kernel/resource.c @@ -472,7 +472,7 @@ static int find_resource(struct resource *root, struct resource *new, * @newsize: new size of the resource descriptor * @constraint: the size and alignment constraints to be met. */ -int reallocate_resource(struct resource *root, struct resource *old, +static int __reallocate_resource(struct resource *root, struct resource *old, resource_size_t newsize, struct resource_constraint *constraint) { @@ -480,7 +480,6 @@ int reallocate_resource(struct resource *root, struct resource *old, struct resource new = *old; struct resource *conflict; - write_lock(&resource_lock); if ((err = __find_resource(root, old, &new, newsize, constraint))) goto out; @@ -506,11 +505,20 @@ int reallocate_resource(struct resource *root, struct resource *old, BUG_ON(conflict); } out: - write_unlock(&resource_lock); return err; } +int reallocate_resource(struct resource *root, struct resource *old, + resource_size_t newsize, + struct resource_constraint *constraint) +{ + int ret; + write_lock(&resource_lock); + ret = __reallocate_resource(root, old, newsize, constraint); + write_unlock(&resource_lock); + return ret; +} /** * allocate_resource - allocate empty slot in the resource tree given range & alignment. * The resource will be reallocated with a new size if it was already allocated @@ -523,7 +531,7 @@ 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 *, @@ -544,19 +552,36 @@ int allocate_resource(struct resource *root, struct resource *new, constraint.alignf = alignf; constraint.alignf_data = alignf_data; - if ( new->parent ) { + if (new->parent) { /* resource is already allocated, try reallocating with the new constraints */ - return reallocate_resource(root, new, size, &constraint); + return __reallocate_resource(root, new, size, &constraint); } - write_lock(&resource_lock); err = find_resource(root, new, size, &constraint); if (err >= 0 && __request_resource(root, new)) err = -EBUSY; - 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) +{ + int ret; + + write_lock(&resource_lock); + ret = __allocate_resource(root, new, size, min, max, align, + alignf, alignf_data); + write_unlock(&resource_lock); + + return ret; +} EXPORT_SYMBOL(allocate_resource); |