public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Dae S. Kim" <dae@velatum.com>
To: arnd@arndb.de
Cc: gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org
Subject: [PATCH] char/misc.c: misc_register: Do not loop on misc_list unconditionally
Date: Mon, 17 Dec 2012 23:26:38 +0100	[thread overview]
Message-ID: <20121217222638.GA3747@Delta> (raw)

If the minor number is assigned dynamically, there is no need to
search for misc->minor in misc_list, since misc->minor == 
MISC_DYNAMIC_MINOR.

Signed-off-by: Dae S. Kim <dae@velatum.com>
---
 drivers/char/misc.c |   13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/char/misc.c b/drivers/char/misc.c
index 522136d..7b262b6 100644
--- a/drivers/char/misc.c
+++ b/drivers/char/misc.c
@@ -190,12 +190,6 @@ int misc_register(struct miscdevice * misc)
 	INIT_LIST_HEAD(&misc->list);
 
 	mutex_lock(&misc_mtx);
-	list_for_each_entry(c, &misc_list, list) {
-		if (c->minor == misc->minor) {
-			mutex_unlock(&misc_mtx);
-			return -EBUSY;
-		}
-	}
 
 	if (misc->minor == MISC_DYNAMIC_MINOR) {
 		int i = find_first_zero_bit(misc_minors, DYNAMIC_MINORS);
@@ -205,6 +199,13 @@ int misc_register(struct miscdevice * misc)
 		}
 		misc->minor = DYNAMIC_MINORS - i - 1;
 		set_bit(i, misc_minors);
+	} else {
+		list_for_each_entry(c, &misc_list, list) {
+			if (c->minor == misc->minor) {
+				mutex_unlock(&misc_mtx);
+				return -EBUSY;
+			}
+		}
 	}
 
 	dev = MKDEV(MISC_MAJOR, misc->minor);
-- 
1.7.9.5


             reply	other threads:[~2012-12-17 22:33 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-17 22:26 Dae S. Kim [this message]
2012-12-19 23:12 ` [PATCH] char/misc.c: misc_register: Do not loop on misc_list unconditionally Andrew Morton

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=20121217222638.GA3747@Delta \
    --to=dae@velatum.com \
    --cc=arnd@arndb.de \
    --cc=gregkh@linuxfoundation.org \
    --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