miscdevice and default attributes

David Bakin davidbak at gmail.com
Sun Jun 7 23:13:37 EDT 2015


Where do I set the default attributes for a device created with
misc_register()?

In kernel 3.19 struct miscdevice looks like this:

struct miscdevice  {
 int minor;
 const char *name;
 const struct file_operations *fops;
 struct list_head list;
 struct device *parent;
 struct device *this_device;
 const char *nodename;
 umode_t mode;
};

No attributes there that I can see. I know that after calling
misc_register() the this_device field is filled in and I can use
device_create_file() to make attributes with it.  But it is too late to use
this_device's own default attributes, right?  The device has already been
created.

The reason this is puzzling me is because Greg KH, here
<http://kroah.com/log/blog/2013/06/26/how-to-create-a-sysfs-file-correctly/>
(in 2013), explains that the right time to set up attributes is when the
device is created, using the device's, the driver's, the class's, or the
bus's default attributes field - if you wait until later you run the risk
of a losing a race against udev.

But maybe I'm just confused (I'm rather new here, after all), because here
<http://lists.kernelnewbies.org/pipermail/kernelnewbies/2015-April/013894.html>
Greg explains that all udev is doing is setting up permissions and
symlinks, so maybe I don't care about the potential race (if I don't need
different permissions).

I guess another way to ask this question is to ask:  What are the
circumstances when I should be concerned about this race between the driver
and udev?  In the case of a new misc device for my own private purposes ...
it seems unlikely I'd want to use udev to rename it in any particular way
or modify permissions separately from the umode I give the kernel, so ...
nothing to worry about, right?

Thanks! -- David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20150607/cf4465be/attachment.html 


More information about the Kernelnewbies mailing list