Skip to content

Commit

Permalink
mm/thp: use conventional format for boolean attributes
Browse files Browse the repository at this point in the history
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.

[[email protected]: use kstrtoul()]
[[email protected]: test_bit() doesn't return 1/0, per Neil]
Signed-off-by: Ben Hutchings <[email protected]>
Cc: Andrea Arcangeli <[email protected]>
Cc: Mel Gorman <[email protected]>
Cc: Johannes Weiner <[email protected]>
Cc: Rik van Riel <[email protected]>
Cc: Hugh Dickins <[email protected]>
Tested-by: David Rientjes <[email protected]>
Cc: NeilBrown <[email protected]>
Cc: <[email protected]> 	[2.6.38.x]
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
bwhacks authored and torvalds committed Apr 14, 2011
1 parent b836aec commit e27e615
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions mm/huge_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,24 +244,28 @@ static ssize_t single_flag_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buf,
enum transparent_hugepage_flag flag)
{
if (test_bit(flag, &transparent_hugepage_flags))
return sprintf(buf, "[yes] no\n");
else
return sprintf(buf, "yes [no]\n");
return sprintf(buf, "%d\n",
!!test_bit(flag, &transparent_hugepage_flags));
}

static ssize_t single_flag_store(struct kobject *kobj,
struct kobj_attribute *attr,
const char *buf, size_t count,
enum transparent_hugepage_flag flag)
{
if (!memcmp("yes", buf,
min(sizeof("yes")-1, count))) {
unsigned long value;
int ret;

ret = kstrtoul(buf, 10, &value);
if (ret < 0)
return ret;
if (value > 1)
return -EINVAL;

if (value)
set_bit(flag, &transparent_hugepage_flags);
} else if (!memcmp("no", buf,
min(sizeof("no")-1, count))) {
else
clear_bit(flag, &transparent_hugepage_flags);
} else
return -EINVAL;

return count;
}
Expand Down

0 comments on commit e27e615

Please sign in to comment.