内核模块里的一点错误直接导致系统崩溃
来源:互联网 发布:电视直播软件哪个最好 编辑:程序博客网 时间:2024/05/20 07:58
#include <linux/module.h>
#include <linux/init.h>
#include <linux/device.h>
#include <linux/sysfs.h>
MODULE_LICENSE("Dual BSD/GPL");
MODULE_AUTHOR("Anfo");
ssize_t show_def(struct bus_type *bus,char *buf){
buf="what?";
return 0;
}
ssize_t store_def(struct bus_type *bus,const char *buf,size_t count){
return 0;
}
static struct device_attribute dev_attrs[] = {
__ATTR(demo, 0764, show_def, store_def),
__ATTR_NULL,
};
static struct bus_type MyBus={
.name="MyBus",
.dev_attrs=dev_attrs
};
static struct device MyDev={
.init_name="Coffee",
.bus=&MyBus
};
static int __init helloModule_init(void){
printk("hello world!\n");
if(bus_register(&MyBus))
{
printk("bus_register error!\n");
bus_unregister(&MyBus);
}
printk("bus_register success!\n");
if(device_register(&MyDev))
{
printk("device_register error!\n");
device_unregister(&MyDev);
}
printk("device_register success!\n");
return 0;
}
static void __exit helloModule_exit(void){
device_unregister(&MyDev);
printk("device_unregister success!\n");
bus_unregister(&MyBus);
printk("bus_unregister success!\n");
printk("bye world!\n");
}
module_init(helloModule_init);
#include <linux/init.h>
#include <linux/device.h>
#include <linux/sysfs.h>
MODULE_LICENSE("Dual BSD/GPL");
MODULE_AUTHOR("Anfo");
ssize_t show_def(struct bus_type *bus,char *buf){
buf="what?";
return 0;
}
ssize_t store_def(struct bus_type *bus,const char *buf,size_t count){
return 0;
}
static struct device_attribute dev_attrs[] = {
__ATTR(demo, 0764, show_def, store_def),
__ATTR_NULL,
};
static struct bus_type MyBus={
.name="MyBus",
.dev_attrs=dev_attrs
};
static struct device MyDev={
.init_name="Coffee",
.bus=&MyBus
};
static int __init helloModule_init(void){
printk("hello world!\n");
if(bus_register(&MyBus))
{
printk("bus_register error!\n");
bus_unregister(&MyBus);
}
printk("bus_register success!\n");
if(device_register(&MyDev))
{
printk("device_register error!\n");
device_unregister(&MyDev);
}
printk("device_register success!\n");
return 0;
}
static void __exit helloModule_exit(void){
device_unregister(&MyDev);
printk("device_unregister success!\n");
bus_unregister(&MyBus);
printk("bus_unregister success!\n");
printk("bye world!\n");
}
module_init(helloModule_init);
module_exit(helloModule_exit);
上面的程序是有问题的。 在insmod与rmmod之后发现 内核警告必须增加 release函数。。
当然傻逼的我一开始还先注销bus再注销device直接导致系统崩掉,或者再注册device的时候填了bus。。。Oh my god!~
所以要细心一点。。。
0 0
- 内核模块里的一点错误直接导致系统崩溃
- 定位内核模块中导致内核崩溃的代码位置
- 内存MCE错误导致系统崩溃的问题分析
- Project Server 2010 SharePoint_AdminContent 错误导致系统崩溃的解决办法
- Linux 2.6内核发现重大漏洞 可导致系统崩溃
- Android中导致小米系列手机直接崩溃的主要原因。
- 关于Usb直接拔出导致的进程崩溃问题
- printk导致系统崩溃
- 时钟中断导致的内核模块死锁
- 不同模块命名相同导致的程序崩溃问题
- 《Linux kernel panic》内核模块空指针导致系统crash
- 内核模块中错误调用kernel_thread创建内核线程导致模块无法卸载
- tableView的indexPath值错误导致删除崩溃
- crotex系列板子 烧写 zImage 出现类似 NFS配置错误 导致内核崩溃时解决方法
- 百度的招聘系统很容易导致IE崩溃?
- 关于9行代码导致系统崩溃的分析整理
- 关于9行代码导致系统崩溃的分析整理
- 使用cpio命令导致系统几乎崩溃的一次经历
- Object类&泛型数组列表(Java核心卷1-D5)
- RDMA编程1 建立侦听
- 总结&备忘:history记录的时间
- python类库
- swift:运算型属性和存储型属性
- 内核模块里的一点错误直接导致系统崩溃
- 数控软件Grbl使用系列(1):Grbl编译
- 数控软件Grbl使用系列(2):烧写到Arduino UNO
- 《重构与模式》 Swift 版之创建方法 (绝对大牛思想)
- 设计模式-简单工厂模式
- Java中反转字符串我所知的五种方法
- 聊聊Socket、TCP/IP、HTTP、FTP及网络编程
- round15
- 装箱与拆箱(Java核心卷1 - D5)