Coding: Multiple Devices (Slideshow)

Instantiate Multiple Devices

  1. Add an int type module parameter, ndevices

    int ndevices;
    ...
    module_param(ndevices, int, 0);
    

    Use that to instantiate ndevices instances of struct my_device, and store those in a doubly linked list.

  2. In the open() implementation, use (major, minor) (stored in the struct inode that gets passed) to find the associated struct my_device in the list. Store a pointer to it in the private_data member of the struct file* that is passed to open().

  3. Use private_data in the ioctl() implementation.