linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Marcin Jabrzyk <m.jabrzyk@samsung.com>
To: minchan@kernel.org, ngupta@vflare.org,
	sergey.senozhatsky.work@gmail.com, linux-kernel@vger.kernel.org,
	linux-mm@kvack.org
Cc: kyungmin.park@samsung.com, Marcin Jabrzyk <m.jabrzyk@samsung.com>
Subject: [PATCH] zram: check compressor name before setting it
Date: Fri, 22 May 2015 10:31:55 +0200	[thread overview]
Message-ID: <1432283515-2005-1-git-send-email-m.jabrzyk@samsung.com> (raw)

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>

             reply	other threads:[~2015-05-22  8:32 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-22  8:31 Marcin Jabrzyk [this message]
2015-05-22  8:56 ` [PATCH] zram: check compressor name before setting it 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1432283515-2005-1-git-send-email-m.jabrzyk@samsung.com \
    --to=m.jabrzyk@samsung.com \
    --cc=kyungmin.park@samsung.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=minchan@kernel.org \
    --cc=ngupta@vflare.org \
    --cc=sergey.senozhatsky.work@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).