public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Wei Yang <richard.weiyang@gmail.com>
To: Wei Yang <richard.weiyang@gmail.com>
Cc: vgoyal@redhat.com, thomas.lendacky@amd.com, bp@suse.de,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] kernel/resource: refine find_next_iomem_res() a little
Date: Fri, 13 Apr 2018 17:03:38 +0800	[thread overview]
Message-ID: <20180413090338.GA66608@WeideMacBook-Pro.local> (raw)
In-Reply-To: <20180326224606.79666-1-richard.weiyang@gmail.com>

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

      reply	other threads:[~2018-04-13  9:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180413090338.GA66608@WeideMacBook-Pro.local \
    --to=richard.weiyang@gmail.com \
    --cc=bp@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=thomas.lendacky@amd.com \
    --cc=vgoyal@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox