summaryrefslogtreecommitdiffstats
path: root/tracing-histogram-Remove-large-array-from-stack-fram.patch
blob: 7b1739e6c47882421a6c64981902b7e893391152 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
From 54bd51480b44b29d54af12de4e93e4677b4e746c Mon Sep 17 00:00:00 2001
From: Carsten Emde <C.Emde@osadl.org>
Date: Wed, 24 Feb 2010 07:49:33 +0100
Subject: [PATCH] tracing: histogram: Remove large array from stack frame

commit 18efbf5b5a41937fa7dd3839a3a8a42fda538cf1 in tip.

Remove stack allocation of buffer space, use dyn memory instead.
Use a better assumption to estimate the required buffer space.

Reported-by: Dan Carpenter <error27@gmail.com>
Signed-off-by: Carsten Emde <C.Emde@osadl.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
---
 kernel/trace/latency_hist.c |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/kernel/trace/latency_hist.c b/kernel/trace/latency_hist.c
index 9f20d61..ce67060 100644
--- a/kernel/trace/latency_hist.c
+++ b/kernel/trace/latency_hist.c
@@ -442,13 +442,19 @@ static ssize_t do_pid(struct file *file, const char __user *ubuf,
 static ssize_t
 show_maxlatproc(struct file *file, char __user *ubuf, size_t cnt, loff_t *ppos)
 {
-	char buf[1024];
 	int r;
 	struct maxlatproc_data *mp = file->private_data;
+	int strmaxlen = TASK_COMM_LEN + 32;
+	char *buf = kmalloc(strmaxlen, GFP_KERNEL);
 
-	r = snprintf(buf, sizeof(buf), "%d %d %ld %s\n",
+	if (buf == NULL)
+		return -ENOMEM;
+
+	r = snprintf(buf, strmaxlen, "%d %d %ld %s\n",
 	    mp->pid, MAX_RT_PRIO-1 - mp->prio, mp->latency, mp->comm);
-	return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
+	r = simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
+	kfree(buf);
+	return r;
 }
 #endif
 
-- 
1.7.0.4