All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH] char: misc: Init misc->list in a safe way
@ 2017-06-26  9:31 Orson Zhai
  2017-06-26 10:02 ` Arnd Bergmann
  0 siblings, 1 reply; 14+ messages in thread
From: Orson Zhai @ 2017-06-26  9:31 UTC (permalink / raw)
  To: Arnd Bergmann, Greg Kroah-Hartman; +Cc: linux-kernel, Zhongping Tan, Orson Zhai

From: Zhongping Tan <zhongping.tan@spreadtrum.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@spreadtrum.com>
Signed-off-by: Orson Zhai <orson.zhai@spreadtrum.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

^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2017-06-29  7:30 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-26  9:31 [RFC PATCH] char: misc: Init misc->list in a safe way Orson Zhai
2017-06-26 10:02 ` Arnd Bergmann
2017-06-26 11:48   ` Zhongping Tan (谭中平)
2017-06-26 12:28     ` Arnd Bergmann
     [not found]       ` <ca76fa84d77449bf84c2f3ddf29048a0@SHMBX02.spreadtrum.com>
2017-06-26 14:10         ` 答复: " Arnd Bergmann
2017-06-27  2:02           ` Zhongping Tan (谭中平)
2017-06-27  6:29             ` Greg Kroah-Hartman
2017-06-28  1:54               ` Orson Zhai
2017-06-28  5:18                 ` Greg Kroah-Hartman
2017-06-28 10:34                   ` Arnd Bergmann
2017-06-28 11:21                     ` Greg Kroah-Hartman
2017-06-29  6:54                       ` Chunyan Zhang
2017-06-29  7:03                         ` Greg Kroah-Hartman
2017-06-29  7:30                           ` Chunyan Zhang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.