Skip to contentSkip to conversation

zram: handle mem suffixes in disk size zram_sysfs parameter

PATCH In review Sergey Senozhatsky 2 participants 5 messages Oct 27, 2012 – Oct 29, 2012 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 2/2 zram: handle mem suffixes in disk size zram_sysfs parameter

zram: handle mem suffixes in disk size zram_sysfs parameter

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

---

 drivers/staging/zram/zram_sysfs.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/staging/zram/zram_sysfs.c +4 -4
index edb0ed4..6be318e 100644
@@ -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 < 1)
+		return -EINVAL;
 
 	down_write(&zram->init_lock);
 	if (zram->init_done) {
#1 lore raw
Quoted 32 lines · Sergey Senozhatsky

zram: handle mem suffixes in disk size zram_sysfs parameter

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

---

  drivers/staging/zram/zram_sysfs.c | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
drivers/staging/zram/zram_sysfs.c +1 -1
index edb0ed4..6be318e 100644
@@ -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;

drivers/staging/zram/zram_sysfs.c static ssize_t disksize_show(struct device *dev, · line 64

Quoted 10 lines
drivers/staging/zram/zram_sysfs.c +3 -3
  	u64 disksize;
  	struct zram *zram = dev_to_zram(dev);
 
-	ret = kstrtoull(buf, 10, &disksize);
-	if (ret)
-		return ret;
+	disksize = memparse(buf, NULL);
+	if (disksize < 1)
+		return -EINVAL;
 

or, just: if (!disksize) ...

Thanks,
Nitin

#2 lore raw
Quoted 12 lines · Nitin Gupta
Quoted 12 lines
drivers/staging/zram/zram_sysfs.c +1 -1
+#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);
 
Quoted 10 lines

drivers/staging/zram/zram_sysfs.c static ssize_t disksize_show(struct device *dev, · line 64

Quoted 7 lines
drivers/staging/zram/zram_sysfs.c +3 -3
-	ret = kstrtoull(buf, 10, &disksize);
-	if (ret)
-		return ret;
+	disksize = memparse(buf, NULL);
+	if (disksize < 1)
+		return -EINVAL;
 

or, just: if (!disksize) ...

will resend shortly.

	-ss
#3 lore raw

PATCH 2/2 zram: handle mem suffixes in disk size zram_sysfs parameter (v2)

In reply to Nitin Gupta

zram: handle mem suffixes in disk size zram_sysfs parameter

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

---

 drivers/staging/zram/zram_sysfs.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/staging/zram/zram_sysfs.c +4 -4
index edb0ed4..de1eacf 100644
@@ -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) {
Reviewed-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] zram: handle mem suffixes in disk size zram_sysfs parameter (v2)

Quoted 10 lines · Sergey Senozhatsky

zram: handle mem suffixes in disk size zram_sysfs parameter

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

FWIW,

Thanks,
Nitin