Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751431AbdFZJfK (ORCPT ); Mon, 26 Jun 2017 05:35:10 -0400 Received: from sci-ig2.spreadtrum.com ([222.66.158.135]:49190 "EHLO SHSQR01.spreadtrum.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1751353AbdFZJfF (ORCPT ); Mon, 26 Jun 2017 05:35:05 -0400 From: Orson Zhai To: Arnd Bergmann , Greg Kroah-Hartman CC: , Zhongping Tan , Orson Zhai Subject: [RFC PATCH] char: misc: Init misc->list in a safe way Date: Mon, 26 Jun 2017 17:31:23 +0800 Message-ID: <20170626093123.23838-1-orson.zhai@spreadtrum.com> X-Mailer: git-send-email 2.12.2 MIME-Version: 1.0 Content-Type: text/plain X-MAIL: SHSQR01.spreadtrum.com v5Q9YZWa071035 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1186 Lines: 39 From: Zhongping Tan 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 Signed-off-by: Orson Zhai --- 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