Coding: Multiple Devices (Slideshow)#
Instantiate Multiple Devices#
Add an
inttype module parameter,ndevicesint ndevices; ... module_param(ndevices, int, 0);
Use that to instantiate
ndevicesinstances ofstruct my_device, and store those in a doubly linked list.In the
open()implementation, use(major, minor)(stored in thestruct inodethat gets passed) to find the associatedstruct my_devicein the list. Store a pointer to it in theprivate_datamember of thestruct file*that is passed toopen().Use
private_datain theioctl()implementation.