tiny4412 rmmod hello 模块出现的错误

出现这些错误..多半是代码问题
rmmod时候出现Segmentation fault错误
rmmod: remove 'led': Device or resource busy
rmmod: chdir(/lib/modules): No such file or directory
/lib/modules # 
/lib/modules # 
/lib/modules # ls
3.5.0-FriendlyARM
/lib/modules # 
/lib/modules # 



rmmod: remove 'led': Device or resource busy  


rmmod: remove 'led': Device or resource busy  






#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <asm/uaccess.h>
#include <asm/irq.h>
#include <asm/io.h>
#include <linux/device.h>




static struct class *firstdrv_class;
static struct class_device *firstdrv_class_dev;






static int first_drv_open(struct inode *inode, struct file *file)
{
printk("first_drv_open\n");
return 0;
}


static ssize_t first_drv_write(struct file *file, const char __user *buf, size_t count, loff_t * ppos)
{


printk("first_drv_write\n");

return 0;
}


static struct file_operations first_drv_fops = {
    .owner  =   THIS_MODULE,    /* 杩欐槸涓€涓畯锛屾帹鍚戠紪璇戞ā鍧楁椂鑷姩鍒涘缓鐨刜_this_module鍙橀噺 */
    .open   =   first_drv_open,     
.write = first_drv_write,   
};




int major;
static int first_drv_init(void)
{
major = register_chrdev(0, "hello", &first_drv_fops); // 娉ㄥ唽, 鍛婅瘔鍐呮牳


firstdrv_class = class_create(THIS_MODULE, "hello");

firstdrv_class_dev = device_create(firstdrv_class, NULL, MKDEV(major, 0), NULL, "hello"); /* /dev/xyz */
printk("first_drv_init\n");
return 0;
}


static void first_drv_exit(void)
{
printk("first_drv_exit\n");
unregister_chrdev(major, "hello"); // 鍗歌浇
printk("unregister_chrdev\n");
/* class_unregister(firstdrv_class_dev);
// class_destroy(firstdrv_class);
printk("class_unregister\n");
device_destroy(firstdrv_class, major);  
printk("device_destroy\n");
    class_destroy(firstdrv_class); */
printk("class_destroy\n");
}


module_init(first_drv_init);
module_exit(first_drv_exit);
MODULE_LICENSE("GPL");
模块卸载的地方注释就可以 ,不知道为啥

                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值