mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mike Frysinger <vapier@gentoo.org>
To: Greg Kroah-Hartman <gregkh@suse.de>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] driver core: simplify platform_get_resource()
Date: Mon, 27 Jul 2009 14:20:56 -0400	[thread overview]
Message-ID: <1248718856-22287-1-git-send-email-vapier@gentoo.org> (raw)

The platform_get_resource() function takes a number for the desired index
into the resource array, but then does a for loop on the array to get to
that index.  Considering the array is linear, the loop overhead is just
that -- overhead.  So unless I missed something, convert it into an index
check and access the desired resource directly.  Resulting code makes a
lot more sense considering its purpose.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
 drivers/base/platform.c |   10 ++++------
 1 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index 81cb01b..dc8c943 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -37,14 +37,12 @@ EXPORT_SYMBOL_GPL(platform_bus);
 struct resource *platform_get_resource(struct platform_device *dev,
 				       unsigned int type, unsigned int num)
 {
-	int i;
-
-	for (i = 0; i < dev->num_resources; i++) {
-		struct resource *r = &dev->resource[i];
-
-		if (type == resource_type(r) && num-- == 0)
+	if (num >= 0 && num < dev->num_resources) {
+		struct resource *r = &dev->resource[num];
+		if (type == resource_type(r))
 			return r;
 	}
+
 	return NULL;
 }
 EXPORT_SYMBOL_GPL(platform_get_resource);
-- 
1.6.3.3


             reply	other threads:[~2009-07-27 18:20 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-27 18:20 Mike Frysinger [this message]
2009-07-28 10:59 ` Mark Brown
2009-07-28 16:31   ` Greg KH

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=1248718856-22287-1-git-send-email-vapier@gentoo.org \
    --to=vapier@gentoo.org \
    --cc=gregkh@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®