Skip to content

Commit 58db578

Browse files
Colin Ian Kingpaulmckrcu
authored andcommitted
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: 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>
1 parent 57f6020 commit 58db578

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

kernel/rcu/refscale.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -546,9 +546,11 @@ static int main_func(void *arg)
546546
// Print the average of all experiments
547547
SCALEOUT("END OF TEST. Calculating average duration per loop (nanoseconds)...\n");
548548

549-
buf[0] = 0;
550-
strcat(buf, "\n");
551-
strcat(buf, "Runs\tTime(ns)\n");
549+
if (!errexit) {
550+
buf[0] = 0;
551+
strcat(buf, "\n");
552+
strcat(buf, "Runs\tTime(ns)\n");
553+
}
552554

553555
for (exp = 0; exp < nruns; exp++) {
554556
u64 avg;

0 commit comments

Comments
 (0)