linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Joey Pabalinas <joeypabalinas@gmail.com>
To: Minchan Kim <minchan@kernel.org>
Cc: Joey Pabalinas <joeypabalinas@gmail.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
Subject: Re: [PATCH v2 5/7] zram: support idle/huge page writeback
Date: Mon, 26 Nov 2018 16:53:32 -1000	[thread overview]
Message-ID: <20181127025332.23wlp4zai6e7mrip@gmail.com> (raw)
In-Reply-To: <20181127021327.GD237537@google.com>

[-- Attachment #1: Type: text/plain, Size: 2000 bytes --]

On Tue, Nov 27, 2018 at 11:13:27AM +0900, Minchan Kim wrote:
> On Sun, Nov 25, 2018 at 11:47:37PM -1000, Joey Pabalinas wrote:
> > On Mon, Nov 26, 2018 at 05:28:11PM +0900, Minchan Kim wrote:
> > > +	strlcpy(mode_buf, buf, sizeof(mode_buf));
> > > +	/* ignore trailing newline */
> > > +	sz = strlen(mode_buf);
> > 
> > One possible idea would be to use strscpy() instead and directly assign
> > the return value to sz, avoiding an extra strlen() call (though you would
> > have to check if `sz == -E2BIG` and do `sz = sizeof(mode_buf) - 1` in that
> > case).
> 
> Thanks for the suggstion.
> If I limit destination buffer smaller, I couldn't meet -E2BIG?

-E2BIG return from strscpy() just means the string was longer than would
fit in the length passed as the third argument. This means only
`sizeof(mode_buf) - 1` bytes were copied into the dest, with the last
byte being the \0 terminator.

You can find the function source in lib/string.c.

> > > +	ret = len;
> > > +	 __free_page(page);
> > > +release_init_lock:
> > > +	up_read(&zram->init_lock);
> > > +	return ret;
> > 
> > Hm, I noticed that this function either returns an error or just the passed
> > in len on success, and I'm left wondering if there might be other useful
> > information which could be passed back to the caller instead. I can't
> > immediately think of any such information, though, so it's possible I'm
> > just daydreaming :)
> 
> It is write syscall semantic of sysfs so not sure it's doable to pass
> other value to user.

Well, with the write system call you can have partial writes, in which
case it would return the (short) number of bytes written. But in this
function, even if there was some sort of partial write possible, this
function still only every returns len or error.

Neither of these are that important though, so Ack from me with or
without these two suggestions.

Reviewed-by: Joey Pabalinas <joeypabalinas@gmail.com>

-- 
Cheers,
Joey Pabalinas

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2018-11-27  2:53 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-26  8:28 [PATCH v2 0/7] zram idle page writeback Minchan Kim
2018-11-26  8:28 ` [PATCH v2 1/7] zram: fix lockdep warning of free block handling Minchan Kim
2018-11-26 20:49   ` Andrew Morton
2018-11-27  2:05     ` Minchan Kim
2018-11-26  8:28 ` [PATCH v2 2/7] zram: fix double free backing device Minchan Kim
2018-11-26  8:28 ` [PATCH v2 3/7] zram: refactoring flags and writeback stuff Minchan Kim
2018-11-26  8:28 ` [PATCH v2 4/7] zram: introduce ZRAM_IDLE flag Minchan Kim
2018-11-26  8:28 ` [PATCH v2 5/7] zram: support idle/huge page writeback Minchan Kim
2018-11-26  9:47   ` Joey Pabalinas
2018-11-26 13:44     ` Joey Pabalinas
2018-11-27  2:13     ` Minchan Kim
2018-11-27  2:53       ` Joey Pabalinas [this message]
2018-11-26  8:28 ` [PATCH v2 6/7] zram: add bd_stat statistics Minchan Kim
2018-11-26 20:58   ` Andrew Morton
2018-11-27  2:07     ` Minchan Kim
2018-11-28 23:30       ` Andrew Morton
2018-11-29  1:45         ` Minchan Kim
2018-11-26  8:28 ` [PATCH v2 7/7] zram: writeback throttle Minchan Kim
2018-11-26 20:54   ` Andrew Morton
2018-11-27  2:08     ` Minchan Kim

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=20181127025332.23wlp4zai6e7mrip@gmail.com \
    --to=joeypabalinas@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=minchan@kernel.org \
    --cc=sergey.senozhatsky.work@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;
as well as URLs for NNTP newsgroup(s).