--- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -636,6 +636,12 @@ static void __mddev_put(struct mddev *mddev) mddev->ctime || mddev->hold_active) return; + /* + * If array is freed by stopping array, MD_DELETED is set by + * do_md_stop(), MD_DELETED is still set here in cause mddev is freed + * directly by closing a mddev that is created by create_on_open. + */ + set_bit(MD_DELETED, &mddev->flags); /* * Call queue_work inside the spinlock so that flush_workqueue() after * mddev_find will succeed in waiting for the work to be done.