[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20170626093123.23838-1-orson.zhai@spreadtrum.com>
Date: Mon, 26 Jun 2017 17:31:23 +0800
From: Orson Zhai <orson.zhai@...eadtrum.com>
To: Arnd Bergmann <arnd@...db.de>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>
CC: <linux-kernel@...r.kernel.org>,
Zhongping Tan <zhongping.tan@...eadtrum.com>,
Orson Zhai <orson.zhai@...eadtrum.com>
Subject: [RFC PATCH] char: misc: Init misc->list in a safe way
From: Zhongping Tan <zhongping.tan@...eadtrum.com>
It is likely to enter a wrong case and return an error when registerring
a misc device. As a result, misc->list will be intialized to a dead loop
which is possible to go into wrong situation if anyone refers to it else
where.
Move the initializion line out of all error branches to avoid any side
effect.
Signed-off-by: Zhongping Tan <zhongping.tan@...eadtrum.com>
Signed-off-by: Orson Zhai <orson.zhai@...eadtrum.com>
---
drivers/char/misc.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/char/misc.c b/drivers/char/misc.c
index c9cd1ea6844a..876e7d57cc6c 100644
--- a/drivers/char/misc.c
+++ b/drivers/char/misc.c
@@ -188,8 +188,6 @@ int misc_register(struct miscdevice *misc)
int err = 0;
bool is_dynamic = (misc->minor == MISC_DYNAMIC_MINOR);
- INIT_LIST_HEAD(&misc->list);
-
mutex_lock(&misc_mtx);
if (is_dynamic) {
@@ -233,6 +231,7 @@ int misc_register(struct miscdevice *misc)
* Add it to the front, so that later devices can "override"
* earlier defaults
*/
+ INIT_LIST_HEAD(&misc->list);
list_add(&misc->list, &misc_list);
out:
mutex_unlock(&misc_mtx);
--
2.12.2
Powered by blists - more mailing lists