Skip to content

Commit

Permalink
[libata] restore sg on DMA mapping failure
Browse files Browse the repository at this point in the history
  • Loading branch information
Tejun Heo authored and Jeff Garzik committed Nov 5, 2005
1 parent fecb4a0 commit 537a95d
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions drivers/scsi/libata-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 537a95d

Please sign in to comment.