Re: [patch] mm, thp: fix defrag setting if newline is not used

From: Andrew Morton
Date: Thu Jan 16 2020 - 22:23:06 EST


On Tue, 14 Jan 2020 17:58:36 -0800 (PST) David Rientjes <rientjes@xxxxxxxxxx> wrote:

> If thp defrag setting "defer" is used and a newline is *not* used when
> writing to the sysfs file, this is interpreted as the "defer+madvise"
> option.
>
> This is because we do prefix matching and if five characters are written
> without a newline, the current code ends up comparing to the first five
> bytes of the "defer+madvise" option and using that instead.
>
> Find the length of what the user is writing and use that to guide our
> decision on which string comparison to do.

Gee, why is this code so complicated? Can't we just do

if (sysfs_streq(buf, "always")) {
...
} else if sysfs_streq(buf, "defer+madvise")) {
...
}
...