mm: strictly nested kmap_atomic()
[linux-2.6.git] / crypto / scatterwalk.c
index 12d1901..41e529a 100644 (file)
@@ -54,20 +54,21 @@ static void scatterwalk_pagedone(struct scatter_walk *walk, int out,
                struct page *page;
 
                page = sg_page(walk->sg) + ((walk->offset - 1) >> PAGE_SHIFT);
-               flush_dcache_page(page);
+               if (!PageSlab(page))
+                       flush_dcache_page(page);
        }
 
        if (more) {
                walk->offset += PAGE_SIZE - 1;
                walk->offset &= PAGE_MASK;
                if (walk->offset >= walk->sg->offset + walk->sg->length)
-                       scatterwalk_start(walk, sg_next(walk->sg));
+                       scatterwalk_start(walk, scatterwalk_sg_next(walk->sg));
        }
 }
 
 void scatterwalk_done(struct scatter_walk *walk, int out, int more)
 {
-       if (!offset_in_page(walk->offset) || !more)
+       if (!(scatterwalk_pagelen(walk) & (PAGE_SIZE - 1)) || !more)
                scatterwalk_pagedone(walk, out, more);
 }
 EXPORT_SYMBOL_GPL(scatterwalk_done);
@@ -105,6 +106,9 @@ void scatterwalk_map_and_copy(void *buf, struct scatterlist *sg,
        struct scatter_walk walk;
        unsigned int offset = 0;
 
+       if (!nbytes)
+               return;
+
        for (;;) {
                scatterwalk_start(&walk, sg);
 
@@ -112,7 +116,7 @@ void scatterwalk_map_and_copy(void *buf, struct scatterlist *sg,
                        break;
 
                offset += sg->length;
-               sg = sg_next(sg);
+               sg = scatterwalk_sg_next(sg);
        }
 
        scatterwalk_advance(&walk, start - offset);