Re: [RFC PATCH] char: misc: Init misc->list in a safe way

From: Arnd Bergmann
Date: Mon Jun 26 2017 - 06:03:07 EST


On Mon, Jun 26, 2017 at 11:31 AM, Orson Zhai <orson.zhai@xxxxxxxxxxxxxx> wrote:
> From: Zhongping Tan <zhongping.tan@xxxxxxxxxxxxxx>
>
> 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@xxxxxxxxxxxxxx>
> Signed-off-by: Orson Zhai <orson.zhai@xxxxxxxxxxxxxx>

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