From: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
To: Andrew Morton <akpm@linux-foundation.org>,
Minchan Kim <minchan@kernel.org>
Cc: Marcin Jabrzyk <m.jabrzyk@samsung.com>,
Nitin Gupta <ngupta@vflare.org>,
linux-kernel@vger.kernel.org,
Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>,
Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Subject: [PATCH] zram: check comp algorithm availability earlier
Date: Tue, 26 May 2015 22:13:37 +0900 [thread overview]
Message-ID: <1432646017-1367-1-git-send-email-sergey.senozhatsky@gmail.com> (raw)
Improvement idea by Marcin Jabrzyk.
comp_algorithm_store() silently accepts any supplied algorithm
name, because zram performs algorithm availability check later,
during the device configuration phase in disksize_store() and
prints
"zram: Cannot initialise %s compressing backend"
to syslog. this error line is somewhat generic and, besides,
can indicate a failed attempt to allocate compression backend's
working buffers.
make algorithm availability check earlier, in comp_algorithm_store(),
and be move verbose:
echo lzz > /sys/block/zram0/comp_algorithm
-bash: echo: write error: Invalid argument
dmesg:
zram: Error: unavailable compression algorithm: lzz
Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Reported-by: Marcin Jabrzyk <m.jabrzyk@samsung.com>
---
drivers/block/zram/zcomp.c | 5 +++++
drivers/block/zram/zcomp.h | 1 +
drivers/block/zram/zram_drv.c | 6 ++++++
3 files changed, 12 insertions(+)
diff --git a/drivers/block/zram/zcomp.c b/drivers/block/zram/zcomp.c
index a1a8b8e..e10e2b4 100644
--- a/drivers/block/zram/zcomp.c
+++ b/drivers/block/zram/zcomp.c
@@ -320,6 +320,11 @@ void zcomp_destroy(struct zcomp *comp)
kfree(comp);
}
+bool zcomp_available_algorithm(const char *comp)
+{
+ return find_backend(comp) != NULL;
+}
+
/*
* search available compressors for requested algorithm.
* allocate new zcomp and initialize it. return compressing
diff --git a/drivers/block/zram/zcomp.h b/drivers/block/zram/zcomp.h
index c59d1fc..46e2b9f 100644
--- a/drivers/block/zram/zcomp.h
+++ b/drivers/block/zram/zcomp.h
@@ -51,6 +51,7 @@ struct zcomp {
};
ssize_t zcomp_available_show(const char *comp, char *buf);
+bool zcomp_available_algorithm(const char *comp);
struct zcomp *zcomp_create(const char *comp, int max_strm);
void zcomp_destroy(struct zcomp *comp);
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 28f6e46..e17b73e 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -378,6 +378,12 @@ static ssize_t comp_algorithm_store(struct device *dev,
if (sz > 0 && zram->compressor[sz - 1] == '\n')
zram->compressor[sz - 1] = 0x00;
+ if (!zcomp_available_algorithm(zram->compressor)) {
+ pr_err("Error: unavailable compression algorithm: %s\n",
+ zram->compressor);
+ len = -EINVAL;
+ }
+
up_write(&zram->init_lock);
return len;
}
--
2.4.1.314.g9532ead
next reply other threads:[~2015-05-26 13:15 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-26 13:13 Sergey Senozhatsky [this message]
2015-05-27 3:51 ` Minchan Kim
2015-05-27 5:53 ` Sergey Senozhatsky
2015-05-27 5:58 ` Minchan Kim
2015-05-27 6:12 ` 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=1432646017-1367-1-git-send-email-sergey.senozhatsky@gmail.com \
--to=sergey.senozhatsky@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=m.jabrzyk@samsung.com \
--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
all inboxes | Powered by JetHome®