diff options
author | Greg Kroah-Hartman <greg@kroah.com> | 2015-04-01 01:36:23 +0200 |
---|---|---|
committer | Greg Kroah-Hartman <greg@kroah.com> | 2015-04-01 01:36:23 +0200 |
commit | 66c98986c909bfe789e8b15f805fd28ef4c36b76 (patch) | |
tree | ec1d1ed2d482cdc57e9ab6960e4e9128a077f258 /drivers/staging/greybus/kernel_ver.h | |
parent | 7a51b9362b547b2f02ef88c10636950637c71fa5 (diff) |
greybus: kernel_ver.h: add sysfs_create_groups() and sysfs_remove_groups()
These functions showed up in 3.12 or so, and we are stuck on 3.10 for
various reasons, so provide backports in kernel_ver.h so that we can
rely on these functions.
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Diffstat (limited to 'drivers/staging/greybus/kernel_ver.h')
-rw-r--r-- | drivers/staging/greybus/kernel_ver.h | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/drivers/staging/greybus/kernel_ver.h b/drivers/staging/greybus/kernel_ver.h index 12b454e4dbf2..92eb024c3bed 100644 --- a/drivers/staging/greybus/kernel_ver.h +++ b/drivers/staging/greybus/kernel_ver.h @@ -78,6 +78,8 @@ static inline void gb_gpiochip_remove(struct gpio_chip *chip) * it here. */ #if LINUX_VERSION_CODE < KERNEL_VERSION(3,11,0) +#include <linux/sysfs.h> + #define ATTRIBUTE_GROUPS(name) \ static const struct attribute_group name##_group = { \ .attrs = name##_attrs, \ @@ -86,6 +88,37 @@ static const struct attribute_group *name##_groups[] = { \ &name##_group, \ NULL, \ } + +static inline int sysfs_create_groups(struct kobject *kobj, + const struct attribute_group **groups) +{ + int error = 0; + int i; + + if (!groups) + return 0; + + for (i = 0; groups[i]; i++) { + error = sysfs_create_group(kobj, groups[i]); + if (error) { + while (--i >= 0) + sysfs_remove_group(kobj, groups[i]); + break; + } + } + return error; +} + +static inline void sysfs_remove_groups(struct kobject *kobj, + const struct attribute_group **groups) +{ + int i; + + if (!groups) + return; + for (i = 0; groups[i]; i++) + sysfs_remove_group(kobj, groups[i]); +} #endif #endif /* __GREYBUS_KERNEL_VER_H */ |