Quoting Andrew Morton (2014-02-05 13:50:52) > On Tue, 4 Feb 2014 12:43:49 -0800 Sebastian Capella <sebastian.capella@xxxxxxxxxx> wrote: > > > kstrdup_trimnl creates a duplicate of the passed in > > null-terminated string. If a trailing newline is found, it > > is removed before duplicating. This is useful for strings > > coming from sysfs that often include trailing whitespace due to > > user input. > > hm, why? I doubt if any caller of this wants to retain leading and/or > trailing spaces and/or tabs. Hi Andrew, I agree the common case doesn't usually need leading or trailing whitespace. Pavel and others pointed out that a valid filename could contain newlines/whitespace at any position. If we allow for this, then it would be incorrect to strip whitespace from the input. Comments also went down the lines that it would be better for the kernel not to second guess what is being passed in. I find stripping the trailing newline to be very useful, and there are many examples of kernel code doing this. I think it would be a mistake to remove this now, and would be confusing for users. A compromise is to strip the final newline only if it's present before the null. This allows the common case of echoing a simple string onto /sys/power/resume, and behaves as expected in that case. A complex string without a trailing newline is also handled by quoting or dding a file onto /sys/power/resume. In the unlikely event a user has trailing newline as part of the input, then adding an additional newline to the end will cover that case. This is not ideal, but it puts the additional burden onto the complex case rather than the common case. Thanks, Sebastian -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@xxxxxxxxx. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href