diff options
author | Dae S. Kim <dae@velatum.com> | 2013-02-27 20:05:14 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2013-02-27 22:10:21 -0500 |
commit | 3c94ce6f48f484bbc4dba83c0ed1f98f5e10957c (patch) | |
tree | 0c475e8b2ab3a9e5b3e70f0a4dcd12f7ac46d514 /drivers/char | |
parent | f2afae4629d74287aaac39d0532aac5819e77e70 (diff) |
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.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/drivers/char/misc.c b/drivers/char/misc.c index 522136d40843..190d4423653f 100644 --- a/drivers/char/misc.c +++ b/drivers/char/misc.c | |||
@@ -183,19 +183,12 @@ static const struct file_operations misc_fops = { | |||
183 | 183 | ||
184 | int misc_register(struct miscdevice * misc) | 184 | int misc_register(struct miscdevice * misc) |
185 | { | 185 | { |
186 | struct miscdevice *c; | ||
187 | dev_t dev; | 186 | dev_t dev; |
188 | int err = 0; | 187 | int err = 0; |
189 | 188 | ||
190 | INIT_LIST_HEAD(&misc->list); | 189 | INIT_LIST_HEAD(&misc->list); |
191 | 190 | ||
192 | mutex_lock(&misc_mtx); | 191 | mutex_lock(&misc_mtx); |
193 | list_for_each_entry(c, &misc_list, list) { | ||
194 | if (c->minor == misc->minor) { | ||
195 | mutex_unlock(&misc_mtx); | ||
196 | return -EBUSY; | ||
197 | } | ||
198 | } | ||
199 | 192 | ||
200 | if (misc->minor == MISC_DYNAMIC_MINOR) { | 193 | if (misc->minor == MISC_DYNAMIC_MINOR) { |
201 | int i = find_first_zero_bit(misc_minors, DYNAMIC_MINORS); | 194 | int i = find_first_zero_bit(misc_minors, DYNAMIC_MINORS); |
@@ -205,6 +198,15 @@ int misc_register(struct miscdevice * misc) | |||
205 | } | 198 | } |
206 | misc->minor = DYNAMIC_MINORS - i - 1; | 199 | misc->minor = DYNAMIC_MINORS - i - 1; |
207 | set_bit(i, misc_minors); | 200 | set_bit(i, misc_minors); |
201 | } else { | ||
202 | struct miscdevice *c; | ||
203 | |||
204 | list_for_each_entry(c, &misc_list, list) { | ||
205 | if (c->minor == misc->minor) { | ||
206 | mutex_unlock(&misc_mtx); | ||
207 | return -EBUSY; | ||
208 | } | ||
209 | } | ||
208 | } | 210 | } |
209 | 211 | ||
210 | dev = MKDEV(MISC_MAJOR, misc->minor); | 212 | dev = MKDEV(MISC_MAJOR, misc->minor); |