Commit 838850ee authored by Dave Jiang's avatar Dave Jiang Committed by Jon Mason

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: default avatarDan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: default avatarDave Jiang <dave.jiang@intel.com>
Acked-by: default avatarAllen Hubbe <Allen.Hubbe@emc.com>
Signed-off-by: default avatarJon Mason <jdmason@kudzu.us>
parent ddc8f6fe
...@@ -559,6 +559,21 @@ static ssize_t debugfs_run_read(struct file *filp, char __user *ubuf, ...@@ -559,6 +559,21 @@ static ssize_t debugfs_run_read(struct file *filp, char __user *ubuf,
return ret; return ret;
} }
static void threads_cleanup(struct perf_ctx *perf)
{
struct pthr_ctx *pctx;
int i;
perf->run = false;
for (i = 0; i < MAX_THREADS; i++) {
pctx = &perf->pthr_ctx[i];
if (pctx->thread) {
kthread_stop(pctx->thread);
pctx->thread = NULL;
}
}
}
static ssize_t debugfs_run_write(struct file *filp, const char __user *ubuf, static ssize_t debugfs_run_write(struct file *filp, const char __user *ubuf,
size_t count, loff_t *offp) size_t count, loff_t *offp)
{ {
...@@ -574,17 +589,9 @@ static ssize_t debugfs_run_write(struct file *filp, const char __user *ubuf, ...@@ -574,17 +589,9 @@ static ssize_t debugfs_run_write(struct file *filp, const char __user *ubuf,
if (atomic_read(&perf->tsync) == 0) if (atomic_read(&perf->tsync) == 0)
perf->run = false; perf->run = false;
if (perf->run) { if (perf->run)
/* lets stop the threads */ threads_cleanup(perf);
perf->run = false; else {
for (i = 0; i < MAX_THREADS; i++) {
if (perf->pthr_ctx[i].thread) {
kthread_stop(perf->pthr_ctx[i].thread);
perf->pthr_ctx[i].thread = NULL;
} else
break;
}
} else {
perf->run = true; perf->run = true;
if (perf->perf_threads > MAX_THREADS) { if (perf->perf_threads > MAX_THREADS) {
...@@ -616,13 +623,8 @@ static ssize_t debugfs_run_write(struct file *filp, const char __user *ubuf, ...@@ -616,13 +623,8 @@ static ssize_t debugfs_run_write(struct file *filp, const char __user *ubuf,
(void *)pctx, (void *)pctx,
node, "ntb_perf %d", i); node, "ntb_perf %d", i);
if (IS_ERR(pctx->thread)) { if (IS_ERR(pctx->thread)) {
perf->run = false;
for (i = 0; i < MAX_THREADS; i++) {
if (pctx->thread) {
kthread_stop(pctx->thread);
pctx->thread = NULL; pctx->thread = NULL;
} goto err;
}
} else } else
wake_up_process(pctx->thread); wake_up_process(pctx->thread);
...@@ -633,6 +635,10 @@ static ssize_t debugfs_run_write(struct file *filp, const char __user *ubuf, ...@@ -633,6 +635,10 @@ static ssize_t debugfs_run_write(struct file *filp, const char __user *ubuf,
} }
return count; return count;
err:
threads_cleanup(perf);
return -ENXIO;
} }
static const struct file_operations ntb_perf_debugfs_run = { static const struct file_operations ntb_perf_debugfs_run = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment