]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
block: add __must_check attribute to sb_min_blocksize()
authorYongpeng Yang <yangyongpeng@xiaomi.com>
Tue, 4 Nov 2025 12:50:10 +0000 (20:50 +0800)
committerChristian Brauner <brauner@kernel.org>
Wed, 5 Nov 2025 13:00:16 +0000 (14:00 +0100)
When sb_min_blocksize() returns 0 and the return value is not checked,
it may lead to a situation where sb->s_blocksize is 0 when
accessing the filesystem super block. After commit a64e5a596067bd
("bdev: add back PAGE_SIZE block size validation for
sb_set_blocksize()"), this becomes more likely to happen when the
block device’s logical_block_size is larger than PAGE_SIZE and the
filesystem is unformatted. Add the __must_check attribute to ensure
callers always check the return value.

Cc: stable@vger.kernel.org # v6.15
Suggested-by: Matthew Wilcox <willy@infradead.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Yongpeng Yang <yangyongpeng@xiaomi.com>
Link: https://patch.msgid.link/20251104125009.2111925-6-yangyongpeng.storage@gmail.com
Signed-off-by: Christian Brauner <brauner@kernel.org>
block/bdev.c
include/linux/fs.h

index 810707cca9703e274affc5a6a1fe0c2bcf169318..638f0cd458ae48821f372bcbba6b0ec9ce8ee479 100644 (file)
@@ -231,7 +231,7 @@ int sb_set_blocksize(struct super_block *sb, int size)
 
 EXPORT_SYMBOL(sb_set_blocksize);
 
-int sb_min_blocksize(struct super_block *sb, int size)
+int __must_check sb_min_blocksize(struct super_block *sb, int size)
 {
        int minsize = bdev_logical_block_size(sb->s_bdev);
        if (size < minsize)
index c895146c1444be36e0a779df55622cc38c9419ff..3ea98c6cce818c15b79dcfb2a952cb6f91c9d6b7 100644 (file)
@@ -3423,8 +3423,8 @@ static inline void remove_inode_hash(struct inode *inode)
 extern void inode_sb_list_add(struct inode *inode);
 extern void inode_add_lru(struct inode *inode);
 
-extern int sb_set_blocksize(struct super_block *, int);
-extern int sb_min_blocksize(struct super_block *, int);
+int sb_set_blocksize(struct super_block *sb, int size);
+int __must_check sb_min_blocksize(struct super_block *sb, int size);
 
 int generic_file_mmap(struct file *, struct vm_area_struct *);
 int generic_file_mmap_prepare(struct vm_area_desc *desc);