Commit 4eea5332 authored by Juan Vazquez's avatar Juan Vazquez Committed by Wei Liu

scsi: storvsc: Fix storvsc_queuecommand() memory leak

Fix possible memory leak in error path of storvsc_queuecommand() when
DMA mapping fails.
Signed-off-by: default avatarJuan Vazquez <juvazq@linux.microsoft.com>
Reviewed-by: default avatarTianyu Lan <Tianyu.Lan@microsoft.com>
Link: https://lore.kernel.org/r/20220109001758.6401-1-juvazq@linux.microsoft.comSigned-off-by: default avatarWei Liu <wei.liu@kernel.org>
parent 51500b71
......@@ -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) {
/*
......@@ -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 = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment