From mboxrd@z Thu Jan 1 00:00:00 1970 From: greg@kroah.com (Greg KH) Date: Thu, 14 Aug 2014 05:40:54 +0800 Subject: Strategies for accessing driver data from file operations!? In-Reply-To: <53EB5E3B.20508@gmail.com> References: <53EA1AE8.1030509@gmail.com> <20140812195328.GA20273@kroah.com> <53EB5E3B.20508@gmail.com> Message-ID: <20140813214054.GA7214@kroah.com> To: kernelnewbies@lists.kernelnewbies.org List-Id: kernelnewbies.lists.kernelnewbies.org 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