From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751752AbdFZM21 (ORCPT ); Mon, 26 Jun 2017 08:28:27 -0400 Received: from mail-oi0-f68.google.com ([209.85.218.68]:34379 "EHLO mail-oi0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751475AbdFZM2Q (ORCPT ); Mon, 26 Jun 2017 08:28:16 -0400 MIME-Version: 1.0 In-Reply-To: References: <20170626093123.23838-1-orson.zhai@spreadtrum.com> From: Arnd Bergmann Date: Mon, 26 Jun 2017 14:28:14 +0200 X-Google-Sender-Auth: absKYj5jZbo2Df1ov2cHH2f51GI Message-ID: Subject: Re: [RFC PATCH] char: misc: Init misc->list in a safe way To: =?UTF-8?B?WmhvbmdwaW5nIFRhbiAo6LCt5Lit5bmzKQ==?= Cc: =?UTF-8?B?T3Jzb24gWmhhaSAo57+f5LqsKQ==?= , Greg Kroah-Hartman , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" 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 quoted-printable to 8bit by mail.home.local id v5QCSUWf009762 On Mon, Jun 26, 2017 at 1:48 PM, Zhongping Tan (谭中平) wrote: > 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. I think you are misinterpreting a bug you see: the pointer we pass into misc_register() must not already be registered, which means that nothing references misc->list at all. If misc_register() returns success, and you then call it another time, you will see the exact behavior that you describe, entering an endless loop in "list_for_each_entry(c, &misc_list, list)". The correct fix for that is in the calling code, to ensure that the same device can not get registered multiple times. Arnd