refperf: Dynamically allocate experiment-summary output buffer
Hello Paul E. McKenney,
This is a semi-automatic email about new static checker warnings.
The patch 54c0ed208976: "refperf: Dynamically allocate experiment-summary output buffer" from May 25, 2020, leads to the following Smatch complaint:
kernel/rcu/refperf.c:395 main_func()
error: we previously assumed 'buf' could be null (see line 352)
kernel/rcu/refperf.c
351 buf = kzalloc(64 + nruns * 32, GFP_KERNEL);
352 if (!result_avg || !buf) {
^^^^Check for NULL
353 VERBOSE_PERFOUT_ERRSTRING("out of memory");
354 errexit = true;
355 }
356 atomic_inc(&n_init);
357
358 // Wait for all threads to start.
359 wait_event(main_wq, atomic_read(&n_init) == (nreaders + 1));
360
361 // Start exp readers up per experiment
362 for (exp = 0; exp < nruns && !torture_must_stop(); exp++) {
363 if (errexit)
364 break;
365 if (torture_must_stop())
366 goto end;
367
368 reset_readers();
369 atomic_set(&nreaders_exp, nreaders);
370
371 exp_idx = exp;
372
373 for (r = 0; r < nreaders; r++) {
374 atomic_set(&reader_tasks[r].start, 1);
375 wake_up(&reader_tasks[r].wq);
376 }
377
378 VERBOSE_PERFOUT("main_func: experiment started, waiting for %d readers",
379 nreaders);
380
381 wait_event(main_wq,
382 !atomic_read(&nreaders_exp) || torture_must_stop());
383
384 VERBOSE_PERFOUT("main_func: experiment ended");
385
386 if (torture_must_stop())
387 goto end;
388
389 result_avg[exp] = 1000 * process_durations(nreaders) / (nreaders * loops);
390 }
391
392 // Print the average of all experiments
393 PERFOUT("END OF TEST. Calculating average duration per loop (nanoseconds)...\n");
394
395 buf[0] = 0;
^^^^^^Unchecked dereferences.
396 strcat(buf, "\n"); 397 strcat(buf, "Threads\tTime(ns)\n");
regards,
dan carpenter
Quoted 8 lines · Dan Carpenter
Hello Paul E. McKenney,
This is a semi-automatic email about new static checker warnings.
The patch
54c0ed208976: "refperf: Dynamically allocate experiment-summary output buffer" from May 25, 2020, leads to the following Smatch complaint:
Quoted 8 lines
kernel/rcu/refperf.c:395main_func()
error: we previously assumed 'buf' could be null (see line 352)
kernel/rcu/refperf.c351 buf = kzalloc(64 + nruns * 32, GFP_KERNEL); 352 if (!result_avg || !buf) { ^^^^Check for NULL
Makes sense. Looks like Paul already fixed it so should be good.
Thanks!