mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Minchan Kim <minchan@kernel.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: joaodias@google.com, LKML <linux-kernel@vger.kernel.org>,
	Amos Bianchi <amosbianchi@google.com>,
	Colin Ian King <colin.king@canonical.com>,
	Minchan Kim <minchan@kernel.org>,
	Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
	stable@vger.kernel.org
Subject: [PATCH 2/2] zram: fix broken page writeback
Date: Fri, 12 Mar 2021 09:39:49 -0800	[thread overview]
Message-ID: <20210312173949.2197662-2-minchan@kernel.org> (raw)
In-Reply-To: <20210312173949.2197662-1-minchan@kernel.org>

commit 0d8359620d9b ("zram: support page writeback") introduced
two problems. It overwrites writeback_store's return value as
kstrtol's return value, which makes return value zero so user
could see zero as return value of write syscall even though it
wrote data successfully.

It also breaks index value in the loop in that it doesn't
increase the index any longer. It means it can write only
first starting block index so user couldn't write all idle
pages in the zram so lose memory saving chance.

This patch fixes those issues.

Cc: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Cc: stable@vger.kernel.org
Reported-by: Amos Bianchi <amosbianchi@google.com>
Fixes: 0d8359620d9b("zram: support page writeback")
Signed-off-by: Minchan Kim <minchan@kernel.org>
---
 drivers/block/zram/zram_drv.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 63bbefdffc81..cf8deecc39ef 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -638,8 +638,8 @@ static ssize_t writeback_store(struct device *dev,
 		if (strncmp(buf, PAGE_WB_SIG, sizeof(PAGE_WB_SIG) - 1))
 			return -EINVAL;
 
-		ret = kstrtol(buf + sizeof(PAGE_WB_SIG) - 1, 10, &index);
-		if (ret || index >= nr_pages)
+		if (kstrtol(buf + sizeof(PAGE_WB_SIG) - 1, 10, &index) ||
+				index >= nr_pages)
 			return -EINVAL;
 
 		nr_pages = 1;
@@ -663,7 +663,7 @@ static ssize_t writeback_store(struct device *dev,
 		goto release_init_lock;
 	}
 
-	while (nr_pages--) {
+	for (; nr_pages != 0; index++, nr_pages--) {
 		struct bio_vec bvec;
 
 		bvec.bv_page = page;
-- 
2.31.0.rc2.261.g7f71774620-goog


      reply	other threads:[~2021-03-12 17:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-12 17:39 [PATCH 1/2] zram: fix return value on writeback_store Minchan Kim
2021-03-12 17:39 ` Minchan Kim [this message]

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=20210312173949.2197662-2-minchan@kernel.org \
    --to=minchan@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=amosbianchi@google.com \
    --cc=colin.king@canonical.com \
    --cc=joaodias@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sergey.senozhatsky@gmail.com \
    --cc=stable@vger.kernel.org \
    /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

Powered by JetHome