Skip to content

Commit

Permalink
refperf: Avoid null pointer dereference when buf fails to allocate
Browse files Browse the repository at this point in the history
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: f518f15 ("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>
  • Loading branch information
Colin Ian King authored and paulmckrcu committed Aug 25, 2020
1 parent 57f6020 commit 58db578
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions kernel/rcu/refscale.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 58db578

Please sign in to comment.