Skip to content

Commit a72cbf8

Browse files
liu-song-6shligit
authored andcommitted
md/r5cache: call mddev_lock/unlock() in r5c_journal_mode_show
In r5c_journal_mode_show(), it is necessary to call mddev_lock() before accessing conf and conf->log. Otherwise, the conf->log may change (and become NULL). Signed-off-by: Song Liu <[email protected]> Reported-by: Stephen Rothwell <[email protected]> Reported-by: kbuild test robot <[email protected]> Signed-off-by: Shaohua Li <[email protected]>
1 parent 26e1304 commit a72cbf8

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

drivers/md/raid5-cache.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2529,11 +2529,18 @@ static void r5l_write_super(struct r5l_log *log, sector_t cp)
25292529

25302530
static ssize_t r5c_journal_mode_show(struct mddev *mddev, char *page)
25312531
{
2532-
struct r5conf *conf = mddev->private;
2532+
struct r5conf *conf;
25332533
int ret;
25342534

2535-
if (!conf->log)
2535+
ret = mddev_lock(mddev);
2536+
if (ret)
2537+
return ret;
2538+
2539+
conf = mddev->private;
2540+
if (!conf || !conf->log) {
2541+
mddev_unlock(mddev);
25362542
return 0;
2543+
}
25372544

25382545
switch (conf->log->r5c_journal_mode) {
25392546
case R5C_JOURNAL_MODE_WRITE_THROUGH:
@@ -2551,6 +2558,7 @@ static ssize_t r5c_journal_mode_show(struct mddev *mddev, char *page)
25512558
default:
25522559
ret = 0;
25532560
}
2561+
mddev_unlock(mddev);
25542562
return ret;
25552563
}
25562564

0 commit comments

Comments
 (0)