LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Unregistering a character Device driver from /proc/devices (https://www.linuxquestions.org/questions/linux-newbie-8/unregistering-a-character-device-driver-from-proc-devices-4175412639/)

krishnateja 06-21-2012 05:42 AM

Unregistering a character Device driver from /proc/devices
 
Hi all, i'm reading linux device drivers,
and i'm creating a character driver.

I alloc a chrdev region
with
alloc_chrdev_region(&dev,minor_number,number_of_devs);

how can i deallocate it ? I tried with
unregister_chrdev_region but it does work only for
statically allocated devices.

i want to deallocate it so that only a single major number is assigned to my driver and

cat /dev/devices | grep $dev_name
returns no more than 1 line.

ppoulsen 06-21-2012 10:22 AM

This is the format for alloc_chrdev_region:
Code:

int alloc_chrdev_region(dev_t *dev, unsigned baseminor, unsigned count, const char *name)
It will store the Major/Minor number information at the address specified by dev. This ought to be a static variable, as it will be used again to unregister.
baseminor is the starting minor number (probably 0).
count is the number of potential character devices (minor numbers will be baseminor through count - 1)
name is the name of the driver that will appear in /proc/devices (not /dev/devices)

NOTE: You should make sure the return value is 0 before moving on in the driver and exit if it isn't.

To unregister, use unregister_chrdev_region:
Code:

void unregister_chrdev_region(dev_t from, unsigned count)
from should be the value stored by alloc_chrdev_region (the actual value this time, not a pointer).
count is the same count from alloc_chrdev_region.

NOTE: Regardless of what you specify for count, using:
Code:

cat /proc/devices | grep $dev_name
should always return one line (as long $dev_name isn't a substring of some other device's name).


All times are GMT -5. The time now is 11:41 PM.