summary refs log tree commit diff
path: root/kernel/rcu
diff options
context:
space:
mode:
authorColin Ian King <colin.king@canonical.com>2020-07-16 15:38:56 +0100
committerPaul E. McKenney <paulmck@kernel.org>2020-08-24 18:45:35 -0700
commit58db5785b0d76be4582a32a7900acce88e691d36 (patch)
treed7632ad3bc8c221f86da83ccdd553a304fcad51e /kernel/rcu
parent57f602022e82ee8fa6476d0e16ddbaf3eb86b245 (diff)
downloadlinux-58db5785b0d76be4582a32a7900acce88e691d36.tar.gz
refperf: Avoid null pointer dereference when buf fails to allocate
Currently in the unlikely event that buf fails to be allocated it
is dereferenced a few times.  Use the errexit flag to determine if
buf should be written to to avoid the null pointer dereferences.

Addresses-Coverity: ("Dereference after null check")
Fixes: f518f154ecef ("refperf: Dynamically allocate experiment-summary output buffer")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
Diffstat (limited to 'kernel/rcu')
-rw-r--r--kernel/rcu/refscale.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/kernel/rcu/refscale.c b/kernel/rcu/refscale.c
index d9291f883b54..952595c678b3 100644
--- a/kernel/rcu/refscale.c
+++ b/kernel/rcu/refscale.c
@@ -546,9 +546,11 @@ static int main_func(void *arg)
 	// Print the average of all experiments
 	SCALEOUT("END OF TEST. Calculating average duration per loop (nanoseconds)...\n");
 
-	buf[0] = 0;
-	strcat(buf, "\n");
-	strcat(buf, "Runs\tTime(ns)\n");
+	if (!errexit) {
+		buf[0] = 0;
+		strcat(buf, "\n");
+		strcat(buf, "Runs\tTime(ns)\n");
+	}
 
 	for (exp = 0; exp < nruns; exp++) {
 		u64 avg;