Skip to content

Commit 3c94ce6

Browse files
Dae S. Kimtorvalds
authored andcommitted
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>
1 parent f2afae4 commit 3c94ce6

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

‎drivers/char/misc.c‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -183,19 +183,12 @@ static const struct file_operations misc_fops = {
183183

184184
int misc_register(struct miscdevice * misc)
185185
{
186-
struct miscdevice *c;
187186
dev_t dev;
188187
int err = 0;
189188

190189
INIT_LIST_HEAD(&misc->list);
191190

192191
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-
}
199192

200193
if (misc->minor == MISC_DYNAMIC_MINOR) {
201194
int i = find_first_zero_bit(misc_minors, DYNAMIC_MINORS);
@@ -205,6 +198,15 @@ int misc_register(struct miscdevice * misc)
205198
}
206199
misc->minor = DYNAMIC_MINORS - i - 1;
207200
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+
}
208210
}
209211

210212
dev = MKDEV(MISC_MAJOR, misc->minor);

0 commit comments

Comments
 (0)