Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

workqueue: fix parse_affn_scope() prefix matching bug

parse_affn_scope() uses strncasecmp() with the length of the candidate
name, which means it only checks if the input *starts with* a known
scope name.

Given that the upcoming diff will create "cache_shard" affinity scope,
writing "cache_shard" to a workqueue's affinity_scope sysfs attribute
always matches "cache" first, making it impossible to select
"cache_shard" via sysfs, so, this fix enable it to distinguish "cache"
and "cache_shard"

Fix by replacing the hand-rolled prefix matching loop with
sysfs_match_string(), which uses sysfs_streq() for exact matching
(modulo trailing newlines). Also add the missing const qualifier to
the wq_affn_names[] array declaration.

Note that sysfs_streq() is case-sensitive, unlike the previous
strncasecmp() approach. This is intentional and consistent with
how other sysfs attributes handle string matching in the kernel.

Signed-off-by: Breno Leitao <leitao@debian.org>
Signed-off-by: Tejun Heo <tj@kernel.org>

authored by

Breno Leitao and committed by
Tejun Heo
1abaae9b b39bf7f0

+2 -8
+2 -8
kernel/workqueue.c
··· 405 405 u32 flags; 406 406 }; 407 407 408 - static const char *wq_affn_names[WQ_AFFN_NR_TYPES] = { 408 + static const char * const wq_affn_names[WQ_AFFN_NR_TYPES] = { 409 409 [WQ_AFFN_DFL] = "default", 410 410 [WQ_AFFN_CPU] = "cpu", 411 411 [WQ_AFFN_SMT] = "smt", ··· 7093 7093 7094 7094 static int parse_affn_scope(const char *val) 7095 7095 { 7096 - int i; 7097 - 7098 - for (i = 0; i < ARRAY_SIZE(wq_affn_names); i++) { 7099 - if (!strncasecmp(val, wq_affn_names[i], strlen(wq_affn_names[i]))) 7100 - return i; 7101 - } 7102 - return -EINVAL; 7096 + return sysfs_match_string(wq_affn_names, val); 7103 7097 } 7104 7098 7105 7099 static int wq_affn_dfl_set(const char *val, const struct kernel_param *kp)