• Dan Carpenter's avatar
    btrfs: qgroup: delete unnecessary check in btrfs_qgroup_check_inherit() · 4a43d735
    Dan Carpenter authored
    This check "if (inherit->num_qgroups > PAGE_SIZE)" is confusing and
    unnecessary.
    
    The problem with the check is that static checkers flag it as a
    potential mixup of between units of bytes vs number of elements.
    Fortunately, the check can safely be deleted because the next check is
    correct and applies an even stricter limit:
    
    	if (size != struct_size(inherit, qgroups, inherit->num_qgroups))
    		return -EINVAL;
    
    The "inherit" struct ends in a variable array of __u64 and
    "inherit->num_qgroups" is the number of elements in the array.  At the
    start of the function we check that:
    
    	if (size < sizeof(*inherit) || size > PAGE_SIZE)
    		return -EINVAL;
    
    Thus, since we verify that the whole struct fits within one page, that
    means that the number of elements in the inherit->qgroups[] array must
    be less than PAGE_SIZE.
    Reviewed-by: default avatarQu Wenruo <wqu@suse.com>
    Signed-off-by: default avatarDan Carpenter <dan.carpenter@linaro.org>
    Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
    Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
    4a43d735
qgroup.c 128 KB