提交 8f894bf4 编写于 作者: Y Yisheng Xie 提交者: Ingo Molnar

sched/debug: Use match_string() helper instead of open-coded logic

match_string() returns the index of an array for a matching string,
which can be used instead of the open coded variant.
Signed-off-by: NYisheng Xie <xieyisheng1@huawei.com>
Reviewed-by: NAndy Shevchenko <andy.shevchenko@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/lkml/1527765086-19873-15-git-send-email-xieyisheng1@huawei.comSigned-off-by: NIngo Molnar <mingo@kernel.org>
上级 b3dae109
...@@ -111,8 +111,10 @@ static int sched_feat_set(char *cmp) ...@@ -111,8 +111,10 @@ static int sched_feat_set(char *cmp)
cmp += 3; cmp += 3;
} }
for (i = 0; i < __SCHED_FEAT_NR; i++) { i = match_string(sched_feat_names, __SCHED_FEAT_NR, cmp);
if (strcmp(cmp, sched_feat_names[i]) == 0) { if (i < 0)
return i;
if (neg) { if (neg) {
sysctl_sched_features &= ~(1UL << i); sysctl_sched_features &= ~(1UL << i);
sched_feat_disable(i); sched_feat_disable(i);
...@@ -120,11 +122,8 @@ static int sched_feat_set(char *cmp) ...@@ -120,11 +122,8 @@ static int sched_feat_set(char *cmp)
sysctl_sched_features |= (1UL << i); sysctl_sched_features |= (1UL << i);
sched_feat_enable(i); sched_feat_enable(i);
} }
break;
}
}
return i; return 0;
} }
static ssize_t static ssize_t
...@@ -133,7 +132,7 @@ sched_feat_write(struct file *filp, const char __user *ubuf, ...@@ -133,7 +132,7 @@ sched_feat_write(struct file *filp, const char __user *ubuf,
{ {
char buf[64]; char buf[64];
char *cmp; char *cmp;
int i; int ret;
struct inode *inode; struct inode *inode;
if (cnt > 63) if (cnt > 63)
...@@ -148,10 +147,10 @@ sched_feat_write(struct file *filp, const char __user *ubuf, ...@@ -148,10 +147,10 @@ sched_feat_write(struct file *filp, const char __user *ubuf,
/* Ensure the static_key remains in a consistent state */ /* Ensure the static_key remains in a consistent state */
inode = file_inode(filp); inode = file_inode(filp);
inode_lock(inode); inode_lock(inode);
i = sched_feat_set(cmp); ret = sched_feat_set(cmp);
inode_unlock(inode); inode_unlock(inode);
if (i == __SCHED_FEAT_NR) if (ret < 0)
return -EINVAL; return ret;
*ppos += cnt; *ppos += cnt;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册