summaryrefslogtreecommitdiff
path: root/drivers/char
diff options
context:
space:
mode:
authorDae S. Kim <dae@velatum.com>2013-02-28 01:05:14 (GMT)
committerLinus Torvalds <torvalds@linux-foundation.org>2013-02-28 03:10:21 (GMT)
commit3c94ce6f48f484bbc4dba83c0ed1f98f5e10957c (patch)
tree0c475e8b2ab3a9e5b3e70f0a4dcd12f7ac46d514 /drivers/char
parentf2afae4629d74287aaac39d0532aac5819e77e70 (diff)
downloadlinux-3c94ce6f48f484bbc4dba83c0ed1f98f5e10957c.tar.xz
drivers/char/misc.c:misc_register(): do not loop on misc_list unconditionally
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. [akpm@linux-foundation.org: reduce scope of local `c'] Signed-off-by: Dae S. Kim <dae@velatum.com> Cc: Arnd Bergmann <arnd@arndb.de> Cc: Greg KH <greg@kroah.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/char')
-rw-r--r--drivers/char/misc.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/drivers/char/misc.c b/drivers/char/misc.c
index 522136d..190d442 100644
--- a/drivers/char/misc.c
+++ b/drivers/char/misc.c
@@ -183,19 +183,12 @@ static const struct file_operations misc_fops = {
int misc_register(struct miscdevice * misc)
{
- struct miscdevice *c;
dev_t dev;
int err = 0;
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 +198,15 @@ int misc_register(struct miscdevice * misc)
}
misc->minor = DYNAMIC_MINORS - i - 1;
set_bit(i, misc_minors);
+ } else {
+ struct miscdevice *c;
+
+ 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);