From: Dae S. Kim Date: Wed, 20 Feb 2013 02:16:33 +0000 (+1100) Subject: drivers/char/misc.c:misc_register(): do not loop on misc_list unconditionally X-Git-Tag: next-20130220~1^2~104 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=0447b14453fafb1dddc890f8d1f01a1a020c7e86;p=karo-tx-linux.git 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. Signed-off-by: Dae S. Kim Cc: Arnd Bergmann Cc: Greg KH Signed-off-by: Andrew Morton --- diff --git a/drivers/char/misc.c b/drivers/char/misc.c index 522136d40843..7b262b69c653 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);