aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorBjorn Helgaas <bjorn.helgaas@hp.com>2010-10-26 17:41:13 -0400
committerJesse Barnes <jbarnes@virtuousgeek.org>2010-10-26 18:33:22 -0400
commita9cea017411c95ec789092971f9baaef1f826883 (patch)
treec26c60f9c4b4e73eccd9ce6597daa250270691e6 /kernel
parent1ca98fa652bb5dc3c8793335db9ccc5d0f2e1f65 (diff)
resources: add a default alignf to simplify find_resource()
This removes a test from find_resource(), which is getting cluttered. No functional change. Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com> Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/resource.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/kernel/resource.c b/kernel/resource.c
index 7b36976e5dea..7dc8ad24f915 100644
--- a/kernel/resource.c
+++ b/kernel/resource.c
@@ -357,6 +357,14 @@ int __weak page_is_ram(unsigned long pfn)
357 return walk_system_ram_range(pfn, 1, NULL, __is_ram) == 1; 357 return walk_system_ram_range(pfn, 1, NULL, __is_ram) == 1;
358} 358}
359 359
360static resource_size_t simple_align_resource(void *data,
361 const struct resource *avail,
362 resource_size_t size,
363 resource_size_t align)
364{
365 return avail->start;
366}
367
360/* 368/*
361 * Find empty slot in the resource tree given range and alignment. 369 * Find empty slot in the resource tree given range and alignment.
362 */ 370 */
@@ -391,8 +399,8 @@ static int find_resource(struct resource *root, struct resource *new,
391 if (tmp.end > max) 399 if (tmp.end > max)
392 tmp.end = max; 400 tmp.end = max;
393 tmp.start = ALIGN(tmp.start, align); 401 tmp.start = ALIGN(tmp.start, align);
394 if (alignf) 402
395 tmp.start = alignf(alignf_data, &tmp, size, align); 403 tmp.start = alignf(alignf_data, &tmp, size, align);
396 if (tmp.start < tmp.end && tmp.end - tmp.start >= size - 1) { 404 if (tmp.start < tmp.end && tmp.end - tmp.start >= size - 1) {
397 new->start = tmp.start; 405 new->start = tmp.start;
398 new->end = tmp.start + size - 1; 406 new->end = tmp.start + size - 1;
@@ -428,6 +436,9 @@ int allocate_resource(struct resource *root, struct resource *new,
428{ 436{
429 int err; 437 int err;
430 438
439 if (!alignf)
440 alignf = simple_align_resource;
441
431 write_lock(&resource_lock); 442 write_lock(&resource_lock);
432 err = find_resource(root, new, size, min, max, align, alignf, alignf_data); 443 err = find_resource(root, new, size, min, max, align, alignf, alignf_data);
433 if (err >= 0 && __request_resource(root, new)) 444 if (err >= 0 && __request_resource(root, new))