Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751435AbdFZKDE (ORCPT ); Mon, 26 Jun 2017 06:03:04 -0400 Received: from mail-oi0-f50.google.com ([209.85.218.50]:33402 "EHLO mail-oi0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752002AbdFZKCt (ORCPT ); Mon, 26 Jun 2017 06:02:49 -0400 MIME-Version: 1.0 In-Reply-To: <20170626093123.23838-1-orson.zhai@spreadtrum.com> References: <20170626093123.23838-1-orson.zhai@spreadtrum.com> From: Arnd Bergmann Date: Mon, 26 Jun 2017 12:02:48 +0200 X-Google-Sender-Auth: fk-r0_wloPa2uBC1EjWHPKrKnkE Message-ID: Subject: Re: [RFC PATCH] char: misc: Init misc->list in a safe way To: Orson Zhai Cc: Greg Kroah-Hartman , Linux Kernel Mailing List , Zhongping Tan 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-Length: 899 Lines: 22 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