Commit 4bbacd51 authored by Sergey Senozhatsky's avatar Sergey Senozhatsky Committed by Linus Torvalds

zram: cut trailing newline in algorithm name

Supplied sysfs values sometimes contain new-line symbols (echo vs.  echo
-n), which we also copy as a compression algorithm name.  it works fine
when we lookup for compression algorithm, because we use sysfs_streq()
which takes care of new line symbols.  however, it doesn't look nice when
we print compression algorithm name if zcomp_create() failed:

 zram: Cannot initialise LXZ
            compressing backend

cut trailing new-line, so the error string will look like

  zram: Cannot initialise LXZ compressing backend

we also now can replace sysfs_streq() in zcomp_available_show() with
Signed-off-by: default avatarSergey Senozhatsky <>
Cc: Minchan Kim <>
Cc: Nitin Gupta <>
Signed-off-by: default avatarAndrew Morton <>
Signed-off-by: default avatarLinus Torvalds <>
parent 17162f41
......@@ -274,7 +274,7 @@ ssize_t zcomp_available_show(const char *comp, char *buf)
int i = 0;
while (backends[i]) {
if (sysfs_streq(comp, backends[i]->name))
if (!strcmp(comp, backends[i]->name))
sz += scnprintf(buf + sz, PAGE_SIZE - sz - 2,
"[%s] ", backends[i]->name);
......@@ -363,6 +363,8 @@ static ssize_t comp_algorithm_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t len)
struct zram *zram = dev_to_zram(dev);
size_t sz;
if (init_done(zram)) {
......@@ -370,6 +372,12 @@ static ssize_t comp_algorithm_store(struct device *dev,
return -EBUSY;
strlcpy(zram->compressor, buf, sizeof(zram->compressor));
/* ignore trailing newline */
sz = strlen(zram->compressor);
if (sz > 0 && zram->compressor[sz - 1] == '\n')
zram->compressor[sz - 1] = 0x00;
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