• David Rientjes's avatar
    mm, mempolicy: make mpol_to_str robust and always succeed · 948927ee
    David Rientjes authored
    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: default avatarDavid 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: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    948927ee
mempolicy.c 74.6 KB