History

scsi: storvsc: Fix storvsc_queuecommand() memory leak

Fix possible memory leak in error path of storvsc_queuecommand() when DMA mapping fails.

Juan Vazquez committed 4 years ago

Commit 4eea5331 parent 51500b71 file · +12 −5Browse files

Unified · Split

drivers/scsi/storvsc_drv.c+12−5
@@ -1850,8 +1850,10 @@ static int storvsc_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *scmnd) · 1849 unmodified lines
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) · 28 unmodified lines
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 = {