[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <20180815203226.2c7e48b2f9395d2772ecfcb2@linux-foundation.org>
Date: Wed, 15 Aug 2018 20:32:26 -0700
From: Andrew Morton <akpm@...ux-foundation.org>
To: Sergey Senozhatsky <sergey.senozhatsky.work@...il.com>
Cc: Minchan Kim <minchan@...nel.org>,
Peter Kalauskas <peskal@...gle.com>,
LKML <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] zram: fix bug storing backing_dev
On Thu, 16 Aug 2018 10:48:35 +0900 Sergey Senozhatsky <sergey.senozhatsky.work@...il.com> wrote:
> > The implementation might be able to use strim() somehow.
>
> strim() trims white-spaces.
Which includes \n.
> What we have here is a trailing new line symbol,
> which echo appends to the string it writes to the kernel [echo -n switch
> disables it]. So we receive a "/dev/name\n" device name from sysfs, which we
> unsuccessfully try to open(). To make it all work we need to remove that
> trailing new line.
>
> A side note,
> There is sysfs_strcmp(), which takes care of that "user space may append
> a new line to the string" case, I wonder if we should finally have
> sysfs_strcpy(), which would not copy the trailing new line. I think this
> "if string[sz - 1] == '\n' then string[sz - 1] == 0x00" is quite common.
Sure, some additional well-chosen helpers here would be good. There's
a LOT of code which does basically-the-same-thing with sysfs input.
And a lot of it misses things, such as leading whitespace. Passing all
this through helpers would provide consistency as well as code-size
reductions, improved reviewability, etc.
Powered by blists - more mailing lists