Merge 3.8-rc5 into staging-next
[firefly-linux-kernel-4.4.55.git] / drivers / staging / zram / zram_drv.c
index f2a73bd739fb94b750e66e1ee2c931e3c971a52a..77a3f0dfba770821ebe8aef3ce3229bfa1163078 100644 (file)
@@ -40,17 +40,7 @@ static int zram_major;
 struct zram *zram_devices;
 
 /* Module params (documentation at end) */
-static unsigned int num_devices;
-
-static void zram_stat_inc(u32 *v)
-{
-       *v = *v + 1;
-}
-
-static void zram_stat_dec(u32 *v)
-{
-       *v = *v - 1;
-}
+static unsigned int num_devices = 1;
 
 static void zram_stat64_add(struct zram *zram, u64 *v, u64 inc)
 {
@@ -126,8 +116,7 @@ static void zram_set_disksize(struct zram *zram, size_t totalram_bytes)
                "\tMemory Size: %zu kB\n"
                "\tSize you selected: %llu kB\n"
                "Continuing anyway ...\n",
-               totalram_bytes >> 10, zram->disksize
-               );
+               totalram_bytes >> 10, zram->disksize >> 10);
        }
 
        zram->disksize &= PAGE_MASK;
@@ -145,22 +134,22 @@ static void zram_free_page(struct zram *zram, size_t index)
                 */
                if (zram_test_flag(zram, index, ZRAM_ZERO)) {
                        zram_clear_flag(zram, index, ZRAM_ZERO);
-                       zram_stat_dec(&zram->stats.pages_zero);
+                       zram->stats.pages_zero--;
                }
                return;
        }
 
        if (unlikely(size > max_zpage_size))
-               zram_stat_dec(&zram->stats.bad_compress);
+               zram->stats.bad_compress--;
 
        zs_free(zram->mem_pool, handle);
 
        if (size <= PAGE_SIZE / 2)
-               zram_stat_dec(&zram->stats.good_compress);
+               zram->stats.good_compress--;
 
        zram_stat64_sub(zram, &zram->stats.compr_size,
                        zram->table[index].size);
-       zram_stat_dec(&zram->stats.pages_stored);
+       zram->stats.pages_stored--;
 
        zram->table[index].handle = 0;
        zram->table[index].size = 0;
@@ -310,9 +299,10 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,
        }
 
        if (page_zero_filled(uncmem)) {
-               if (!is_partial_io(bvec))
-                       kunmap_atomic(user_mem);
-               zram_stat_inc(&zram->stats.pages_zero);
+               kunmap_atomic(user_mem);
+               if (is_partial_io(bvec))
+                       kfree(uncmem);
+               zram->stats.pages_zero++;
                zram_set_flag(zram, index, ZRAM_ZERO);
                ret = 0;
                goto out;
@@ -333,7 +323,7 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,
        }
 
        if (unlikely(clen > max_zpage_size)) {
-               zram_stat_inc(&zram->stats.bad_compress);
+               zram->stats.bad_compress++;
                clen = PAGE_SIZE;
                src = NULL;
                if (is_partial_io(bvec))
@@ -362,9 +352,9 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,
 
        /* Update stats */
        zram_stat64_add(zram, &zram->stats.compr_size, clen);
-       zram_stat_inc(&zram->stats.pages_stored);
+       zram->stats.pages_stored++;
        if (clen <= PAGE_SIZE / 2)
-               zram_stat_inc(&zram->stats.good_compress);
+               zram->stats.good_compress++;
 
 out:
        if (is_partial_io(bvec))
@@ -724,13 +714,7 @@ static int __init zram_init(void)
                goto out;
        }
 
-       if (!num_devices) {
-               pr_info("num_devices not specified. Using default: 1\n");
-               num_devices = 1;
-       }
-
        /* Allocate the device array and initialize each one */
-       pr_info("Creating %u devices ...\n", num_devices);
        zram_devices = kzalloc(num_devices * sizeof(struct zram), GFP_KERNEL);
        if (!zram_devices) {
                ret = -ENOMEM;
@@ -743,6 +727,8 @@ static int __init zram_init(void)
                        goto free_devices;
        }
 
+       pr_info("Created %u device(s) ...\n", num_devices);
+
        return 0;
 
 free_devices: