Skip to content

Commit a26116c

Browse files
rafaelmsoaresmstsirkin
authored andcommitted
virtio_blk: Fix signedness bug in virtblk_prep_rq()
The virtblk_map_data() function returns negative error codes, however, the 'nents' field of vbr->sg_table is an unsigned int, which causes the error handling not to work correctly. Cc: [email protected] Fixes: 0e9911f ("virtio-blk: support mq_ops->queue_rqs()") Signed-off-by: Rafael Mendonca <[email protected]> Message-Id: <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]> Reviewed-by: Stefano Garzarella <[email protected]> Reviewed-by: Suwan Kim <[email protected]> Reviewed-by: Stefan Hajnoczi <[email protected]> Acked-by: Jason Wang <[email protected]>
1 parent 72455a1 commit a26116c

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

drivers/block/virtio_blk.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,14 +334,16 @@ static blk_status_t virtblk_prep_rq(struct blk_mq_hw_ctx *hctx,
334334
struct virtblk_req *vbr)
335335
{
336336
blk_status_t status;
337+
int num;
337338

338339
status = virtblk_setup_cmd(vblk->vdev, req, vbr);
339340
if (unlikely(status))
340341
return status;
341342

342-
vbr->sg_table.nents = virtblk_map_data(hctx, req, vbr);
343-
if (unlikely(vbr->sg_table.nents < 0))
343+
num = virtblk_map_data(hctx, req, vbr);
344+
if (unlikely(num < 0))
344345
return virtblk_fail_to_queue(req, -ENOMEM);
346+
vbr->sg_table.nents = num;
345347

346348
blk_mq_start_request(req);
347349

0 commit comments

Comments
 (0)