aboutsummaryrefslogtreecommitdiffstats
path: root/fs/proc
diff options
context:
space:
mode:
authorDavid Rientjes <rientjes@google.com>2013-11-12 18:07:28 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2013-11-12 22:09:05 -0500
commit948927ee9e4f35f287e61a79c9f0e85ca2202c7d (patch)
tree611c78ab8b15b7ed1bb1e03791711bfb8f19edf5 /fs/proc
parent40c3baa7c66f1352521378ee83509fb8f4c465de (diff)
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>
Diffstat (limited to 'fs/proc')
-rw-r--r--fs/proc/task_mmu.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index 390bdab01c3c..9f1369fe0afb 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -1387,8 +1387,8 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
1387 struct mm_struct *mm = vma->vm_mm; 1387 struct mm_struct *mm = vma->vm_mm;
1388 struct mm_walk walk = {}; 1388 struct mm_walk walk = {};
1389 struct mempolicy *pol; 1389 struct mempolicy *pol;
1390 int n; 1390 char buffer[64];
1391 char buffer[50]; 1391 int nid;
1392 1392
1393 if (!mm) 1393 if (!mm)
1394 return 0; 1394 return 0;
@@ -1404,10 +1404,8 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
1404 walk.mm = mm; 1404 walk.mm = mm;
1405 1405
1406 pol = get_vma_policy(task, vma, vma->vm_start); 1406 pol = get_vma_policy(task, vma, vma->vm_start);
1407 n = mpol_to_str(buffer, sizeof(buffer), pol); 1407 mpol_to_str(buffer, sizeof(buffer), pol);
1408 mpol_cond_put(pol); 1408 mpol_cond_put(pol);
1409 if (n < 0)
1410 return n;
1411 1409
1412 seq_printf(m, "%08lx %s", vma->vm_start, buffer); 1410 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
1413 1411
@@ -1460,9 +1458,9 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
1460 if (md->writeback) 1458 if (md->writeback)
1461 seq_printf(m, " writeback=%lu", md->writeback); 1459 seq_printf(m, " writeback=%lu", md->writeback);
1462 1460
1463 for_each_node_state(n, N_MEMORY) 1461 for_each_node_state(nid, N_MEMORY)
1464 if (md->node[n]) 1462 if (md->node[nid])
1465 seq_printf(m, " N%d=%lu", n, md->node[n]); 1463 seq_printf(m, " N%d=%lu", nid, md->node[nid]);
1466out: 1464out:
1467 seq_putc(m, '\n'); 1465 seq_putc(m, '\n');
1468 1466