Commit d93435c3 authored by Sergey Senozhatsky's avatar Sergey Senozhatsky Committed by Linus Torvalds

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: default avatarSergey Senozhatsky <sergey.senozhatsky@gmail.com>
Reported-by: default avatarMarcin Jabrzyk <m.jabrzyk@samsung.com>
Acked-by: default avatarMinchan Kim <minchan@kernel.org>
Cc: Nitin Gupta <ngupta@vflare.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 4bbacd51
...@@ -286,6 +286,11 @@ ssize_t zcomp_available_show(const char *comp, char *buf) ...@@ -286,6 +286,11 @@ ssize_t zcomp_available_show(const char *comp, char *buf)
return sz; return sz;
} }
bool zcomp_available_algorithm(const char *comp)
{
return find_backend(comp) != NULL;
}
bool zcomp_set_max_streams(struct zcomp *comp, int num_strm) bool zcomp_set_max_streams(struct zcomp *comp, int num_strm)
{ {
return comp->set_max_streams(comp, num_strm); return comp->set_max_streams(comp, num_strm);
......
...@@ -51,6 +51,7 @@ struct zcomp { ...@@ -51,6 +51,7 @@ struct zcomp {
}; };
ssize_t zcomp_available_show(const char *comp, char *buf); 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); struct zcomp *zcomp_create(const char *comp, int max_strm);
void zcomp_destroy(struct zcomp *comp); void zcomp_destroy(struct zcomp *comp);
......
...@@ -378,6 +378,9 @@ static ssize_t comp_algorithm_store(struct device *dev, ...@@ -378,6 +378,9 @@ static ssize_t comp_algorithm_store(struct device *dev,
if (sz > 0 && zram->compressor[sz - 1] == '\n') if (sz > 0 && zram->compressor[sz - 1] == '\n')
zram->compressor[sz - 1] = 0x00; zram->compressor[sz - 1] = 0x00;
if (!zcomp_available_algorithm(zram->compressor))
len = -EINVAL;
up_write(&zram->init_lock); up_write(&zram->init_lock);
return len; return len;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment