staging: zram: handle mem suffixes in disk size zram_sysfs parameter
authorSergey Senozhatsky <sergey.senozhatsky@gmail.com>
Tue, 30 Oct 2012 19:42:31 +0000 (22:42 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 31 Oct 2012 21:49:09 +0000 (14:49 -0700)
Use memparse() to allow mem suffixes in disksize sysfs number.
Examples:
    echo 256K > /sys/block/zram0/disksize
    echo 512M > /sys/block/zram0/disksize
    echo 1G > /sys/block/zram0/disksize

Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Reviewed-by: Nitin Gupta <ngupta@vflare.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/zram/zram_sysfs.c

index edb0ed4125d5b2c9a08058d2d01f5db507a4d1ee..de1eacf65dbdc167bf4707cdcf6a9eb7bfa0fbf7 100644 (file)
@@ -15,6 +15,7 @@
 #include <linux/device.h>
 #include <linux/genhd.h>
 #include <linux/mm.h>
+#include <linux/kernel.h>
 
 #include "zram_drv.h"
 
@@ -54,13 +55,12 @@ static ssize_t disksize_show(struct device *dev,
 static ssize_t disksize_store(struct device *dev,
                struct device_attribute *attr, const char *buf, size_t len)
 {
-       int ret;
        u64 disksize;
        struct zram *zram = dev_to_zram(dev);
 
-       ret = kstrtoull(buf, 10, &disksize);
-       if (ret)
-               return ret;
+       disksize = memparse(buf, NULL);
+       if (!disksize)
+               return -EINVAL;
 
        down_write(&zram->init_lock);
        if (zram->init_done) {