Messages in this thread | | | Date | Wed, 15 Aug 2018 20:32:26 -0700 | From | Andrew Morton <> | Subject | Re: [PATCH] zram: fix bug storing backing_dev |
| |
On Thu, 16 Aug 2018 10:48:35 +0900 Sergey Senozhatsky <sergey.senozhatsky.work@gmail.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.
| |