]> pilppa.com Git - linux-2.6-omap-h63xx.git/commitdiff
[libata] restore sg on DMA mapping failure
authorTejun Heo <htejun@gmail.com>
Sat, 5 Nov 2005 19:29:01 +0000 (14:29 -0500)
committerJeff Garzik <jgarzik@pobox.com>
Sat, 5 Nov 2005 19:29:01 +0000 (14:29 -0500)
drivers/scsi/libata-core.c

index e1346cddd37fa140335bd3c59c70680ab8b71146..1c1a7caf785e9e1fbf6659daa72c18d2004842e5 100644 (file)
@@ -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);