lkml.org 
[lkml]   [2018]   [Aug]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [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.


\
 
 \ /
  Last update: 2018-08-16 05:33    [W:0.054 / U:0.384 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site