diff options
author | Tejun Heo <htejun@gmail.com> | 2006-02-20 09:48:38 -0500 |
---|---|---|
committer | Jeff Garzik <jgarzik@pobox.com> | 2006-02-20 16:48:18 -0500 |
commit | 2e242fa994428bd1a40b6a7e97430413246d0a16 (patch) | |
tree | 8ba101ac6b2f9d6e5d14eebb9091d43c9177626c /drivers | |
parent | cc1887f3d8ae8ea61efa1a75af8ec0467b9dd546 (diff) |
[PATCH] libata: make ata_sg_setup_one() trim zero length sg
This patch makes ata_sg_setup_one() trim sg entry (thus making
qc->n_elem zero) if padding results in zero length sg entry.
Signed-off-by: Tejun Heo <htejun@gmail.com>
Signed-off-by: Jeff Garzik <jgarzik@pobox.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/scsi/libata-core.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/drivers/scsi/libata-core.c b/drivers/scsi/libata-core.c index bbac87a13d57..5f1d7580218d 100644 --- a/drivers/scsi/libata-core.c +++ b/drivers/scsi/libata-core.c | |||
@@ -2514,7 +2514,7 @@ static void ata_sg_clean(struct ata_queued_cmd *qc) | |||
2514 | assert(sg != NULL); | 2514 | assert(sg != NULL); |
2515 | 2515 | ||
2516 | if (qc->flags & ATA_QCFLAG_SINGLE) | 2516 | if (qc->flags & ATA_QCFLAG_SINGLE) |
2517 | assert(qc->n_elem == 1); | 2517 | assert(qc->n_elem <= 1); |
2518 | 2518 | ||
2519 | VPRINTK("unmapping %u sg elements\n", qc->n_elem); | 2519 | VPRINTK("unmapping %u sg elements\n", qc->n_elem); |
2520 | 2520 | ||
@@ -2537,7 +2537,7 @@ static void ata_sg_clean(struct ata_queued_cmd *qc) | |||
2537 | kunmap_atomic(addr, KM_IRQ0); | 2537 | kunmap_atomic(addr, KM_IRQ0); |
2538 | } | 2538 | } |
2539 | } else { | 2539 | } else { |
2540 | if (sg_dma_len(&sg[0]) > 0) | 2540 | if (qc->n_elem) |
2541 | dma_unmap_single(ap->host_set->dev, | 2541 | dma_unmap_single(ap->host_set->dev, |
2542 | sg_dma_address(&sg[0]), sg_dma_len(&sg[0]), | 2542 | sg_dma_address(&sg[0]), sg_dma_len(&sg[0]), |
2543 | dir); | 2543 | dir); |
@@ -2715,6 +2715,7 @@ static int ata_sg_setup_one(struct ata_queued_cmd *qc) | |||
2715 | int dir = qc->dma_dir; | 2715 | int dir = qc->dma_dir; |
2716 | struct scatterlist *sg = qc->__sg; | 2716 | struct scatterlist *sg = qc->__sg; |
2717 | dma_addr_t dma_address; | 2717 | dma_addr_t dma_address; |
2718 | int trim_sg = 0; | ||
2718 | 2719 | ||
2719 | /* we must lengthen transfers to end on a 32-bit boundary */ | 2720 | /* we must lengthen transfers to end on a 32-bit boundary */ |
2720 | qc->pad_len = sg->length & 3; | 2721 | qc->pad_len = sg->length & 3; |
@@ -2734,13 +2735,15 @@ static int ata_sg_setup_one(struct ata_queued_cmd *qc) | |||
2734 | sg_dma_len(psg) = ATA_DMA_PAD_SZ; | 2735 | sg_dma_len(psg) = ATA_DMA_PAD_SZ; |
2735 | /* trim sg */ | 2736 | /* trim sg */ |
2736 | sg->length -= qc->pad_len; | 2737 | sg->length -= qc->pad_len; |
2738 | if (sg->length == 0) | ||
2739 | trim_sg = 1; | ||
2737 | 2740 | ||
2738 | DPRINTK("padding done, sg->length=%u pad_len=%u\n", | 2741 | DPRINTK("padding done, sg->length=%u pad_len=%u\n", |
2739 | sg->length, qc->pad_len); | 2742 | sg->length, qc->pad_len); |
2740 | } | 2743 | } |
2741 | 2744 | ||
2742 | if (!sg->length) { | 2745 | if (trim_sg) { |
2743 | sg_dma_address(sg) = 0; | 2746 | qc->n_elem--; |
2744 | goto skip_map; | 2747 | goto skip_map; |
2745 | } | 2748 | } |
2746 | 2749 | ||
@@ -2753,9 +2756,9 @@ static int ata_sg_setup_one(struct ata_queued_cmd *qc) | |||
2753 | } | 2756 | } |
2754 | 2757 | ||
2755 | sg_dma_address(sg) = dma_address; | 2758 | sg_dma_address(sg) = dma_address; |
2756 | skip_map: | ||
2757 | sg_dma_len(sg) = sg->length; | 2759 | sg_dma_len(sg) = sg->length; |
2758 | 2760 | ||
2761 | skip_map: | ||
2759 | DPRINTK("mapped buffer of %d bytes for %s\n", sg_dma_len(sg), | 2762 | DPRINTK("mapped buffer of %d bytes for %s\n", sg_dma_len(sg), |
2760 | qc->tf.flags & ATA_TFLAG_WRITE ? "write" : "read"); | 2763 | qc->tf.flags & ATA_TFLAG_WRITE ? "write" : "read"); |
2761 | 2764 | ||