From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751754AbdFZLsl (ORCPT ); Mon, 26 Jun 2017 07:48:41 -0400 Received: from sci-ig2.spreadtrum.com ([222.66.158.135]:49176 "EHLO SHSQR01.spreadtrum.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1751425AbdFZLsf (ORCPT ); Mon, 26 Jun 2017 07:48:35 -0400 From: =?utf-8?B?WmhvbmdwaW5nIFRhbiAo6LCt5Lit5bmzKQ==?= To: Arnd Bergmann , =?utf-8?B?T3Jzb24gWmhhaSAo57+f5LqsKQ==?= CC: Greg Kroah-Hartman , Linux Kernel Mailing List Subject: RE: [RFC PATCH] char: misc: Init misc->list in a safe way Thread-Topic: [RFC PATCH] char: misc: Init misc->list in a safe way Thread-Index: AQHS7l9tD7gZL09yLUqhZDhhbDen76I2Y98AgACdGHA= Date: Mon, 26 Jun 2017 11:48:14 +0000 Message-ID: References: <20170626093123.23838-1-orson.zhai@spreadtrum.com> In-Reply-To: Accept-Language: zh-CN, en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.0.1.253] Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 X-MAIL: SHSQR01.spreadtrum.com v5QBmE6L051171 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by mail.home.local id v5QBmjoS005592 Hi Arnd: If we can get list_add(&misc->list, &misc_list), then there is no problem at all, but if the misc_register return "-EBUSY"(Maybe the same miscdevice register twice ), then the deadloop will happen at list_for_each_entry(c, &misc_list, list); So at my opinion just remove the initialization code or do initialization when we need do list_add. -----Original Message----- From: arndbergmann@gmail.com [mailto:arndbergmann@gmail.com] On Behalf Of Arnd Bergmann Sent: Monday, June 26, 2017 6:03 PM To: Orson Zhai (翟京) Cc: Greg Kroah-Hartman; Linux Kernel Mailing List; Zhongping Tan (谭中平) Subject: Re: [RFC PATCH] char: misc: Init misc->list in a safe way On Mon, Jun 26, 2017 at 11:31 AM, Orson Zhai wrote: > 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 I fail to see the problem. Did you run into a bug that gets fixed by this patch, or did you arrive here after code inspection? As far as I can tell, the INIT_LIST_HEAD() on the entry has no effect at all, the fields simply get initialized in the list_add(), and the list traversal is protected using misc_mtx. Arnd