summaryrefslogtreecommitdiffstats
path: root/drivers/base
diff options
context:
space:
mode:
authorTang Chen <tangchen@cn.fujitsu.com>2014-08-06 16:05:11 -0700
committerLinus Torvalds <torvalds@linux-foundation.org>2014-08-06 18:01:16 -0700
commit1f6a6cc82ed305c09385753c80bb7b3bc9eea864 (patch)
treecf9341c6ec5c49b05b89b170b862f96eead028b0 /drivers/base
parentc0d73261f5c1355a35b8b40e871d31578ce0c044 (diff)
downloadlinux-stable-1f6a6cc82ed305c09385753c80bb7b3bc9eea864.tar.gz
linux-stable-1f6a6cc82ed305c09385753c80bb7b3bc9eea864.tar.bz2
linux-stable-1f6a6cc82ed305c09385753c80bb7b3bc9eea864.zip
mem-hotplug: avoid illegal state prefixed with legal state when changing state of memory_block
We use the following command to online a memory_block: echo online|online_kernel|online_movable > /sys/devices/system/memory/memoryXXX/state But, if we do the following: echo online_fhsjkghfkd > /sys/devices/system/memory/memoryXXX/state the block will also be onlined. This is because the following code in store_mem_state() does not compare the whole string, but only the prefix of the string. store_mem_state() { ...... 328 if (!strncmp(buf, "online_kernel", min_t(int, count, 13))) Here, only compare the first 13 letters of the string. If we give "online_kernelXXXXXX", it will be recognized as online_kernel, which is incorrect. 329 online_type = ONLINE_KERNEL; 330 else if (!strncmp(buf, "online_movable", min_t(int, count, 14))) We have the same problem here, 331 online_type = ONLINE_MOVABLE; 332 else if (!strncmp(buf, "online", min_t(int, count, 6))) here, (Here is more problematic. If we give online_movalbe, which is a typo of online_movable, it will be recognized as online without noticing the author.) 333 online_type = ONLINE_KEEP; 334 else if (!strncmp(buf, "offline", min_t(int, count, 7))) and here. 335 online_type = -1; 336 else { 337 ret = -EINVAL; 338 goto err; 339 } ...... } This patch fixes this problem by using sysfs_streq() to compare the whole string. Signed-off-by: Tang Chen <tangchen@cn.fujitsu.com> Reported-by: Hu Tao <hutao@cn.fujitsu.com> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Lai Jiangshan <laijs@cn.fujitsu.com> Cc: Yasuaki Ishimatsu <isimatu.yasuaki@jp.fujitsu.com> Cc: Gu Zheng <guz.fnst@cn.fujitsu.com> Acked-by: Toshi Kani <toshi.kani@hp.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/base')
-rw-r--r--drivers/base/memory.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/drivers/base/memory.c b/drivers/base/memory.c
index 89f752dd8465..c6707dfb5284 100644
--- a/drivers/base/memory.c
+++ b/drivers/base/memory.c
@@ -315,13 +315,13 @@ store_mem_state(struct device *dev,
if (ret)
return ret;
- if (!strncmp(buf, "online_kernel", min_t(int, count, 13)))
+ if (sysfs_streq(buf, "online_kernel"))
online_type = ONLINE_KERNEL;
- else if (!strncmp(buf, "online_movable", min_t(int, count, 14)))
+ else if (sysfs_streq(buf, "online_movable"))
online_type = ONLINE_MOVABLE;
- else if (!strncmp(buf, "online", min_t(int, count, 6)))
+ else if (sysfs_streq(buf, "online"))
online_type = ONLINE_KEEP;
- else if (!strncmp(buf, "offline", min_t(int, count, 7)))
+ else if (sysfs_streq(buf, "offline"))
online_type = -1;
else {
ret = -EINVAL;