Commit 8744de7f authored by Jan Kara's avatar Jan Kara Committed by Greg Kroah-Hartman

f2fs: avoid returning uninitialized value to userspace from f2fs_trim_fs()

commit 9bd27ae4 upstream.

If user specifies too low end sector for trimming, f2fs_trim_fs() will
use uninitialized value as a number of trimmed blocks and returns it to
userspace. Initialize number of trimmed blocks early to avoid the
problem.

Coverity-id: 1248809
Signed-off-by: default avatarJan Kara <jack@suse.cz>
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 83b12edd
...@@ -1004,6 +1004,7 @@ int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range) ...@@ -1004,6 +1004,7 @@ int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range)
range->len < sbi->blocksize) range->len < sbi->blocksize)
return -EINVAL; return -EINVAL;
cpc.trimmed = 0;
if (end <= MAIN_BLKADDR(sbi)) if (end <= MAIN_BLKADDR(sbi))
goto out; goto out;
...@@ -1015,7 +1016,6 @@ int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range) ...@@ -1015,7 +1016,6 @@ int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range)
cpc.trim_start = start_segno; cpc.trim_start = start_segno;
cpc.trim_end = end_segno; cpc.trim_end = end_segno;
cpc.trim_minlen = range->minlen >> sbi->log_blocksize; cpc.trim_minlen = range->minlen >> sbi->log_blocksize;
cpc.trimmed = 0;
/* do checkpoint to issue discard commands safely */ /* do checkpoint to issue discard commands safely */
write_checkpoint(sbi, &cpc); write_checkpoint(sbi, &cpc);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment