Strategies for accessing driver data from file operations!?

Greg KH greg at kroah.com
Wed Aug 13 17:40:54 EDT 2014


On Wed, Aug 13, 2014 at 09:46:51AM -0300, Daniel Hilst Selli wrote:
> One last question, supposing I need to create multiple /dev nodes, do I need to
> allocate one struct cdev for each major:minor pair (cdev_alloc(), cdev_init(), cdev_add())?

No, you can allocate multiple minor numbers with a single set of cdev
calls.  But watch out, you also need to create a 'struct device' for
_each_ minor number you are actually using if you want the device nodes
to show up in /dev automatically.

Yeah, it's a pain, sorry, but this way you can allocate a whole range of
major:minor pairs but don't actually expose them to userspace until you
really need them (i.e. the hardware is present in the system.)  This
keeps /dev looking like only the devices that are present in the system,
not the "old" way of "every possible device that could ever be possibly
present".

Hope this helps,

greg k-h



More information about the Kernelnewbies mailing list