Skip to content

Commit 8637fa8

Browse files
Yongpeng Yangbrauner
authored andcommitted
block: add __must_check attribute to sb_min_blocksize()
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 a64e5a5 ("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>
1 parent 124af08 commit 8637fa8

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

block/bdev.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ int sb_set_blocksize(struct super_block *sb, int size)
231231

232232
EXPORT_SYMBOL(sb_set_blocksize);
233233

234-
int sb_min_blocksize(struct super_block *sb, int size)
234+
int __must_check sb_min_blocksize(struct super_block *sb, int size)
235235
{
236236
int minsize = bdev_logical_block_size(sb->s_bdev);
237237
if (size < minsize)

include/linux/fs.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3423,8 +3423,8 @@ static inline void remove_inode_hash(struct inode *inode)
34233423
extern void inode_sb_list_add(struct inode *inode);
34243424
extern void inode_add_lru(struct inode *inode);
34253425

3426-
extern int sb_set_blocksize(struct super_block *, int);
3427-
extern int sb_min_blocksize(struct super_block *, int);
3426+
int sb_set_blocksize(struct super_block *sb, int size);
3427+
int __must_check sb_min_blocksize(struct super_block *sb, int size);
34283428

34293429
int generic_file_mmap(struct file *, struct vm_area_struct *);
34303430
int generic_file_mmap_prepare(struct vm_area_desc *desc);

0 commit comments

Comments
 (0)