diff --git a/drivers/md/md.c b/drivers/md/md.c index 3c79243e9d07a6d0a6ede4c3048b15d20c19a07c..16a97dc385b493a3114582d9fcf3a510388760eb 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -7589,8 +7589,11 @@ static int md_ioctl(struct block_device *bdev, fmode_t mode, err = -EBUSY; goto out; } - WARN_ON_ONCE(test_bit(MD_CLOSING, &mddev->flags)); - set_bit(MD_CLOSING, &mddev->flags); + if (test_and_set_bit(MD_CLOSING, &mddev->flags)) { + mutex_unlock(&mddev->open_mutex); + err = -EBUSY; + goto out; + } did_set_md_closing = true; mutex_unlock(&mddev->open_mutex); sync_blockdev(bdev);