Re: [PATCH v3 1/2] init/do_mounts.c: ignore final \n in name_to_dev_t
From: Andrew Morton <akpm@linux-foundation.org>
Date: 2014-01-29 18:41:11
Also in:
linux-arm-kernel, lkml
From: Andrew Morton <akpm@linux-foundation.org>
Date: 2014-01-29 18:41:11
Also in:
linux-arm-kernel, lkml
On Wed, 29 Jan 2014 10:29:56 -0800 Sebastian Capella [off-list ref] wrote:
Hi Andrew, By the way, I do see a call (sysfs_streq) in use for this purpose other places. Sorry, I didn't find it while looking at the original problem. I'm not sure if this is preferable, but it appears to have been added specifically for the strings coming through sysfs.
Yes, I wrote it ;) I didn't think sysfs_streq() is well suited to this problem. And the issue of possibly-null-terminated-strings coming in from userspace is a common one, so it is desirable that we build up the suite of utilities to handle this. There are probably quite a lot of open-coded \n trimming loops which can be cleaned up using such tools. grep -r "if .* == '\\\n'" .
My preference is copying the string and cleaning it up before passing it to internal functions, even though we incur an allocation.
Yes. Here on the kernel/userspace boundary we are typically running in GFP_KERNEL context and the code is not performance critical - it is a good fit.