]> git.karo-electronics.de Git - karo-tx-linux.git/commit
mm, mempolicy: make mpol_to_str robust and always succeed
authorDavid Rientjes <rientjes@google.com>
Tue, 5 Nov 2013 05:55:32 +0000 (16:55 +1100)
committerStephen Rothwell <sfr@canb.auug.org.au>
Tue, 5 Nov 2013 05:55:32 +0000 (16:55 +1100)
commitba74acca911c6be76a9f16643156a0bb69cd62ed
tree7de7d7c67daa4762ed7775484a4bfffcf95579c3
parent88dda4960eae890535d4450675bc5385ffb236a0
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>
fs/proc/task_mmu.c
include/linux/mempolicy.h
mm/mempolicy.c