Skip to content

Commit e9b0a15

Browse files
Li Nanliu-song-6
authored andcommitted
md: check mddev->pers before calling md_set_readonly()
If 'mddev->pers' is NULL, there is nothing to do in md_set_readonly(). Except for md_ioctl(), the other two callers of md_set_readonly() have already checked 'mddev->pers'. To simplify the code, move the check of 'mddev->pers' to the caller. Signed-off-by: Li Nan <[email protected]> Signed-off-by: Song Liu <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 650b2e6 commit e9b0a15

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

drivers/md/md.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6420,6 +6420,7 @@ void md_stop(struct mddev *mddev)
64206420

64216421
EXPORT_SYMBOL_GPL(md_stop);
64226422

6423+
/* ensure 'mddev->pers' exist before calling md_set_readonly() */
64236424
static int md_set_readonly(struct mddev *mddev)
64246425
{
64256426
int err = 0;
@@ -6444,20 +6445,18 @@ static int md_set_readonly(struct mddev *mddev)
64446445
goto out;
64456446
}
64466447

6447-
if (mddev->pers) {
6448-
__md_stop_writes(mddev);
6449-
6450-
if (mddev->ro == MD_RDONLY) {
6451-
err = -ENXIO;
6452-
goto out;
6453-
}
6448+
__md_stop_writes(mddev);
64546449

6455-
mddev->ro = MD_RDONLY;
6456-
set_disk_ro(mddev->gendisk, 1);
6450+
if (mddev->ro == MD_RDONLY) {
6451+
err = -ENXIO;
6452+
goto out;
64576453
}
64586454

6455+
mddev->ro = MD_RDONLY;
6456+
set_disk_ro(mddev->gendisk, 1);
6457+
64596458
out:
6460-
if ((mddev->pers && !err) || did_freeze) {
6459+
if (!err || did_freeze) {
64616460
clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery);
64626461
set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
64636462
sysfs_notify_dirent_safe(mddev->sysfs_state);
@@ -7730,7 +7729,8 @@ static int md_ioctl(struct block_device *bdev, blk_mode_t mode,
77307729
goto unlock;
77317730

77327731
case STOP_ARRAY_RO:
7733-
err = md_set_readonly(mddev);
7732+
if (mddev->pers)
7733+
err = md_set_readonly(mddev);
77347734
goto unlock;
77357735

77367736
case HOT_REMOVE_DISK:

0 commit comments

Comments
 (0)