Use count in open/close device driver

View: New views
1 Messages — Rating Filter:   Alert me  

Use count in open/close device driver

by yong rao :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

We want to have use count in the dev_open(), dev_close() functions. Just like in Linux, in open_dev() function we counld have

  #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
        MOD_INC_USE_COUNT;
  #endif

  #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0)
   try_module_get(THIS_MODULE);    /* increment the usage counter */
 #endif

to increment the use count. In close_dev(), we could decrement the use count.

So, when the device driver is unloaded, we would be able to know if there is any other application processes is still using the driver.

Is there anybody having any clues?

Thanks a lot,

Yong Rao