linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] zram: check compressor name before setting it
@ 2015-05-22  8:31 Marcin Jabrzyk
  2015-05-22  8:56 ` Sergey Senozhatsky
  0 siblings, 1 reply; 16+ messages in thread
From: Marcin Jabrzyk @ 2015-05-22  8:31 UTC (permalink / raw)
  To: minchan, ngupta, sergey.senozhatsky.work, linux-kernel, linux-mm
  Cc: kyungmin.park, Marcin Jabrzyk

Zram sysfs interface was not making any check of
proper compressor name when setting it.
Any name is accepted, but further tries of device
creation would end up with not very meaningfull error.
eg.

echo lz0 > comp_algorithm
echo 200M > disksize
echo: write error: Invalid argument

This commit fixes that behaviour with returning
EINVAL and proper error message.

Signed-off-by: Marcin Jabrzyk <m.jabrzyk@samsung.com>
---
 drivers/block/zram/zcomp.c    | 22 +++++++++++-----------
 drivers/block/zram/zcomp.h    |  1 +
 drivers/block/zram/zram_drv.c |  5 +++++
 3 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/drivers/block/zram/zcomp.c b/drivers/block/zram/zcomp.c
index f1ff39a3d1c1..f81a2b5fef43 100644
--- a/drivers/block/zram/zcomp.c
+++ b/drivers/block/zram/zcomp.c
@@ -51,17 +51,6 @@ static struct zcomp_backend *backends[] = {
 	NULL
 };
 
-static struct zcomp_backend *find_backend(const char *compress)
-{
-	int i = 0;
-	while (backends[i]) {
-		if (sysfs_streq(compress, backends[i]->name))
-			break;
-		i++;
-	}
-	return backends[i];
-}
-
 static void zcomp_strm_free(struct zcomp *comp, struct zcomp_strm *zstrm)
 {
 	if (zstrm->private)
@@ -267,6 +256,17 @@ static int zcomp_strm_single_create(struct zcomp *comp)
 	return 0;
 }
 
+struct zcomp_backend *find_backend(const char *compress)
+{
+	int i = 0;
+	while (backends[i]) {
+		if (sysfs_streq(compress, backends[i]->name))
+			break;
+		i++;
+	}
+	return backends[i];
+}
+
 /* show available compressors */
 ssize_t zcomp_available_show(const char *comp, char *buf)
 {
diff --git a/drivers/block/zram/zcomp.h b/drivers/block/zram/zcomp.h
index c59d1fca72c0..a531350858d0 100644
--- a/drivers/block/zram/zcomp.h
+++ b/drivers/block/zram/zcomp.h
@@ -50,6 +50,7 @@ struct zcomp {
 	void (*destroy)(struct zcomp *comp);
 };
 
+struct zcomp_backend *find_backend(const char *compress);
 ssize_t zcomp_available_show(const char *comp, char *buf);
 
 struct zcomp *zcomp_create(const char *comp, int max_strm);
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 01ec6945c2a9..ef4acd6e52d1 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -268,6 +268,11 @@ static ssize_t comp_algorithm_store(struct device *dev,
 {
 	struct zram *zram = dev_to_zram(dev);
 	down_write(&zram->init_lock);
+	if (!find_backend(buf)) {
+		up_write(&zram->init_lock);
+		pr_info("There is no such compression algorithm\n");
+		return -EINVAL;
+	}
 	if (init_done(zram)) {
 		up_write(&zram->init_lock);
 		pr_info("Can't change algorithm for initialized device\n");
-- 
1.9.1

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2015-05-26  0:09 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-22  8:31 [PATCH] zram: check compressor name before setting it Marcin Jabrzyk
2015-05-22  8:56 ` Sergey Senozhatsky
2015-05-22  9:12   ` Marcin Jabrzyk
2015-05-22 12:44     ` Sergey Senozhatsky
2015-05-22 13:14       ` Minchan Kim
2015-05-22 13:34         ` Marcin Jabrzyk
2015-05-25  4:03         ` Sergey Senozhatsky
2015-05-25 14:16           ` Minchan Kim
2015-05-22 13:26       ` Marcin Jabrzyk
2015-05-25  6:18         ` Sergey Senozhatsky
2015-05-25  6:23           ` Sergey Senozhatsky
2015-05-25  7:15           ` Marcin Jabrzyk
2015-05-25  7:34             ` Sergey Senozhatsky
2015-05-25  8:05               ` Marcin Jabrzyk
2015-05-25 14:21           ` Minchan Kim
2015-05-26  0:09             ` Sergey Senozhatsky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).