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.

sched_ext: Replace naked scx_root dereferences in kobject callbacks

scx_attr_ops_show() and scx_uevent() access scx_root->ops.name directly.
This is problematic for two reasons:

1. The file-level comment explicitly identifies naked scx_root
dereferences as a temporary measure that needs to be replaced
with proper per-instance access.

2. scx_attr_events_show(), the neighboring sysfs show function in
the same group, already uses the correct pattern:

struct scx_sched *sch = container_of(kobj, struct scx_sched, kobj);

Having inconsistent access patterns in the same sysfs/uevent
group is error-prone.

The kobject embedded in struct scx_sched is initialized as:

kobject_init_and_add(&sch->kobj, &scx_ktype, NULL, "root");

so container_of(kobj, struct scx_sched, kobj) correctly retrieves
the owning scx_sched instance in both callbacks.

Replace the naked scx_root dereferences with container_of()-based
access, consistent with scx_attr_events_show() and in preparation
for proper multi-instance scx_sched support.

Signed-off-by: zhidao su <suzhidao@xiaomi.com>
Signed-off-by: Tejun Heo <tj@kernel.org>

authored by

zhidao su and committed by
Tejun Heo
494eaf46 9adfcef3

+6 -2
+6 -2
kernel/sched/ext.c
··· 3712 3712 static ssize_t scx_attr_ops_show(struct kobject *kobj, 3713 3713 struct kobj_attribute *ka, char *buf) 3714 3714 { 3715 - return sysfs_emit(buf, "%s\n", scx_root->ops.name); 3715 + struct scx_sched *sch = container_of(kobj, struct scx_sched, kobj); 3716 + 3717 + return sysfs_emit(buf, "%s\n", sch->ops.name); 3716 3718 } 3717 3719 SCX_ATTR(ops); 3718 3720 ··· 3758 3756 3759 3757 static int scx_uevent(const struct kobject *kobj, struct kobj_uevent_env *env) 3760 3758 { 3761 - return add_uevent_var(env, "SCXOPS=%s", scx_root->ops.name); 3759 + const struct scx_sched *sch = container_of(kobj, struct scx_sched, kobj); 3760 + 3761 + return add_uevent_var(env, "SCXOPS=%s", sch->ops.name); 3762 3762 } 3763 3763 3764 3764 static const struct kset_uevent_ops scx_uevent_ops = {