diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c index 7ffd719d89de..f817bc651ed3 100644 --- a/drivers/block/virtio_blk.c +++ b/drivers/block/virtio_blk.c @@ -282,8 +282,6 @@ static blk_status_t virtio_queue_rq(struct blk_mq_hw_ctx *hctx, bool unmap = false; u32 type; - BUG_ON(req->nr_phys_segments + 2 > vblk->sg_elems); - switch (req_op(req)) { case REQ_OP_READ: case REQ_OP_WRITE: @@ -311,6 +309,10 @@ static blk_status_t virtio_queue_rq(struct blk_mq_hw_ctx *hctx, return BLK_STS_IOERR; } + BUG_ON(type != VIRTIO_BLK_T_DISCARD && + type != VIRTIO_BLK_T_WRITE_ZEROES && + (req->nr_phys_segments + 2 > vblk->sg_elems)); + vbr->out_hdr.type = cpu_to_virtio32(vblk->vdev, type); vbr->out_hdr.sector = type ? 0 : cpu_to_virtio64(vblk->vdev, blk_rq_pos(req));