[PATCH] kernel/resource: refine find_next_iomem_res() a little

From: Wei Yang
Date: Mon Mar 26 2018 - 18:46:22 EST


This patch does several refine for find_next_iomem_res()

* use first_level_children_only directly
* remove some local variables
* use resrouce_clip()

Signed-off-by: Wei Yang <richard.weiyang@xxxxxxxxx>
---
kernel/resource.c | 40 +++++++++++++++-------------------------
1 file changed, 15 insertions(+), 25 deletions(-)

diff --git a/kernel/resource.c b/kernel/resource.c
index e270b5048988..769109f20fb7 100644
--- a/kernel/resource.c
+++ b/kernel/resource.c
@@ -351,6 +351,15 @@ int release_resource(struct resource *old)

EXPORT_SYMBOL(release_resource);

+static void resource_clip(struct resource *res, resource_size_t min,
+ resource_size_t max)
+{
+ if (res->start < min)
+ res->start = min;
+ if (res->end > max)
+ res->end = max;
+}
+
/*
* Finds the lowest iomem resource existing within [res->start.res->end).
* The caller must specify res->start, res->end, res->flags, and optionally
@@ -361,31 +370,24 @@ EXPORT_SYMBOL(release_resource);
static int find_next_iomem_res(struct resource *res, unsigned long desc,
bool first_level_children_only)
{
- resource_size_t start, end;
struct resource *p;
- bool sibling_only = false;

BUG_ON(!res);
-
- start = res->start;
- end = res->end;
- BUG_ON(start >= end);
-
- if (first_level_children_only)
- sibling_only = true;
+ BUG_ON(res->start >= res->end);

read_lock(&resource_lock);

- for (p = iomem_resource.child; p; p = next_resource(p, sibling_only)) {
+ for (p = iomem_resource.child; p;
+ p = next_resource(p, first_level_children_only)) {
if ((p->flags & res->flags) != res->flags)
continue;
if ((desc != IORES_DESC_NONE) && (desc != p->desc))
continue;
- if (p->start > end) {
+ if (p->start > res->end) {
p = NULL;
break;
}
- if ((p->end >= start) && (p->start < end))
+ if ((p->end >= res->start) && (p->start < res->end))
break;
}

@@ -393,10 +395,7 @@ static int find_next_iomem_res(struct resource *res, unsigned long desc,
if (!p)
return -1;
/* copy data */
- if (res->start < p->start)
- res->start = p->start;
- if (res->end > p->end)
- res->end = p->end;
+ resource_clip(res, p->start, p->end);
res->flags = p->flags;
res->desc = p->desc;
return 0;
@@ -600,15 +599,6 @@ static resource_size_t simple_align_resource(void *data,
return avail->start;
}

-static void resource_clip(struct resource *res, resource_size_t min,
- resource_size_t max)
-{
- if (res->start < min)
- res->start = min;
- if (res->end > max)
- res->end = max;
-}
-
/*
* Find empty slot in the resource tree with the given range and
* alignment constraints
--
2.15.1