@@ -299,13 +299,6 @@ int blkdev_issue_secure_erase(struct block_device *bdev, sector_t sector,
max_sectors = UINT_MAX >> SECTOR_SHIFT;
max_sectors &= ~bs_mask;
- if (max_sectors == 0)
- return -EOPNOTSUPP;
- if ((sector | nr_sects) & bs_mask)
- return -EINVAL;
- if (bdev_read_only(bdev))
- return -EPERM;
-
blk_start_plug(&plug);
while (nr_sects) {
unsigned int len = min_t(sector_t, nr_sects, max_sectors);
@@ -163,6 +163,7 @@ static int blk_ioctl_discard(struct block_device *bdev, blk_mode_t mode,
static int blk_ioctl_secure_erase(struct block_device *bdev, blk_mode_t mode,
void __user *argp)
{
+ unsigned int bs_mask = bdev_logical_block_size(bdev) - 1;
uint64_t start, len;
uint64_t range[2];
int err;
@@ -171,12 +172,17 @@ static int blk_ioctl_secure_erase(struct block_device *bdev, blk_mode_t mode,
return -EBADF;
if (!bdev_max_secure_erase_sectors(bdev))
return -EOPNOTSUPP;
+ if (bdev_read_only(bdev))
+ return -EPERM;
if (copy_from_user(range, argp, sizeof(range)))
return -EFAULT;
start = range[0];
len = range[1];
- if ((start & 511) || (len & 511))
+
+ if (!len)
+ return -EINVAL;
+ if ((start | len) & bs_mask)
return -EINVAL;
if (start + len > bdev_nr_bytes(bdev))
return -EINVAL;
Most bio operations get basic sanity checking in submit_bio and anything more complicated than that is done in the callers. Secure erase is a bit different from that in that a lot of checking is done in blkdev_issue_secure_erase, and the specific errnos for that are returned to userspace. Move the checks that require specific errnos to the ioctl handler instead, and just leave the basic sanity checking in submit_bio Signed-off-by: Christoph Hellwig <hch@lst.de> --- block/blk-lib.c | 7 ------- block/ioctl.c | 8 +++++++- 2 files changed, 7 insertions(+), 8 deletions(-)