Re: [RFC PATCH] char: misc: Init misc->list in a safe way
From: Arnd Bergmann
Date: Mon Jun 26 2017 - 08:28:29 EST
On Mon, Jun 26, 2017 at 1:48 PM, Zhongping Tan (èäå)
<Zhongping.Tan@xxxxxxxxxxxxxx> 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