md: fix mddev->kobj lifetime
authorChristoph Hellwig <hch@lst.de>
Tue, 19 Jul 2022 09:18:15 +0000 (11:18 +0200)
committerSong Liu <song@kernel.org>
Wed, 20 Jul 2022 05:33:21 +0000 (22:33 -0700)
commit069cce613a4a06bf76cd6c1f1158f24c44c3426c
tree293e3e365b87938a84cd82177bcd601c2fbc38c9
parentf68c68c0a6d522ad2509a87e28b6ef3e46992f12
md: fix mddev->kobj lifetime

Once a kobject is initialized, the containing object should not be
directly freed.  So delay initialization until it is added.  Also
remove the kobject_del call as the last put will remove the kobject as
well.  The explicitly delete isn't needed here, and dropping it will
simplify further fixes.

With this md_free now does not need to check that ->gendisk is non-NULL
as it is always set by the time that kobject_init is called on
mddev->kobj.

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