io_uring/net: un-indent mshot retry path in io_recv_finish()
[platform/kernel/linux-rpi.git] / block / ioctl.c
index d5f5cd6..d1d8e83 100644 (file)
@@ -18,10 +18,8 @@ static int blkpg_do_ioctl(struct block_device *bdev,
 {
        struct gendisk *disk = bdev->bd_disk;
        struct blkpg_partition p;
-       long long start, length;
+       sector_t start, length;
 
-       if (disk->flags & GENHD_FL_NO_PART)
-               return -EINVAL;
        if (!capable(CAP_SYS_ADMIN))
                return -EACCES;
        if (copy_from_user(&p, upart, sizeof(struct blkpg_partition)))
@@ -35,14 +33,17 @@ static int blkpg_do_ioctl(struct block_device *bdev,
        if (op == BLKPG_DEL_PARTITION)
                return bdev_del_partition(disk, p.pno);
 
+       if (p.start < 0 || p.length <= 0 || p.start + p.length < 0)
+               return -EINVAL;
+       /* Check that the partition is aligned to the block size */
+       if (!IS_ALIGNED(p.start | p.length, bdev_logical_block_size(bdev)))
+               return -EINVAL;
+
        start = p.start >> SECTOR_SHIFT;
        length = p.length >> SECTOR_SHIFT;
 
        switch (op) {
        case BLKPG_ADD_PARTITION:
-               /* check if partition is aligned to blocksize */
-               if (p.start & (bdev_logical_block_size(bdev) - 1))
-                       return -EINVAL;
                return bdev_add_partition(disk, p.pno, start, length);
        case BLKPG_RESIZE_PARTITION:
                return bdev_resize_partition(disk, p.pno, start, length);