Coding: Multiple Devices (Slideshow)¶
Instantiate Multiple Devices¶
Add an
int
type module parameter,ndevices
int ndevices; ... module_param(ndevices, int, 0);
Use that to instantiate
ndevices
instances ofstruct my_device
, and store those in a doubly linked list.In the
open()
implementation, use(major, minor)
(stored in thestruct inode
that gets passed) to find the associatedstruct my_device
in the list. Store a pointer to it in theprivate_data
member of thestruct file*
that is passed toopen()
.Use
private_data
in theioctl()
implementation.