Re: [PATCH v4 01/10] loop: Factor out loop size validation

From: Ming Lei
Date: Wed Apr 29 2020 - 10:12:53 EST


On Wed, Apr 29, 2020 at 04:03:32PM +0200, Martijn Coenen wrote:
> Ensuring we don't truncate loff_t when casting to sector_t is done in
> multiple places; factor it out.
>
> Signed-off-by: Martijn Coenen <maco@xxxxxxxxxxx>
> ---
> drivers/block/loop.c | 25 ++++++++++++++++++++-----
> 1 file changed, 20 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/block/loop.c b/drivers/block/loop.c
> index f1754262fc94..396b8bd4d75c 100644
> --- a/drivers/block/loop.c
> +++ b/drivers/block/loop.c
> @@ -228,15 +228,30 @@ static void __loop_update_dio(struct loop_device *lo, bool dio)
> blk_mq_unfreeze_queue(lo->lo_queue);
> }
>
> +/**
> + * loop_validate_size() - validates that the passed in size fits in a sector_t
> + * @size: size to validate
> + */
> +static int
> +loop_validate_size(loff_t size)
> +{
> + if ((loff_t)(sector_t)size != size)
> + return -EFBIG;
> +
> + return 0;
> +}
> +

Now sector_t has been switched to u64 unconditionally, do we still need such
validation?


Thanks,
Ming