All of lore.kernel.org
 help / color / mirror / Atom feed
From: Orson Zhai <orson.zhai@spreadtrum.com>
To: Arnd Bergmann <arnd@arndb.de>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: <linux-kernel@vger.kernel.org>,
	Zhongping Tan <zhongping.tan@spreadtrum.com>,
	Orson Zhai <orson.zhai@spreadtrum.com>
Subject: [RFC PATCH] char: misc: Init misc->list in a safe way
Date: Mon, 26 Jun 2017 17:31:23 +0800	[thread overview]
Message-ID: <20170626093123.23838-1-orson.zhai@spreadtrum.com> (raw)

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

             reply	other threads:[~2017-06-26  9:35 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-26  9:31 Orson Zhai [this message]
2017-06-26 10:02 ` [RFC PATCH] char: misc: Init misc->list in a safe way 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170626093123.23838-1-orson.zhai@spreadtrum.com \
    --to=orson.zhai@spreadtrum.com \
    --cc=arnd@arndb.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=zhongping.tan@spreadtrum.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.