]> err.no Git - linux-2.6/commitdiff
Fix loop terminating conditions in fill_sg().
authorDavid S. Miller <davem@sunset.davemloft.net>
Wed, 17 Oct 2007 11:08:48 +0000 (04:08 -0700)
committerJens Axboe <jens.axboe@oracle.com>
Wed, 17 Oct 2007 11:11:59 +0000 (13:11 +0200)
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
arch/sparc64/kernel/iommu.c
arch/sparc64/kernel/pci_sun4v.c

index 5d4e96dba412bc8028c37a586f939b0459203ba7..29af777d7ac920d138d9c8e7598f5fbd0d14a3de 100644 (file)
@@ -475,12 +475,11 @@ static void dma_4u_unmap_single(struct device *dev, dma_addr_t bus_addr,
 #define SG_ENT_PHYS_ADDRESS(SG)        \
        (__pa(page_address((SG)->page)) + (SG)->offset)
 
-static inline void fill_sg(iopte_t *iopte, struct scatterlist *sg,
-                          int nused, int nelems,
-                          unsigned long iopte_protection)
+static void fill_sg(iopte_t *iopte, struct scatterlist *sg,
+                   int nused, int nelems,
+                   unsigned long iopte_protection)
 {
        struct scatterlist *dma_sg = sg;
-       struct scatterlist *sg_end = sg_last(sg, nelems);
        int i;
 
        for (i = 0; i < nused; i++) {
@@ -516,6 +515,7 @@ static inline void fill_sg(iopte_t *iopte, struct scatterlist *sg,
                                        break;
                                }
                                sg = sg_next(sg);
+                               nelems--;
                        }
 
                        pteval = iopte_protection | (pteval & IOPTE_PAGE);
@@ -529,18 +529,20 @@ static inline void fill_sg(iopte_t *iopte, struct scatterlist *sg,
 
                        pteval = (pteval & IOPTE_PAGE) + len;
                        sg = sg_next(sg);
+                       nelems--;
 
                        /* Skip over any tail mappings we've fully mapped,
                         * adjusting pteval along the way.  Stop when we
                         * detect a page crossing event.
                         */
-                       while (sg != sg_end &&
+                       while (nelems &&
                               (pteval << (64 - IO_PAGE_SHIFT)) != 0UL &&
                               (pteval == SG_ENT_PHYS_ADDRESS(sg)) &&
                               ((pteval ^
                                 (SG_ENT_PHYS_ADDRESS(sg) + sg->length - 1UL)) >> IO_PAGE_SHIFT) == 0UL) {
                                pteval += sg->length;
                                sg = sg_next(sg);
+                               nelems--;
                        }
                        if ((pteval << (64 - IO_PAGE_SHIFT)) == 0UL)
                                pteval = ~0UL;
index 119f8efa03d207966e398acbec946c125fee833d..fe46ace3e59f6582a185b72641363f03d2966d3a 100644 (file)
@@ -368,12 +368,11 @@ static void dma_4v_unmap_single(struct device *dev, dma_addr_t bus_addr,
 #define SG_ENT_PHYS_ADDRESS(SG)        \
        (__pa(page_address((SG)->page)) + (SG)->offset)
 
-static inline long fill_sg(long entry, struct device *dev,
-                          struct scatterlist *sg,
-                          int nused, int nelems, unsigned long prot)
+static long fill_sg(long entry, struct device *dev,
+                   struct scatterlist *sg,
+                   int nused, int nelems, unsigned long prot)
 {
        struct scatterlist *dma_sg = sg;
-       struct scatterlist *sg_end = sg_last(sg, nelems);
        unsigned long flags;
        int i;
 
@@ -414,6 +413,7 @@ static inline long fill_sg(long entry, struct device *dev,
                                        break;
                                }
                                sg = sg_next(sg);
+                               nelems--;
                        }
 
                        pteval = (pteval & IOPTE_PAGE);
@@ -432,19 +432,20 @@ static inline long fill_sg(long entry, struct device *dev,
 
                        pteval = (pteval & IOPTE_PAGE) + len;
                        sg = sg_next(sg);
+                       nelems--;
 
                        /* Skip over any tail mappings we've fully mapped,
                         * adjusting pteval along the way.  Stop when we
                         * detect a page crossing event.
                         */
-                       while ((pteval << (64 - IO_PAGE_SHIFT)) != 0UL &&
+                       while (nelems &&
+                              (pteval << (64 - IO_PAGE_SHIFT)) != 0UL &&
                               (pteval == SG_ENT_PHYS_ADDRESS(sg)) &&
                               ((pteval ^
                                 (SG_ENT_PHYS_ADDRESS(sg) + sg->length - 1UL)) >> IO_PAGE_SHIFT) == 0UL) {
                                pteval += sg->length;
-                               if (sg == sg_end)
-                                       break;
                                sg = sg_next(sg);
+                               nelems--;
                        }
                        if ((pteval << (64 - IO_PAGE_SHIFT)) == 0UL)
                                pteval = ~0UL;