mm/thp: use conventional format for boolean attributes

The conventional format for boolean attributes in sysfs is numeric ("0" or
"1" followed by new-line).  Any boolean attribute can then be read and
written using a generic function.  Using the strings "yes [no]", "[yes]
no" (read), "yes" and "no" (write) will frustrate this.

[akpm@linux-foundation.org: use kstrtoul()]
[akpm@linux-foundation.org: test_bit() doesn't return 1/0, per Neil]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Mel Gorman <mel@csn.ul.ie>
Cc: Johannes Weiner <jweiner@redhat.com>
Cc: Rik van Riel <riel@redhat.com>
Cc: Hugh Dickins <hughd@google.com>
Tested-by: David Rientjes <rientjes@google.com>
Cc: NeilBrown <neilb@suse.de>
Cc: <stable@kernel.org> 	[2.6.38.x]
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Ben Hutchings 2011-04-14 15:22:21 -07:00 committed by Linus Torvalds
parent b836aec53e
commit e27e6151b1

View File

@ -244,25 +244,29 @@ static ssize_t single_flag_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buf, struct kobj_attribute *attr, char *buf,
enum transparent_hugepage_flag flag) enum transparent_hugepage_flag flag)
{ {
if (test_bit(flag, &transparent_hugepage_flags)) return sprintf(buf, "%d\n",
return sprintf(buf, "[yes] no\n"); !!test_bit(flag, &transparent_hugepage_flags));
else
return sprintf(buf, "yes [no]\n");
} }
static ssize_t single_flag_store(struct kobject *kobj, static ssize_t single_flag_store(struct kobject *kobj,
struct kobj_attribute *attr, struct kobj_attribute *attr,
const char *buf, size_t count, const char *buf, size_t count,
enum transparent_hugepage_flag flag) enum transparent_hugepage_flag flag)
{ {
if (!memcmp("yes", buf, unsigned long value;
min(sizeof("yes")-1, count))) { int ret;
set_bit(flag, &transparent_hugepage_flags);
} else if (!memcmp("no", buf, ret = kstrtoul(buf, 10, &value);
min(sizeof("no")-1, count))) { if (ret < 0)
clear_bit(flag, &transparent_hugepage_flags); return ret;
} else if (value > 1)
return -EINVAL; return -EINVAL;
if (value)
set_bit(flag, &transparent_hugepage_flags);
else
clear_bit(flag, &transparent_hugepage_flags);
return count; return count;
} }