]> git.baikalelectronics.ru Git - kernel.git/commit
mm, mempolicy: make mpol_to_str robust and always succeed
authorDavid Rientjes <rientjes@google.com>
Tue, 12 Nov 2013 23:07:28 +0000 (15:07 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 13 Nov 2013 03:09:05 +0000 (12:09 +0900)
commitfa976a3cf1cdb17dbf1d46f9a4432c2363314b55
tree611c78ab8b15b7ed1bb1e03791711bfb8f19edf5
parentd543ccd11a78923df80e217eacfab54409e5fdd9
mm, mempolicy: make mpol_to_str robust and always succeed

mpol_to_str() should not fail.  Currently, it either fails because the
string buffer is too small or because a string hasn't been defined for a
mempolicy mode.

If a new mempolicy mode is introduced and no string is defined for it,
just warn and return "unknown".

If the buffer is too small, just truncate the string and return, the
same behavior as snprintf().

This also fixes a bug where there was no NULL-byte termination when doing
*p++ = '=' and *p++ ':' and maxlen has been reached.

Signed-off-by: David Rientjes <rientjes@google.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Chen Gang <gang.chen@asianux.com>
Cc: Rik van Riel <riel@redhat.com>
Cc: Dave Jones <davej@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
fs/proc/task_mmu.c
include/linux/mempolicy.h
mm/mempolicy.c