mm: strictly nested kmap_atomic()
[linux-2.6.git] / crypto / scatterwalk.c
index e93a8f6..41e529a 100644 (file)
@@ -13,6 +13,8 @@
  * any later version.
  *
  */
+
+#include <crypto/scatterwalk.h>
 #include <linux/kernel.h>
 #include <linux/mm.h>
 #include <linux/module.h>
 #include <linux/highmem.h>
 #include <linux/scatterlist.h>
 
-#include "internal.h"
-#include "scatterwalk.h"
-
-enum km_type crypto_km_types[] = {
-       KM_USER0,
-       KM_USER1,
-       KM_SOFTIRQ0,
-       KM_SOFTIRQ1,
-};
-EXPORT_SYMBOL_GPL(crypto_km_types);
-
 static inline void memcpy_dir(void *buf, void *sgdata, size_t nbytes, int out)
 {
        void *src = out ? buf : sgdata;
@@ -62,21 +53,22 @@ static void scatterwalk_pagedone(struct scatter_walk *walk, int out,
        if (out) {
                struct page *page;
 
-               page = walk->sg->page + ((walk->offset - 1) >> PAGE_SHIFT);
-               flush_dcache_page(page);
+               page = sg_page(walk->sg) + ((walk->offset - 1) >> PAGE_SHIFT);
+               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);
@@ -114,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);
 
@@ -121,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);