Skip to content

Commit 8f894bf

Browse files
Yisheng XieIngo Molnar
authored andcommitted
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: Yisheng Xie <xieyisheng1@huawei.com> Reviewed-by: Andy 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.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent b3dae10 commit 8f894bf

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

kernel/sched/debug.c

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -111,20 +111,19 @@ static int sched_feat_set(char *cmp)
111111
cmp += 3;
112112
}
113113

114-
for (i = 0; i < __SCHED_FEAT_NR; i++) {
115-
if (strcmp(cmp, sched_feat_names[i]) == 0) {
116-
if (neg) {
117-
sysctl_sched_features &= ~(1UL << i);
118-
sched_feat_disable(i);
119-
} else {
120-
sysctl_sched_features |= (1UL << i);
121-
sched_feat_enable(i);
122-
}
123-
break;
124-
}
114+
i = match_string(sched_feat_names, __SCHED_FEAT_NR, cmp);
115+
if (i < 0)
116+
return i;
117+
118+
if (neg) {
119+
sysctl_sched_features &= ~(1UL << i);
120+
sched_feat_disable(i);
121+
} else {
122+
sysctl_sched_features |= (1UL << i);
123+
sched_feat_enable(i);
125124
}
126125

127-
return i;
126+
return 0;
128127
}
129128

130129
static ssize_t
@@ -133,7 +132,7 @@ sched_feat_write(struct file *filp, const char __user *ubuf,
133132
{
134133
char buf[64];
135134
char *cmp;
136-
int i;
135+
int ret;
137136
struct inode *inode;
138137

139138
if (cnt > 63)
@@ -148,10 +147,10 @@ sched_feat_write(struct file *filp, const char __user *ubuf,
148147
/* Ensure the static_key remains in a consistent state */
149148
inode = file_inode(filp);
150149
inode_lock(inode);
151-
i = sched_feat_set(cmp);
150+
ret = sched_feat_set(cmp);
152151
inode_unlock(inode);
153-
if (i == __SCHED_FEAT_NR)
154-
return -EINVAL;
152+
if (ret < 0)
153+
return ret;
155154

156155
*ppos += cnt;
157156

0 commit comments

Comments
 (0)