Skip to content

Commit 3273d8a

Browse files
chaseyuJaegeuk Kim
authored andcommitted
f2fs: fix to do cast in F2FS_{BLK_TO_BYTES, BTYES_TO_BLK} to avoid overflow
It missed to cast variable to unsigned long long type before bit shift, which will cause overflow, fix it. Fixes: f7ef9b8 ("f2fs: introduce macros to convert bytes and blocks in f2fs") Signed-off-by: Chao Yu <[email protected]> Signed-off-by: Jaegeuk Kim <[email protected]>
1 parent 789ca0e commit 3273d8a

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

fs/f2fs/super.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3344,7 +3344,7 @@ loff_t max_file_blocks(struct inode *inode)
33443344
* fit within U32_MAX + 1 data units.
33453345
*/
33463346

3347-
result = min(result, F2FS_BYTES_TO_BLK(((loff_t)U32_MAX + 1) * 4096));
3347+
result = umin(result, F2FS_BYTES_TO_BLK(((loff_t)U32_MAX + 1) * 4096));
33483348

33493349
return result;
33503350
}

include/linux/f2fs_fs.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
#define NEW_ADDR ((block_t)-1) /* used as block_t addresses */
2525
#define COMPRESS_ADDR ((block_t)-2) /* used as compressed data flag */
2626

27-
#define F2FS_BYTES_TO_BLK(bytes) ((bytes) >> F2FS_BLKSIZE_BITS)
28-
#define F2FS_BLK_TO_BYTES(blk) ((blk) << F2FS_BLKSIZE_BITS)
27+
#define F2FS_BYTES_TO_BLK(bytes) ((unsigned long long)(bytes) >> F2FS_BLKSIZE_BITS)
28+
#define F2FS_BLK_TO_BYTES(blk) ((unsigned long long)(blk) << F2FS_BLKSIZE_BITS)
2929
#define F2FS_BLK_END_BYTES(blk) (F2FS_BLK_TO_BYTES(blk + 1) - 1)
30-
#define F2FS_BLK_ALIGN(x) (F2FS_BYTES_TO_BLK((x) + F2FS_BLKSIZE - 1))
30+
#define F2FS_BLK_ALIGN(x) (F2FS_BYTES_TO_BLK((x) + F2FS_BLKSIZE - 1))
3131

3232
/* 0, 1(node nid), 2(meta nid) are reserved node id */
3333
#define F2FS_RESERVED_NODE_NUM 3

0 commit comments

Comments
 (0)