[PATCH] driver: sysfs: Replace default_attrs with default_groups

2 views
Skip to first unread message

Ralf Ramsauer

unread,
Apr 26, 2022, 1:22:34 PM4/26/22
to Jan Kiszka, Jailhouse, Ralf Ramsauer, Stefan Huber
Since Linux commit cdb4f26a63c3 ("kobject: kobj_type: remove
default_attrs"), the deprecated kobj member default_attrs is gone. It is
replaced by default_groups.

default_groups is available since 2013, so simply switch to
default_groups, without (hopefully) breaking any older kernel.

Signed-off-by: Ralf Ramsauer <ralf.r...@oth-regensburg.de>
---
driver/sysfs.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/driver/sysfs.c b/driver/sysfs.c
index a604afa4..f91d5ac5 100644
--- a/driver/sysfs.c
+++ b/driver/sysfs.c
@@ -180,10 +180,11 @@ static struct attribute *cell_stats_attrs[] = {
#endif
NULL
};
+ATTRIBUTE_GROUPS(cell_stats);

static struct kobj_type cell_stats_type = {
.sysfs_ops = &kobj_sysfs_ops,
- .default_attrs = cell_stats_attrs,
+ .default_groups = cell_stats_groups,
};

static struct attribute *cpu_stats_attrs[] = {
@@ -212,10 +213,11 @@ static struct attribute *cpu_stats_attrs[] = {
#endif
NULL
};
+ATTRIBUTE_GROUPS(cpu_stats);

static struct kobj_type cell_cpu_type = {
.sysfs_ops = &kobj_sysfs_ops,
- .default_attrs = cpu_stats_attrs,
+ .default_groups = cpu_stats_groups,
};

static int print_cpumask(char *buf, size_t size, cpumask_t *mask, bool as_list)
@@ -342,11 +344,12 @@ static struct attribute *cell_attrs[] = {
&cell_cpus_failed_list_attr.attr,
NULL,
};
+ATTRIBUTE_GROUPS(cell);

static struct kobj_type cell_type = {
.release = jailhouse_cell_kobj_release,
.sysfs_ops = &kobj_sysfs_ops,
- .default_attrs = cell_attrs,
+ .default_groups = cell_groups,
};

static struct cell_cpu *find_cell_cpu(struct cell *cell, unsigned int cpu)
--
2.36.0

Jan Kiszka

unread,
Apr 27, 2022, 2:26:12 AM4/27/22
to Ralf Ramsauer, Jailhouse, Stefan Huber
Which kernel versions are compatible with the new API?

Jan

--
Siemens AG, Technology
Competence Center Embedded Linux

Ralf Ramsauer

unread,
Apr 27, 2022, 12:13:42 PM4/27/22
to Jan Kiszka, Jailhouse, Stefan Huber
With the latest v5.18 release, it becomes mandatory.

I just successfully compile-tested v5.17, v5.16, v5.14, v5.10, v5.4 and
v5.2 (the latest one that works). Latest LTS 4.19.y and downwards won't
compile.

The question is, if we want to demand at least v5.2, or introduce yet
another workaround.

Ralf

Jan Kiszka

unread,
Apr 27, 2022, 12:34:20 PM4/27/22
to Ralf Ramsauer, Jailhouse, Stefan Huber
I think wrapping could be fairly simple in this case, and 4.19 may still
be used, and we actually wrap much further down, let's account for this
difference once again.

Ralf Ramsauer

unread,
Apr 27, 2022, 2:18:55 PM4/27/22
to Jan Kiszka, Jailhouse, Ralf Ramsauer, Stefan Huber
Since Linux commit cdb4f26a63c3 ("kobject: kobj_type: remove
default_attrs"), the deprecated kobj member default_attrs is gone. It is
replaced by default_groups.

Add a compatibility layer to support older, as well as latest kernel
versions.

Signed-off-by: Ralf Ramsauer <ralf.r...@oth-regensburg.de>
---

Note: only compile-time tested!

driver/sysfs.c | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/driver/sysfs.c b/driver/sysfs.c
index a604afa4..a5a02831 100644
--- a/driver/sysfs.c
+++ b/driver/sysfs.c
@@ -59,6 +59,14 @@ static const struct sysfs_ops cell_sysfs_ops = {
};
#define kobj_sysfs_ops cell_sysfs_ops
#endif /* < 3.14 */
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(5,2,0)
+#define COMPAT_ATTRIBUTE_GROUPS(x) /* not used */
+#define DEFAULT_GROUPS(x) .default_attrs = x##_attrs
+#else
+#define COMPAT_ATTRIBUTE_GROUPS(x) ATTRIBUTE_GROUPS(x)
+#define DEFAULT_GROUPS(x) .default_groups = x##_groups
+#endif /* < 5.2 */
/* End of compatibility section - remove as version become obsolete */

static struct kobject *cells_dir;
@@ -180,10 +188,11 @@ static struct attribute *cell_stats_attrs[] = {
#endif
NULL
};
+COMPAT_ATTRIBUTE_GROUPS(cell_stats);

static struct kobj_type cell_stats_type = {
.sysfs_ops = &kobj_sysfs_ops,
- .default_attrs = cell_stats_attrs,
+ DEFAULT_GROUPS(cell_stats),
};

static struct attribute *cpu_stats_attrs[] = {
@@ -212,10 +221,11 @@ static struct attribute *cpu_stats_attrs[] = {
#endif
NULL
};
+COMPAT_ATTRIBUTE_GROUPS(cpu_stats);

static struct kobj_type cell_cpu_type = {
.sysfs_ops = &kobj_sysfs_ops,
- .default_attrs = cpu_stats_attrs,
+ DEFAULT_GROUPS(cpu_stats),
};

static int print_cpumask(char *buf, size_t size, cpumask_t *mask, bool as_list)
@@ -342,11 +352,12 @@ static struct attribute *cell_attrs[] = {
&cell_cpus_failed_list_attr.attr,
NULL,
};
+COMPAT_ATTRIBUTE_GROUPS(cell);

static struct kobj_type cell_type = {
.release = jailhouse_cell_kobj_release,
.sysfs_ops = &kobj_sysfs_ops,
- .default_attrs = cell_attrs,
+ DEFAULT_GROUPS(cell),
};

static struct cell_cpu *find_cell_cpu(struct cell *cell, unsigned int cpu)
--
2.36.0

Jan Kiszka

unread,
May 2, 2022, 12:09:15 PM5/2/22
to Ralf Ramsauer, Jailhouse, Stefan Huber
Thanks, applied.
Reply all
Reply to author
Forward
0 new messages