aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/block
diff options
context:
space:
mode:
authorSergey Senozhatsky <sergey.senozhatsky@gmail.com>2015-06-25 18:00:32 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2015-06-25 20:00:37 -0400
commitd93435c3fba4a47b773693b0c8992470d38510d5 (patch)
tree0eee23d9451b404c4f2aa9ad7e6a6fe970806cae /drivers/block
parent4bbacd51a683e45c13f7d6df6f85cb7391590311 (diff)
zram: check comp algorithm availability earlier
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 emits the following error: "zram: Cannot initialise %s compressing backend" this error line is somewhat generic and, besides, can indicate a failed attempt to allocate compression backend's working buffers. add algorithm availability check to comp_algorithm_store(): echo lzz > /sys/block/zram0/comp_algorithm -bash: echo: write error: Invalid argument Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com> Reported-by: Marcin Jabrzyk <m.jabrzyk@samsung.com> Acked-by: Minchan Kim <minchan@kernel.org> Cc: Nitin Gupta <ngupta@vflare.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/block')
-rw-r--r--drivers/block/zram/zcomp.c5
-rw-r--r--drivers/block/zram/zcomp.h1
-rw-r--r--drivers/block/zram/zram_drv.c3
3 files changed, 9 insertions, 0 deletions
diff --git a/drivers/block/zram/zcomp.c b/drivers/block/zram/zcomp.c
index a1a8b8ee9fda..965d1afb0eaa 100644
--- a/drivers/block/zram/zcomp.c
+++ b/drivers/block/zram/zcomp.c
@@ -286,6 +286,11 @@ ssize_t zcomp_available_show(const char *comp, char *buf)
286 return sz; 286 return sz;
287} 287}
288 288
289bool zcomp_available_algorithm(const char *comp)
290{
291 return find_backend(comp) != NULL;
292}
293
289bool zcomp_set_max_streams(struct zcomp *comp, int num_strm) 294bool zcomp_set_max_streams(struct zcomp *comp, int num_strm)
290{ 295{
291 return comp->set_max_streams(comp, num_strm); 296 return comp->set_max_streams(comp, num_strm);
diff --git a/drivers/block/zram/zcomp.h b/drivers/block/zram/zcomp.h
index c59d1fca72c0..46e2b9f8f1f0 100644
--- a/drivers/block/zram/zcomp.h
+++ b/drivers/block/zram/zcomp.h
@@ -51,6 +51,7 @@ struct zcomp {
51}; 51};
52 52
53ssize_t zcomp_available_show(const char *comp, char *buf); 53ssize_t zcomp_available_show(const char *comp, char *buf);
54bool zcomp_available_algorithm(const char *comp);
54 55
55struct zcomp *zcomp_create(const char *comp, int max_strm); 56struct zcomp *zcomp_create(const char *comp, int max_strm);
56void zcomp_destroy(struct zcomp *comp); 57void zcomp_destroy(struct zcomp *comp);
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index d94696b28a85..fb655e8d1e3b 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -378,6 +378,9 @@ static ssize_t comp_algorithm_store(struct device *dev,
378 if (sz > 0 && zram->compressor[sz - 1] == '\n') 378 if (sz > 0 && zram->compressor[sz - 1] == '\n')
379 zram->compressor[sz - 1] = 0x00; 379 zram->compressor[sz - 1] = 0x00;
380 380
381 if (!zcomp_available_algorithm(zram->compressor))
382 len = -EINVAL;
383
381 up_write(&zram->init_lock); 384 up_write(&zram->init_lock);
382 return len; 385 return len;
383} 386}