Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

misc: Add attribute groups

Add groups field to struct miscdevice for passing the attribute groups
at device creation. In this way, the driver can avoid the manual call
of device_create_file() after the device registration, which is
basically a racy operation, in addition to the reduction of manual
device_remove_file() calls.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Takashi Iwai and committed by
Greg Kroah-Hartman
bd735995 2f976319

+5 -2
+3 -2
drivers/char/misc.c
··· 207 207 208 208 dev = MKDEV(MISC_MAJOR, misc->minor); 209 209 210 - misc->this_device = device_create(misc_class, misc->parent, dev, 211 - misc, "%s", misc->name); 210 + misc->this_device = 211 + device_create_with_groups(misc_class, misc->parent, dev, 212 + misc, misc->groups, "%s", misc->name); 212 213 if (IS_ERR(misc->this_device)) { 213 214 int i = DYNAMIC_MINORS - misc->minor - 1; 214 215 if (i < DYNAMIC_MINORS && i >= 0)
+2
include/linux/miscdevice.h
··· 52 52 #define MISC_DYNAMIC_MINOR 255 53 53 54 54 struct device; 55 + struct attribute_group; 55 56 56 57 struct miscdevice { 57 58 int minor; ··· 61 60 struct list_head list; 62 61 struct device *parent; 63 62 struct device *this_device; 63 + const struct attribute_group **groups; 64 64 const char *nodename; 65 65 umode_t mode; 66 66 };