Re: [PATCH v2] ataflop: remove ataflop_probe_lock mutex
From: Luis Chamberlain <mcgrof@kernel.org>
Date: 2021-10-21 16:21:07
Also in:
linux-m68k
On Thu, Oct 21, 2021 at 09:20:06AM -0700, Luis Chamberlain wrote:
On Sun, Oct 17, 2021 at 11:09:47AM +0900, Tetsuo Handa wrote:quoted
Commit bf9c0538e485b591 ("ataflop: use a separate gendisk for each media format") introduced ataflop_probe_lock mutex, but forgot to unlock the mutex when atari_floppy_init() (i.e. module loading) succeeded. This will result in double lock deadlock if ataflop_probe() is called. Also, unregister_blkdev() must not be called from atari_floppy_init() with ataflop_probe_lock held when atari_floppy_init() failed, for ataflop_probe() waits for ataflop_probe_lock with major_names_lock held (i.e. AB-BA deadlock). __register_blkdev() needs to be called last in order to avoid calling ataflop_probe() when atari_floppy_init() is about to fail, for memory for completing already-started ataflop_probe() safely will be released as soon as atari_floppy_init() released ataflop_probe_lock mutex. As with commit 8b52d8be86d72308 ("loop: reorder loop_exit"), unregister_blkdev() needs to be called first in order to avoid calling ataflop_alloc_disk() from ataflop_probe() after del_gendisk() from atari_floppy_exit(). By relocating __register_blkdev() / unregister_blkdev() as explained above, we can remove ataflop_probe_lock mutex, for probe function and __exit function are serialized by major_names_lock mutex. Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> Fixes: bf9c0538e485b591 ("ataflop: use a separate gendisk for each media format")Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
I should note though that this does not apply to linux-next, I rebased it and will send a rebased version on my v3 series of my last patch set for add_disk error handling work(). Luis