Merge git://git.kernel.org/pub/scm/linux/kernel/git/mason/btrfs-unstable
[pandora-kernel.git] / fs / btrfs / zlib.c
index ba2527d..3e2b90e 100644 (file)
@@ -30,6 +30,7 @@
 #include <linux/sched.h>
 #include <linux/pagemap.h>
 #include <linux/bio.h>
+#include "compression.h"
 
 /* Plan: call deflate() with avail_in == *sourcelen,
        avail_out = *dstlen - 12 and flush == Z_FINISH.
@@ -151,7 +152,7 @@ static int free_workspace(struct workspace *workspace)
 static void free_workspaces(void)
 {
        struct workspace *workspace;
-       while(!list_empty(&idle_workspace)) {
+       while (!list_empty(&idle_workspace)) {
                workspace = list_entry(idle_workspace.next, struct workspace,
                                       list);
                list_del(&workspace->list);
@@ -207,7 +208,7 @@ int btrfs_zlib_compress_pages(struct address_space *mapping,
        *total_in = 0;
 
        workspace = find_zlib_workspace();
-       if (!workspace)
+       if (IS_ERR(workspace))
                return -1;
 
        if (Z_OK != zlib_deflateInit(&workspace->def_strm, 3)) {
@@ -365,12 +366,12 @@ int btrfs_zlib_decompress_biovec(struct page **pages_in,
        char *kaddr;
 
        workspace = find_zlib_workspace();
-       if (!workspace)
+       if (IS_ERR(workspace))
                return -ENOMEM;
 
        data_in = kmap(pages_in[page_in_index]);
        workspace->inf_strm.next_in = data_in;
-       workspace->inf_strm.avail_in = min(srclen, PAGE_CACHE_SIZE);
+       workspace->inf_strm.avail_in = min_t(size_t, srclen, PAGE_CACHE_SIZE);
        workspace->inf_strm.total_in = 0;
 
        workspace->inf_strm.total_out = 0;
@@ -396,12 +397,10 @@ int btrfs_zlib_decompress_biovec(struct page **pages_in,
                ret = -1;
                goto out;
        }
-       while(workspace->inf_strm.total_in < srclen) {
+       while (workspace->inf_strm.total_in < srclen) {
                ret = zlib_inflate(&workspace->inf_strm, Z_NO_FLUSH);
-               if (ret != Z_OK && ret != Z_STREAM_END) {
+               if (ret != Z_OK && ret != Z_STREAM_END)
                        break;
-               }
-
                /*
                 * buf start is the byte offset we're of the start of
                 * our workspace buffer
@@ -423,16 +422,14 @@ int btrfs_zlib_decompress_biovec(struct page **pages_in,
                        /* we didn't make progress in this inflate
                         * call, we're done
                         */
-                       if (ret != Z_STREAM_END) {
+                       if (ret != Z_STREAM_END)
                                ret = -1;
-                       }
                        break;
                }
 
                /* we haven't yet hit data corresponding to this page */
-               if (total_out <= start_byte) {
+               if (total_out <= start_byte)
                        goto next;
-               }
 
                /*
                 * the start of the data we care about is offset into
@@ -447,7 +444,7 @@ int btrfs_zlib_decompress_biovec(struct page **pages_in,
                current_buf_start = buf_start;
 
                /* copy bytes from the working buffer into the pages */
-               while(working_bytes > 0) {
+               while (working_bytes > 0) {
                        bytes = min(PAGE_CACHE_SIZE - pg_offset,
                                    PAGE_CACHE_SIZE - buf_offset);
                        bytes = min(bytes, working_bytes);
@@ -470,6 +467,7 @@ int btrfs_zlib_decompress_biovec(struct page **pages_in,
                                        ret = 0;
                                        goto done;
                                }
+
                                page_out = bvec[page_out_index].bv_page;
                                pg_offset = 0;
                                page_bytes_left = PAGE_CACHE_SIZE;
@@ -479,9 +477,8 @@ int btrfs_zlib_decompress_biovec(struct page **pages_in,
                                 * make sure our new page is covered by this
                                 * working buffer
                                 */
-                               if (total_out <= start_byte) {
+                               if (total_out <= start_byte)
                                        goto next;
-                               }
 
                                /* the next page in the biovec might not
                                 * be adjacent to the last page, but it
@@ -516,11 +513,10 @@ next:
                                                           PAGE_CACHE_SIZE);
                }
        }
-       if (ret != Z_STREAM_END) {
+       if (ret != Z_STREAM_END)
                ret = -1;
-       } else {
+       else
                ret = 0;
-       }
 done:
        zlib_inflateEnd(&workspace->inf_strm);
        if (data_in)
@@ -551,7 +547,7 @@ int btrfs_zlib_decompress(unsigned char *data_in,
                return -ENOMEM;
 
        workspace = find_zlib_workspace();
-       if (!workspace)
+       if (IS_ERR(workspace))
                return -ENOMEM;
 
        workspace->inf_strm.next_in = data_in;
@@ -578,16 +574,15 @@ int btrfs_zlib_decompress(unsigned char *data_in,
                goto out;
        }
 
-       while(bytes_left > 0) {
+       while (bytes_left > 0) {
                unsigned long buf_start;
                unsigned long buf_offset;
                unsigned long bytes;
                unsigned long pg_offset = 0;
 
                ret = zlib_inflate(&workspace->inf_strm, Z_NO_FLUSH);
-               if (ret != Z_OK && ret != Z_STREAM_END) {
+               if (ret != Z_OK && ret != Z_STREAM_END)
                        break;
-               }
 
                buf_start = total_out;
                total_out = workspace->inf_strm.total_out;
@@ -597,15 +592,13 @@ int btrfs_zlib_decompress(unsigned char *data_in,
                        break;
                }
 
-               if (total_out <= start_byte) {
+               if (total_out <= start_byte)
                        goto next;
-               }
 
-               if (total_out > start_byte && buf_start < start_byte) {
+               if (total_out > start_byte && buf_start < start_byte)
                        buf_offset = start_byte - buf_start;
-               } else {
+               else
                        buf_offset = 0;
-               }
 
                bytes = min(PAGE_CACHE_SIZE - pg_offset,
                            PAGE_CACHE_SIZE - buf_offset);
@@ -621,11 +614,12 @@ next:
                workspace->inf_strm.next_out = workspace->buf;
                workspace->inf_strm.avail_out = PAGE_CACHE_SIZE;
        }
-       if (ret != Z_STREAM_END && bytes_left != 0) {
+
+       if (ret != Z_STREAM_END && bytes_left != 0)
                ret = -1;
-       } else {
+       else
                ret = 0;
-       }
+
        zlib_inflateEnd(&workspace->inf_strm);
 out:
        free_workspace(workspace);