From 6698b2cae647bf633a91ec639c63c30619e4ec14 Mon Sep 17 00:00:00 2001 From: hselasky Date: Mon, 4 Nov 2019 14:19:09 +0000 Subject: [PATCH] Enable device class group attributes in the LinuxKPI. Bump the __FreeBSD_version to force recompilation of external kernel modules due to structure change. Differential Revision: https://reviews.freebsd.org/D21564 Submitted by: Greg V MFC after: 1 week Sponsored by: Mellanox Technologies --- .../linuxkpi/common/include/linux/device.h | 5 +++++ .../linuxkpi/common/include/linux/sysfs.h | 20 ++++++++++++++++--- sys/sys/param.h | 2 +- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/sys/compat/linuxkpi/common/include/linux/device.h b/sys/compat/linuxkpi/common/include/linux/device.h index 0e8711f687e0..5361236baea8 100644 --- a/sys/compat/linuxkpi/common/include/linux/device.h +++ b/sys/compat/linuxkpi/common/include/linux/device.h @@ -54,6 +54,7 @@ struct class { struct kobject kobj; devclass_t bsdclass; const struct dev_pm_ops *pm; + const struct attribute_group **dev_groups; void (*class_release)(struct class *class); void (*dev_release)(struct device *dev); char * (*devnode)(struct device *dev, umode_t *mode); @@ -424,6 +425,8 @@ done: kobject_init(&dev->kobj, &linux_dev_ktype); kobject_add(&dev->kobj, &dev->class->kobj, dev_name(dev)); + sysfs_create_groups(&dev->kobj, dev->class->dev_groups); + return (0); } @@ -432,6 +435,8 @@ device_unregister(struct device *dev) { device_t bsddev; + sysfs_remove_groups(&dev->kobj, dev->class->dev_groups); + bsddev = dev->bsddev; dev->bsddev = NULL; diff --git a/sys/compat/linuxkpi/common/include/linux/sysfs.h b/sys/compat/linuxkpi/common/include/linux/sysfs.h index 164b9befbf5f..59e30f152f6e 100644 --- a/sys/compat/linuxkpi/common/include/linux/sysfs.h +++ b/sys/compat/linuxkpi/common/include/linux/sysfs.h @@ -62,12 +62,13 @@ struct attribute_group { #define ATTRIBUTE_GROUPS(_name) \ static struct attribute_group _name##_group = { \ + .name = __stringify(_name), \ .attrs = _name##_attrs, \ }; \ - static struct attribute_group *_name##_groups[] = { \ + static const struct attribute_group *_name##_groups[] = { \ &_name##_group, \ NULL, \ - }; + } /* * Handle our generic '\0' terminated 'C' string. @@ -210,14 +211,27 @@ sysfs_create_groups(struct kobject *kobj, const struct attribute_group **grps) int error = 0; int i; + if (grps == NULL) + goto done; for (i = 0; grps[i] && !error; i++) error = sysfs_create_group(kobj, grps[i]); while (error && --i >= 0) sysfs_remove_group(kobj, grps[i]); - +done: return (error); } +static inline void +sysfs_remove_groups(struct kobject *kobj, const struct attribute_group **grps) +{ + int i; + + if (grps == NULL) + return; + for (i = 0; grps[i]; i++) + sysfs_remove_group(kobj, grps[i]); +} + static inline int sysfs_merge_group(struct kobject *kobj, const struct attribute_group *grp) { diff --git a/sys/sys/param.h b/sys/sys/param.h index dd987bb44ffd..7602bf89ff55 100644 --- a/sys/sys/param.h +++ b/sys/sys/param.h @@ -60,7 +60,7 @@ * in the range 5 to 9. */ #undef __FreeBSD_version -#define __FreeBSD_version 1300054 /* Master, propagated to newvers */ +#define __FreeBSD_version 1300055 /* Master, propagated to newvers */ /* * __FreeBSD_kernel__ indicates that this system uses the kernel of FreeBSD,