driver core: add device_{add|remove}_group() helpers
authorDmitry Torokhov <dmitry.torokhov@gmail.com>
Thu, 20 Jul 2017 00:24:32 +0000 (17:24 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 22 Jul 2017 09:59:23 +0000 (11:59 +0200)
We have helpers that work with NULL terminated array of groups, but many
drivers only create a single supplemental group, and do not want to declare
a group array. Let's provide them with helpers working with a single group.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
include/linux/device.h

index 10cf209a4e8219936e5ca93cdd1b099b332ef1b5..7698a513b35e397a2aa5d0ddead47f075fa775e0 100644 (file)
@@ -1205,6 +1205,22 @@ extern int __must_check device_add_groups(struct device *dev,
 extern void device_remove_groups(struct device *dev,
                                 const struct attribute_group **groups);
 
+static inline int __must_check device_add_group(struct device *dev,
+                                       const struct attribute_group *grp)
+{
+       const struct attribute_group *groups[] = { grp, NULL };
+
+       return device_add_groups(dev, groups);
+}
+
+static inline void device_remove_group(struct device *dev,
+                                      const struct attribute_group *grp)
+{
+       const struct attribute_group *groups[] = { grp, NULL };
+
+       return device_remove_groups(dev, groups);
+}
+
 /*
  * Platform "fixup" functions - allow the platform to have their say
  * about devices and actions that the general device layer doesn't