[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <20121219151243.9f8882c8.akpm@linux-foundation.org>
Date: Wed, 19 Dec 2012 15:12:43 -0800
From: Andrew Morton <akpm@...ux-foundation.org>
To: "Dae S. Kim" <dae@...atum.com>
Cc: arnd@...db.de, gregkh@...uxfoundation.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH] char/misc.c: misc_register: Do not loop on misc_list
unconditionally
On Mon, 17 Dec 2012 23:26:38 +0100
"Dae S. Kim" <dae@...atum.com> wrote:
> 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.
>
> ...
>
> --- 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;
> + }
> + }
> }
>
Looks OK. It permits this:
From: Andrew Morton <akpm@...ux-foundation.org>
Subject: drivers-char-miscc-misc_register-do-not-loop-on-misc_list-unconditionally-fix
reduce scope of local `c'
Cc: "Dae S. Kim" <dae@...atum.com>
Cc: Arnd Bergmann <arnd@...db.de>
Cc: Dae S. Kim <dae@...atum.com>
Cc: Greg KH <greg@...ah.com>
Signed-off-by: Andrew Morton <akpm@...ux-foundation.org>
---
drivers/char/misc.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff -puN drivers/char/misc.c~drivers-char-miscc-misc_register-do-not-loop-on-misc_list-unconditionally-fix drivers/char/misc.c
--- a/drivers/char/misc.c~drivers-char-miscc-misc_register-do-not-loop-on-misc_list-unconditionally-fix
+++ a/drivers/char/misc.c
@@ -183,7 +183,6 @@ static const struct file_operations misc
int misc_register(struct miscdevice * misc)
{
- struct miscdevice *c;
dev_t dev;
int err = 0;
@@ -200,6 +199,8 @@ int misc_register(struct miscdevice * mi
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);
_
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists