zram: cut trailing newline in algorithm name
authorSergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
Thu, 25 Jun 2015 22:00:29 +0000 (15:00 -0700)
committerDanny Wood <danwood76@gmail.com>
Tue, 14 Sep 2021 19:02:17 +0000 (20:02 +0100)
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().

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>
Change-Id: If00faf29cca63fc20c8caea57ababe97a16c4a7a

drivers/block/zram/zcomp.c
drivers/block/zram/zram_drv.c

index 6fbb10ca73b10eb34466fc5441fc30809bf9df4d..b299ac8ee85cd6b8f5999e795488dfe1ec2f6ac2 100644 (file)
@@ -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);
                else
index a61a749828dc8d39f3bef00364e53c0daa1df37b..87df9f3bcec8310e32d6ecd2f7e8b58259936719 100644 (file)
@@ -271,6 +271,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;
+
        down_write(&zram->init_lock);
        if (init_done(zram)) {
                up_write(&zram->init_lock);
@@ -278,6 +280,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;
+
        up_write(&zram->init_lock);
        return len;
 }