2

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.

user567879
  • 5,139
  • 20
  • 71
  • 105

2 Answers2

3
  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"

Sun
  • 1,505
  • 17
  • 25
0

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

davidh
  • 1
  • 3
  • Could you please elaborate more your answer adding a little more description about the solution you provide? – abarisone Apr 14 '15 at 06:41
  • In order to successfully unregister a device its owner should be the relevant module, owner is determined using owner field. for example: cdev.owner = THIS_MODULE – davidh Dec 15 '15 at 15:33