Question

I am writing a simple charcter driver scull based on ldd. For my sample character driver, evethough module is unloaded device with major number exist in /proc/devices. How to remove that?

My module exit function has

void scull_exit(void)
{
    unregister_chrdev(Major, "scull1");
    cdev_del(my_cdev);  
    printk(KERN_ALERT "Good Bye\n");

}

I could see the old device with its major number when I load new module after unloading the same.

Was it helpful?

Solution

  1. cdev_del takes a pointer, ensure that your my_cdev is a pointer.

    void cdev_del(struct cdev *);

  2. It is cdev_del, first and unregister_chrdev later, it seems you have done it the other way, use cdev_del first and then unregister_chrdev_region

  3. You have mixed up old notation of unregister_chrdev and new notation of cdev_del.

    • either unregister_chrdev should be used when you use register_chrdev for registering

      OR

    • "cdev_init/cdev_add after register_chrdev_region" should be used in conjunction with "cdev_del before unregister_chrdev_region"

OTHER TIPS

struct cdev has an owner field that should be set to THIS_MODULE. Make sure it is set

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top