Skip to content

Commit

Permalink
scsi: storvsc: Fix storvsc_queuecommand() memory leak
Browse files Browse the repository at this point in the history
Fix possible memory leak in error path of storvsc_queuecommand() when
DMA mapping fails.

Signed-off-by: Juan Vazquez <juvazq@linux.microsoft.com>
Reviewed-by: Tianyu Lan <Tianyu.Lan@microsoft.com>
Link: https://lore.kernel.org/r/20220109001758.6401-1-juvazq@linux.microsoft.com
Signed-off-by: Wei Liu <wei.liu@kernel.org>
  • Loading branch information
Juan Vazquez authored and Wei Liu committed Jan 10, 2022
1 parent 51500b7 commit 4eea533
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions drivers/scsi/storvsc_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -1850,8 +1850,10 @@ static int storvsc_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *scmnd)
payload->range.offset = offset_in_hvpg;

sg_count = scsi_dma_map(scmnd);
if (sg_count < 0)
return SCSI_MLQUEUE_DEVICE_BUSY;
if (sg_count < 0) {
ret = SCSI_MLQUEUE_DEVICE_BUSY;
goto err_free_payload;
}

for_each_sg(sgl, sg, sg_count, j) {
/*
Expand Down Expand Up @@ -1886,13 +1888,18 @@ static int storvsc_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *scmnd)
put_cpu();

if (ret == -EAGAIN) {
if (payload_sz > sizeof(cmd_request->mpb))
kfree(payload);
/* no more space */
return SCSI_MLQUEUE_DEVICE_BUSY;
ret = SCSI_MLQUEUE_DEVICE_BUSY;
goto err_free_payload;
}

return 0;

err_free_payload:
if (payload_sz > sizeof(cmd_request->mpb))
kfree(payload);

return ret;
}

static struct scsi_host_template scsi_driver = {
Expand Down

0 comments on commit 4eea533

Please sign in to comment.