Merge branch 'master'
[linux-2.6.git] / drivers / scsi / sata_mv.c
index 46dbdee79f77af8d51ecbe334323bea22c2f641c..64af334e71f49daaad0622a384fc20e11e6015ef 100644 (file)
@@ -784,23 +784,24 @@ static void mv_port_stop(struct ata_port *ap)
 static void mv_fill_sg(struct ata_queued_cmd *qc)
 {
        struct mv_port_priv *pp = qc->ap->private_data;
-       unsigned int i;
+       unsigned int i = 0;
+       struct scatterlist *sg;
 
-       for (i = 0; i < qc->n_elem; i++) {
+       ata_for_each_sg(sg, qc) {
                u32 sg_len;
                dma_addr_t addr;
 
-               addr = sg_dma_address(&qc->sg[i]);
-               sg_len = sg_dma_len(&qc->sg[i]);
+               addr = sg_dma_address(sg);
+               sg_len = sg_dma_len(sg);
 
                pp->sg_tbl[i].addr = cpu_to_le32(addr & 0xffffffff);
                pp->sg_tbl[i].addr_hi = cpu_to_le32((addr >> 16) >> 16);
                assert(0 == (sg_len & ~MV_DMA_BOUNDARY));
                pp->sg_tbl[i].flags_size = cpu_to_le32(sg_len);
-       }
-       if (0 < qc->n_elem) {
-               pp->sg_tbl[qc->n_elem - 1].flags_size |= 
-                       cpu_to_le32(EPRD_FLAG_END_OF_TBL);
+               if (ata_sg_is_last(sg, qc))
+                       pp->sg_tbl[i].flags_size |= cpu_to_le32(EPRD_FLAG_END_OF_TBL);
+
+               i++;
        }
 }