Skip to content

Commit 838850e

Browse files
davejiangjonmason
authored andcommitted
NTB: Fix incorrect clean up routine in ntb_perf
The clean up routine when we failed to allocate kthread is not cleaning up all the threads, only the same one over and over again. Reported-by: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: Dave Jiang <dave.jiang@intel.com> Acked-by: Allen Hubbe <Allen.Hubbe@emc.com> Signed-off-by: Jon Mason <jdmason@kudzu.us>
1 parent ddc8f6f commit 838850e

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

drivers/ntb/test/ntb_perf.c

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,21 @@ static ssize_t debugfs_run_read(struct file *filp, char __user *ubuf,
559559
return ret;
560560
}
561561

562+
static void threads_cleanup(struct perf_ctx *perf)
563+
{
564+
struct pthr_ctx *pctx;
565+
int i;
566+
567+
perf->run = false;
568+
for (i = 0; i < MAX_THREADS; i++) {
569+
pctx = &perf->pthr_ctx[i];
570+
if (pctx->thread) {
571+
kthread_stop(pctx->thread);
572+
pctx->thread = NULL;
573+
}
574+
}
575+
}
576+
562577
static ssize_t debugfs_run_write(struct file *filp, const char __user *ubuf,
563578
size_t count, loff_t *offp)
564579
{
@@ -574,17 +589,9 @@ static ssize_t debugfs_run_write(struct file *filp, const char __user *ubuf,
574589
if (atomic_read(&perf->tsync) == 0)
575590
perf->run = false;
576591

577-
if (perf->run) {
578-
/* lets stop the threads */
579-
perf->run = false;
580-
for (i = 0; i < MAX_THREADS; i++) {
581-
if (perf->pthr_ctx[i].thread) {
582-
kthread_stop(perf->pthr_ctx[i].thread);
583-
perf->pthr_ctx[i].thread = NULL;
584-
} else
585-
break;
586-
}
587-
} else {
592+
if (perf->run)
593+
threads_cleanup(perf);
594+
else {
588595
perf->run = true;
589596

590597
if (perf->perf_threads > MAX_THREADS) {
@@ -616,13 +623,8 @@ static ssize_t debugfs_run_write(struct file *filp, const char __user *ubuf,
616623
(void *)pctx,
617624
node, "ntb_perf %d", i);
618625
if (IS_ERR(pctx->thread)) {
619-
perf->run = false;
620-
for (i = 0; i < MAX_THREADS; i++) {
621-
if (pctx->thread) {
622-
kthread_stop(pctx->thread);
623-
pctx->thread = NULL;
624-
}
625-
}
626+
pctx->thread = NULL;
627+
goto err;
626628
} else
627629
wake_up_process(pctx->thread);
628630

@@ -633,6 +635,10 @@ static ssize_t debugfs_run_write(struct file *filp, const char __user *ubuf,
633635
}
634636

635637
return count;
638+
639+
err:
640+
threads_cleanup(perf);
641+
return -ENXIO;
636642
}
637643

638644
static const struct file_operations ntb_perf_debugfs_run = {

0 commit comments

Comments
 (0)