Skip to content

Commit

Permalink
zram: cut trailing newline in algorithm name
Browse files Browse the repository at this point in the history
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
strcmp().

Change-Id: If20e9c6253a9d810e0a15c3df78284145c05c424
Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Cc: 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>
  • Loading branch information
sergey-senozhatsky authored and alexax66 committed Aug 15, 2020
1 parent e64a101 commit 5800ae4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion drivers/block/zram/zcomp.c
Expand Up @@ -282,7 +282,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);
else
Expand Down
8 changes: 8 additions & 0 deletions drivers/block/zram/zram_drv.c
Expand Up @@ -271,13 +271,21 @@ 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;

down_write(&zram->init_lock);
if (init_done(zram)) {
up_write(&zram->init_lock);
pr_info("Can't change algorithm for initialized device\n");
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;

up_write(&zram->init_lock);
return len;
}
Expand Down

0 comments on commit 5800ae4

Please sign in to comment.