The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
To: Andrew Morton <akpm@linux-foundation.org>,
	Minchan Kim <minchan@kernel.org>
Cc: Nitin Gupta <ngupta@vflare.org>,
	linux-kernel@vger.kernel.org,
	Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>,
	Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Subject: [PATCH] zram: cut the trailing new-line in algorithm name
Date: Fri, 22 May 2015 18:34:34 +0900	[thread overview]
Message-ID: <1432287274-7638-1-git-send-email-sergey.senozhatsky@gmail.com> (raw)

supplied sysfs values sometimes contain new-line symbols, which we
also copy as a compression algorithm name. this works fine, because
we use sysfs_streq(), which takes care of new line symbols, when we
lookup for compression algorithm. we print its name if zcomp_create()
has failed, which unfortunately doesn't lok too good

 zram: Cannot initialise LXZ
            compressing backend

cut the trailing new-line symbol, so the reporting line 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>
---
 drivers/block/zram/zcomp.c    |  2 +-
 drivers/block/zram/zram_drv.c | 12 ++++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/drivers/block/zram/zcomp.c b/drivers/block/zram/zcomp.c
index f1ff39a..a1a8b8e 100644
--- a/drivers/block/zram/zcomp.c
+++ b/drivers/block/zram/zcomp.c
@@ -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
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index f401883..26d23b8 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -363,6 +363,13 @@ 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 (len <= 1) {
+		pr_err("Invalid compression backend name\n");
+		return -EINVAL;
+	}
+
 	down_write(&zram->init_lock);
 	if (init_done(zram)) {
 		up_write(&zram->init_lock);
@@ -371,6 +378,11 @@ static ssize_t comp_algorithm_store(struct device *dev,
 	}
 	strlcpy(zram->compressor, buf, sizeof(zram->compressor));
 	up_write(&zram->init_lock);
+
+	/* cut the trailing new-line */
+	sz = strlen(zram->compressor) - 1;
+	if (zram->compressor[sz] == '\n')
+		zram->compressor[sz] = 0x00;
 	return len;
 }
 
-- 
2.4.1.168.g1ea28e1


             reply	other threads:[~2015-05-22  9:34 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-22  9:34 Sergey Senozhatsky [this message]
2015-05-22 13:09 ` [PATCH] zram: cut the trailing new-line in algorithm name Sergey Senozhatsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1432287274-7638-1-git-send-email-sergey.senozhatsky@gmail.com \
    --to=sergey.senozhatsky.work@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=minchan@kernel.org \
    --cc=ngupta@vflare.org \
    --cc=sergey.senozhatsky@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox