Skip to content

Commit 4eea533

Browse files
Juan Vazquezliuw
authored andcommitted
scsi: storvsc: Fix storvsc_queuecommand() memory leak
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>
1 parent 51500b7 commit 4eea533

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

drivers/scsi/storvsc_drv.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1850,8 +1850,10 @@ static int storvsc_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *scmnd)
18501850
payload->range.offset = offset_in_hvpg;
18511851

18521852
sg_count = scsi_dma_map(scmnd);
1853-
if (sg_count < 0)
1854-
return SCSI_MLQUEUE_DEVICE_BUSY;
1853+
if (sg_count < 0) {
1854+
ret = SCSI_MLQUEUE_DEVICE_BUSY;
1855+
goto err_free_payload;
1856+
}
18551857

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

18881890
if (ret == -EAGAIN) {
1889-
if (payload_sz > sizeof(cmd_request->mpb))
1890-
kfree(payload);
18911891
/* no more space */
1892-
return SCSI_MLQUEUE_DEVICE_BUSY;
1892+
ret = SCSI_MLQUEUE_DEVICE_BUSY;
1893+
goto err_free_payload;
18931894
}
18941895

18951896
return 0;
1897+
1898+
err_free_payload:
1899+
if (payload_sz > sizeof(cmd_request->mpb))
1900+
kfree(payload);
1901+
1902+
return ret;
18961903
}
18971904

18981905
static struct scsi_host_template scsi_driver = {

0 commit comments

Comments
 (0)