Commit 083a6a50 authored by Martijn Coenen's avatar Martijn Coenen Committed by Jens Axboe

loop: Remove sector_t truncation checks

sector_t is now always u64, so we don't need to check for truncation.
Signed-off-by: default avatarMartijn Coenen <maco@android.com>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 7c5014b0
...@@ -228,24 +228,20 @@ static void __loop_update_dio(struct loop_device *lo, bool dio) ...@@ -228,24 +228,20 @@ static void __loop_update_dio(struct loop_device *lo, bool dio)
blk_mq_unfreeze_queue(lo->lo_queue); blk_mq_unfreeze_queue(lo->lo_queue);
} }
static int static void
figure_loop_size(struct loop_device *lo, loff_t offset, loff_t sizelimit) figure_loop_size(struct loop_device *lo, loff_t offset, loff_t sizelimit)
{ {
loff_t size = get_size(offset, sizelimit, lo->lo_backing_file); loff_t size = get_size(offset, sizelimit, lo->lo_backing_file);
sector_t x = (sector_t)size;
struct block_device *bdev = lo->lo_device; struct block_device *bdev = lo->lo_device;
if (unlikely((loff_t)x != size))
return -EFBIG;
if (lo->lo_offset != offset) if (lo->lo_offset != offset)
lo->lo_offset = offset; lo->lo_offset = offset;
if (lo->lo_sizelimit != sizelimit) if (lo->lo_sizelimit != sizelimit)
lo->lo_sizelimit = sizelimit; lo->lo_sizelimit = sizelimit;
set_capacity(lo->lo_disk, x); set_capacity(lo->lo_disk, size);
bd_set_size(bdev, (loff_t)get_capacity(bdev->bd_disk) << 9); bd_set_size(bdev, (loff_t)get_capacity(bdev->bd_disk) << 9);
/* let user-space know about the new size */ /* let user-space know about the new size */
kobject_uevent(&disk_to_dev(bdev->bd_disk)->kobj, KOBJ_CHANGE); kobject_uevent(&disk_to_dev(bdev->bd_disk)->kobj, KOBJ_CHANGE);
return 0;
} }
static inline int static inline int
...@@ -1003,10 +999,8 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode, ...@@ -1003,10 +999,8 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
!file->f_op->write_iter) !file->f_op->write_iter)
lo_flags |= LO_FLAGS_READ_ONLY; lo_flags |= LO_FLAGS_READ_ONLY;
error = -EFBIG;
size = get_loop_size(lo, file); size = get_loop_size(lo, file);
if ((loff_t)(sector_t)size != size)
goto out_unlock;
error = loop_prepare_queue(lo); error = loop_prepare_queue(lo);
if (error) if (error)
goto out_unlock; goto out_unlock;
...@@ -1328,10 +1322,7 @@ loop_set_status(struct loop_device *lo, const struct loop_info64 *info) ...@@ -1328,10 +1322,7 @@ loop_set_status(struct loop_device *lo, const struct loop_info64 *info)
lo->lo_device->bd_inode->i_mapping->nrpages); lo->lo_device->bd_inode->i_mapping->nrpages);
goto out_unfreeze; goto out_unfreeze;
} }
if (figure_loop_size(lo, info->lo_offset, info->lo_sizelimit)) { figure_loop_size(lo, info->lo_offset, info->lo_sizelimit);
err = -EFBIG;
goto out_unfreeze;
}
} }
memcpy(lo->lo_file_name, info->lo_file_name, LO_NAME_SIZE); memcpy(lo->lo_file_name, info->lo_file_name, LO_NAME_SIZE);
...@@ -1534,7 +1525,9 @@ static int loop_set_capacity(struct loop_device *lo) ...@@ -1534,7 +1525,9 @@ static int loop_set_capacity(struct loop_device *lo)
if (unlikely(lo->lo_state != Lo_bound)) if (unlikely(lo->lo_state != Lo_bound))
return -ENXIO; return -ENXIO;
return figure_loop_size(lo, lo->lo_offset, lo->lo_sizelimit); figure_loop_size(lo, lo->lo_offset, lo->lo_sizelimit);
return 0;
} }
static int loop_set_dio(struct loop_device *lo, unsigned long arg) static int loop_set_dio(struct loop_device *lo, unsigned long arg)
......
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