- 论坛徽章:
- 0
|
新手刚学驱动开发,请教下面的代码,
如果输入的参数who为空,我这边打印init failed,但是实际上module已经加载到内核中了,
想问下,如果我想让参数为空时不加载该模块,应该怎么改?直接调用module_exit吗?有什么好的错误处理机制吗?谢谢。- #include <linux/init.h>
- #include <linux/module.h>
- #include <asm/current.h>
- #include <linux/sched.h>
- MODULE_LICENSE("Dual BSD/GPL");
- static char *who;
- static int times;
- module_param(who,charp,S_IRUGO|S_IWUSR);
- module_param(times,int,S_IRUGO|S_IWUSR);
- static int hello_init(void)
- {
- int i=0;
- if(NULL == who)
- {
- printk(KERN_ALERT "Init failed!\n");
- return 0;
- }
- printk(KERN_ALERT "Init success!\n");
- //printk(KERN_INFO "The process is \"%s\" (pid %i)\n", current->comm, current->pid);
- for(i=0;i<times;i++)
- {
- printk(KERN_ALERT "I love %s %d times!\n",who,i);
- }
- return 0;
- }
- static void hello_exit(void)
- {
- printk(KERN_ALERT "Goodbye, cruel world\n");
- }
- module_init(hello_init);
- module_exit(hello_exit);
复制代码 |
|