Skip to content

Commit a214fe0

Browse files
leitaoclsotog
authored andcommitted
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> (cherry picked from commit 1abaae9) Signed-off-by: Carol L Soto <csoto@nvidia.com>
1 parent 0ccf98e commit a214fe0

1 file changed

Lines changed: 2 additions & 8 deletions

File tree

kernel/workqueue.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ struct work_offq_data {
412412
u32 flags;
413413
};
414414

415-
static const char *wq_affn_names[WQ_AFFN_NR_TYPES] = {
415+
static const char * const wq_affn_names[WQ_AFFN_NR_TYPES] = {
416416
[WQ_AFFN_DFL] = "default",
417417
[WQ_AFFN_CPU] = "cpu",
418418
[WQ_AFFN_SMT] = "smt",
@@ -7090,13 +7090,7 @@ int workqueue_unbound_housekeeping_update(const struct cpumask *hk)
70907090

70917091
static int parse_affn_scope(const char *val)
70927092
{
7093-
int i;
7094-
7095-
for (i = 0; i < ARRAY_SIZE(wq_affn_names); i++) {
7096-
if (!strncasecmp(val, wq_affn_names[i], strlen(wq_affn_names[i])))
7097-
return i;
7098-
}
7099-
return -EINVAL;
7093+
return sysfs_match_string(wq_affn_names, val);
71007094
}
71017095

71027096
static int wq_affn_dfl_set(const char *val, const struct kernel_param *kp)

0 commit comments

Comments
 (0)