]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
drivers/char/misc.c:misc_register(): do not loop on misc_list unconditionally
authorDae S. Kim <dae@velatum.com>
Wed, 20 Feb 2013 02:16:33 +0000 (13:16 +1100)
committerStephen Rothwell <sfr@canb.auug.org.au>
Wed, 20 Feb 2013 05:53:57 +0000 (16:53 +1100)
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>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Greg KH <greg@kroah.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
drivers/char/misc.c

index 522136d40843e8a38f1205ef61e1bae8e68e07ab..7b262b69c6532f893385238e0c837a43f8fbeb85 100644 (file)
@@ -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);