]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
f2fs: fix null reference error when checking end of zone
authorDaejun Park <daejun7.park@samsung.com>
Thu, 4 Jul 2024 01:01:21 +0000 (10:01 +0900)
committerJaegeuk Kim <jaegeuk@kernel.org>
Wed, 10 Jul 2024 22:47:57 +0000 (22:47 +0000)
This patch fixes a potentially null pointer being accessed by
is_end_zone_blkaddr() that checks the last block of a zone
when f2fs is mounted as a single device.

Fixes: e067dc3c6b9c ("f2fs: maintain six open zones for zoned devices")
Signed-off-by: Daejun Park <daejun7.park@samsung.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Reviewed-by: Daeho Jeong <daehojeong@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/data.c

index b6dcb3bcaef713795379830f3c8ffab15ac0497b..1aa7eefa659cbe998548aaca45ad1c5bc084919a 100644 (file)
@@ -925,6 +925,7 @@ alloc_new:
 #ifdef CONFIG_BLK_DEV_ZONED
 static bool is_end_zone_blkaddr(struct f2fs_sb_info *sbi, block_t blkaddr)
 {
+       struct block_device *bdev = sbi->sb->s_bdev;
        int devi = 0;
 
        if (f2fs_is_multi_device(sbi)) {
@@ -935,8 +936,9 @@ static bool is_end_zone_blkaddr(struct f2fs_sb_info *sbi, block_t blkaddr)
                        return false;
                }
                blkaddr -= FDEV(devi).start_blk;
+               bdev = FDEV(devi).bdev;
        }
-       return bdev_is_zoned(FDEV(devi).bdev) &&
+       return bdev_is_zoned(bdev) &&
                f2fs_blkz_is_seq(sbi, devi, blkaddr) &&
                (blkaddr % sbi->blocks_per_blkz == sbi->blocks_per_blkz - 1);
 }