From 537a95d9351f41cc3c24ddb2a646aedd6debb21b Mon Sep 17 00:00:00 2001 From: Tejun Heo Date: Sat, 5 Nov 2005 14:29:01 -0500 Subject: [libata] restore sg on DMA mapping failure --- drivers/scsi/libata-core.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/libata-core.c b/drivers/scsi/libata-core.c index e1346cddd37..1c1a7caf785 100644 --- a/drivers/scsi/libata-core.c +++ b/drivers/scsi/libata-core.c @@ -2622,8 +2622,11 @@ static int ata_sg_setup_one(struct ata_queued_cmd *qc) dma_address = dma_map_single(ap->host_set->dev, qc->buf_virt, sg->length, dir); - if (dma_mapping_error(dma_address)) + if (dma_mapping_error(dma_address)) { + /* restore sg */ + sg->length += qc->pad_len; return -1; + } sg_dma_address(sg) = dma_address; sg_dma_len(sg) = sg->length; @@ -2694,8 +2697,11 @@ static int ata_sg_setup(struct ata_queued_cmd *qc) dir = qc->dma_dir; n_elem = dma_map_sg(ap->host_set->dev, sg, qc->n_elem, dir); - if (n_elem < 1) + if (n_elem < 1) { + /* restore last sg */ + lsg->length += qc->pad_len; return -1; + } DPRINTK("%d sg elements mapped\n", n_elem); -- cgit v1.2.2