md: fix error handling in md_alloc
authorChristoph Hellwig <hch@lst.de>
Tue, 19 Jul 2022 09:18:16 +0000 (11:18 +0200)
committerSong Liu <song@kernel.org>
Wed, 20 Jul 2022 05:36:16 +0000 (22:36 -0700)
commit9c39164ac17d7e7119496f013d7c043583436339
tree45337e33d151e5c47a0ade132dd7a17083e02c66
parent069cce613a4a06bf76cd6c1f1158f24c44c3426c
md: fix error handling in md_alloc

Error handling in md_alloc is a mess.  Untangle it to just free the mddev
directly before add_disk is called and thus the gendisk is globally
visible.  After that clear the hold flag and let the mddev_put take care
of cleaning up the mddev through the usual mechanisms.

Fixes: 5e55e2f5fc95 ("[PATCH] md: convert compile time warnings into runtime warnings")
Fixes: 9be68dd7ac0e ("md: add error handling support for add_disk()")
Fixes: 7ad1069166c0 ("md: properly unwind when failing to add the kobject in md_alloc")
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Logan Gunthorpe <logang@deltatee.com>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Song Liu <song@kernel.org>
drivers/md/md.c