]> Pileus Git - ~andy/linux/commitdiff
btrfs: Return EINVAL when length to trim is less than FSB
authorLukas Czerner <lczerner@redhat.com>
Tue, 16 Oct 2012 09:34:36 +0000 (09:34 +0000)
committerChris Mason <chris.mason@fusionio.com>
Thu, 25 Oct 2012 19:46:22 +0000 (15:46 -0400)
Currently if len argument in btrfs_ioctl_fitrim() is smaller than
one FSB we will continue and finally return 0 bytes discarded.
However if the length to discard is smaller then file system block
we should really return EINVAL.

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
fs/btrfs/ioctl.c

index f5a2e6c4320ae9e4283800ff2b0e6c4bbe60687a..da518ded34bd620646087772d64cd256c346ebf7 100644 (file)
@@ -343,7 +343,8 @@ static noinline int btrfs_ioctl_fitrim(struct file *file, void __user *arg)
                return -EOPNOTSUPP;
        if (copy_from_user(&range, arg, sizeof(range)))
                return -EFAULT;
-       if (range.start > total_bytes)
+       if (range.start > total_bytes ||
+           range.len < fs_info->sb->s_blocksize)
                return -EINVAL;
 
        range.len = min(range.len, total_bytes - range.start);