Re: [PATCH] zram: fix bug storing backing_dev
From: Andrew Morton
Date: Wed Aug 15 2018 - 23:32:44 EST
On Thu, 16 Aug 2018 10:48:35 +0900 Sergey Senozhatsky <sergey.senozhatsky.work@xxxxxxxxx> 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.