linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kernel/resource: refine find_next_iomem_res() a little
@ 2018-03-26 22:46 Wei Yang
  2018-04-13  9:03 ` Wei Yang
  0 siblings, 1 reply; 2+ messages in thread
From: Wei Yang @ 2018-03-26 22:46 UTC (permalink / raw)
  To: vgoyal, thomas.lendacky, bp; +Cc: linux-kernel, Wei Yang

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@gmail.com>
---
 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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] kernel/resource: refine find_next_iomem_res() a little
  2018-03-26 22:46 [PATCH] kernel/resource: refine find_next_iomem_res() a little Wei Yang
@ 2018-04-13  9:03 ` Wei Yang
  0 siblings, 0 replies; 2+ messages in thread
From: Wei Yang @ 2018-04-13  9:03 UTC (permalink / raw)
  To: Wei Yang; +Cc: vgoyal, thomas.lendacky, bp, linux-kernel

Hello every one,

Someone would like to take a look at this?

On Tue, Mar 27, 2018 at 06:46:06AM +0800, Wei Yang wrote:
>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@gmail.com>
>---
> 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

-- 
Wei Yang
Help you, Help me

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-04-13  9:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-26 22:46 [PATCH] kernel/resource: refine find_next_iomem_res() a little Wei Yang
2018-04-13  9:03 ` Wei Yang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).