diff options
| author | Breno Leitao <leitao@debian.org> | 2026-03-12 09:12:02 -0700 |
|---|---|---|
| committer | Tejun Heo <tj@kernel.org> | 2026-03-13 07:36:40 -1000 |
| commit | 1abaae9b38a85c9dabff67a22d8c99f7254c423a (patch) | |
| tree | 1698a937dcdb27ab2383b2908f4a44ef67a84c17 /kernel/workqueue.c | |
| parent | b39bf7f0fae98c03e5ba6061e2251eeb36ec0b39 (diff) | |
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>
Diffstat (limited to 'kernel/workqueue.c')
| -rw-r--r-- | kernel/workqueue.c | 10 |
1 files changed, 2 insertions, 8 deletions
diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 715a23d5348f..c1743b20a524 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -405,7 +405,7 @@ struct work_offq_data { u32 flags; }; -static const char *wq_affn_names[WQ_AFFN_NR_TYPES] = { +static const char * const wq_affn_names[WQ_AFFN_NR_TYPES] = { [WQ_AFFN_DFL] = "default", [WQ_AFFN_CPU] = "cpu", [WQ_AFFN_SMT] = "smt", @@ -7093,13 +7093,7 @@ int workqueue_unbound_housekeeping_update(const struct cpumask *hk) static int parse_affn_scope(const char *val) { - int i; - - for (i = 0; i < ARRAY_SIZE(wq_affn_names); i++) { - if (!strncasecmp(val, wq_affn_names[i], strlen(wq_affn_names[i]))) - return i; - } - return -EINVAL; + return sysfs_match_string(wq_affn_names, val); } static int wq_affn_dfl_set(const char *val, const struct kernel_param *kp) |
