c - Linux: My char driver creates a node in sysfs but can not clean it after reloading -


i writting simple char driver. create node in sysfs device_create() , created properly. node in /dev automatically well. problem class_distroy() , device_destroy() don't clean /sys/devices/virtual/tdmcdev/tdm/ directory crated on init. init , close code below

    ...     /* node in /dev/  */     tdm->dev_major = 0; //for dynamic major              tdm_dev = mkdev(tdm->dev_major, 0);     tdm->dev_major = major(tdm_dev);     err = alloc_chrdev_region(&tdm_dev, 0, 1, "tdm"); //one node read/write data frame     if (err) {             printk("can't alloc minor /dev/tdm\n");             return -enodev;     }      cdev_init(&(tdm->cdev), &tdm_dev_fops);     tdm->cdev.owner = this_module;     err = cdev_add(&(tdm->cdev), tdm_dev, 1);     if (err) {             printk("cdev_add() failed /dev/tdm\n");             unregister_chrdev_region(tdm_dev, 1);             return -enodev;     }      /* node /sys/devices/virtual/tdmcdev/tdm/  */     tdm->dev_class = class_create(this_module, "tdmcdev");     if (is_err(device_create(tdm->dev_class, null, tdm_dev, null, "tdm"))) {             printk("device_create() failed tdm device\n");             class_destroy(tdm->dev_class);             cdev_del(&(tdm->cdev));             unregister_chrdev_region(tdm_dev, 1);             return -enomem;     }     ...  

my close code

    dev_t tdm_dev = mkdev(tdm->dev_major, 0);      device_destroy(tdm->dev_class, tdm_dev);     class_destroy(tdm->dev_class);      cdev_del(&(tdm->cdev));     unregister_chrdev_region(tdm_dev, 1);     ... 

it on linux openwrt 3.10.49 on mips cpu. seeing not in order?

thanks. dimitar

it appeared stupid one. using dynamic major start value 0. have move tdm->dev_major = major(tdm_dev) after alloc_chrdev_region() of course proper major can clean afterwords

thanks dimitar


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -