f2fs: bug fix on bit overflow from 32bits to 64bits
This patch fixes some bit overflows by the shift operations. Dan Carpenter reported potential bugs on bit overflows as follows. fs/f2fs/segment.c:910 submit_write_page() warn: should 'blk_addr << ((sbi)->log_blocksize - 9)' be a 64 bit type? fs/f2fs/checkpoint.c:429 get_valid_checkpoint() warn: should '1 << ()' be a 64 bit type? fs/f2fs/data.c:408 f2fs_readpage() warn: should 'blk_addr << ((sbi)->log_blocksize - 9)' be a 64 bit type? fs/f2fs/data.c:457 submit_read_page() warn: should 'blk_addr << ((sbi)->log_blocksize - 9)' be a 64 bit type? fs/f2fs/data.c:525 get_data_block_ro() warn: should 'i << blkbits' be a 64 bit type? Bug-Reported-by: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
This commit is contained in:
parent
3679556794
commit
f9a4e6df52
|
@ -426,7 +426,8 @@ int get_valid_checkpoint(struct f2fs_sb_info *sbi)
|
||||||
cp1 = validate_checkpoint(sbi, cp_start_blk_no, &cp1_version);
|
cp1 = validate_checkpoint(sbi, cp_start_blk_no, &cp1_version);
|
||||||
|
|
||||||
/* The second checkpoint pack should start at the next segment */
|
/* The second checkpoint pack should start at the next segment */
|
||||||
cp_start_blk_no += 1 << le32_to_cpu(fsb->log_blocks_per_seg);
|
cp_start_blk_no += ((unsigned long long)1) <<
|
||||||
|
le32_to_cpu(fsb->log_blocks_per_seg);
|
||||||
cp2 = validate_checkpoint(sbi, cp_start_blk_no, &cp2_version);
|
cp2 = validate_checkpoint(sbi, cp_start_blk_no, &cp2_version);
|
||||||
|
|
||||||
if (cp1 && cp2) {
|
if (cp1 && cp2) {
|
||||||
|
|
|
@ -525,7 +525,7 @@ static int get_data_block_ro(struct inode *inode, sector_t iblock,
|
||||||
!= (dn.data_blkaddr + i)) || maxblocks == i)
|
!= (dn.data_blkaddr + i)) || maxblocks == i)
|
||||||
break;
|
break;
|
||||||
map_bh(bh_result, inode->i_sb, dn.data_blkaddr);
|
map_bh(bh_result, inode->i_sb, dn.data_blkaddr);
|
||||||
bh_result->b_size = (i << blkbits);
|
bh_result->b_size = (((size_t)i) << blkbits);
|
||||||
}
|
}
|
||||||
f2fs_put_dnode(&dn);
|
f2fs_put_dnode(&dn);
|
||||||
trace_f2fs_get_data_block(inode, iblock, bh_result, 0);
|
trace_f2fs_get_data_block(inode, iblock, bh_result, 0);
|
||||||
|
|
|
@ -270,8 +270,8 @@ static void locate_dirty_segment(struct f2fs_sb_info *sbi, unsigned int segno)
|
||||||
static void f2fs_issue_discard(struct f2fs_sb_info *sbi,
|
static void f2fs_issue_discard(struct f2fs_sb_info *sbi,
|
||||||
block_t blkstart, block_t blklen)
|
block_t blkstart, block_t blklen)
|
||||||
{
|
{
|
||||||
sector_t start = ((sector_t)blkstart) << sbi->log_sectors_per_block;
|
sector_t start = SECTOR_FROM_BLOCK(sbi, blkstart);
|
||||||
sector_t len = ((sector_t)blklen) << sbi->log_sectors_per_block;
|
sector_t len = SECTOR_FROM_BLOCK(sbi, blklen);
|
||||||
blkdev_issue_discard(sbi->sb->s_bdev, start, len, GFP_NOFS, 0);
|
blkdev_issue_discard(sbi->sb->s_bdev, start, len, GFP_NOFS, 0);
|
||||||
trace_f2fs_issue_discard(sbi->sb, blkstart, blklen);
|
trace_f2fs_issue_discard(sbi->sb, blkstart, blklen);
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,9 +86,9 @@
|
||||||
#define TOTAL_SECS(sbi) (sbi->total_sections)
|
#define TOTAL_SECS(sbi) (sbi->total_sections)
|
||||||
|
|
||||||
#define SECTOR_FROM_BLOCK(sbi, blk_addr) \
|
#define SECTOR_FROM_BLOCK(sbi, blk_addr) \
|
||||||
(blk_addr << ((sbi)->log_blocksize - F2FS_LOG_SECTOR_SIZE))
|
(((sector_t)blk_addr) << (sbi)->log_sectors_per_block)
|
||||||
#define SECTOR_TO_BLOCK(sbi, sectors) \
|
#define SECTOR_TO_BLOCK(sbi, sectors) \
|
||||||
(sectors >> ((sbi)->log_blocksize - F2FS_LOG_SECTOR_SIZE))
|
(sectors >> (sbi)->log_sectors_per_block)
|
||||||
#define MAX_BIO_BLOCKS(max_hw_blocks) \
|
#define MAX_BIO_BLOCKS(max_hw_blocks) \
|
||||||
(min((int)max_hw_blocks, BIO_MAX_PAGES))
|
(min((int)max_hw_blocks, BIO_MAX_PAGES))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue