Linux 为什么这个seq_file misc char驱动程序冻结了我的系统?
我正在学习如何编写Linux设备驱动程序,目前我正被一个非常简单的misc char设备示例难倒。我有这个:Linux 为什么这个seq_file misc char驱动程序冻结了我的系统?,linux,char,linux-device-driver,device-driver,Linux,Char,Linux Device Driver,Device Driver,我正在学习如何编写Linux设备驱动程序,目前我正被一个非常简单的misc char设备示例难倒。我有这个: static char *dev_contents = "hello world!"; static int demo_show(struct seq_file *f, void *unused) { seq_puts(f, dev_contents); return 0; } static int demo_open(struct inode *i,
static char *dev_contents = "hello world!";
static int demo_show(struct seq_file *f, void *unused)
{
seq_puts(f, dev_contents);
return 0;
}
static int demo_open(struct inode *i, struct file *f)
{
return single_open(f, demo_show, NULL);
}
const struct file_operations demo_fops = {
.owner = THIS_MODULE,
.open = demo_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
static struct miscdevice demo_dev = {
MISC_DYNAMIC_MINOR,
"demo",
&demo_fops
};
int __init init_module(void)
{
int res = 0;
res = misc_register(&demo_dev);
if (res)
pr_err("Error registering demo misc device.\n");
return res;
}
void __exit cleanup_module(void)
{
misc_deregister(&demo_dev);
}
它确实如预期的那样显示在/dev中,我可以对设备文件进行cat。返回字符串,但在返回最后一个字符后,整个系统将冻结
我把它和其他做同样事情的例子进行了比较,我很难看出我做错了什么。有人愿意为我指出正确的方向吗
谢谢 你能用字符串末尾的换行符试试吗?正如Peter所说,试着用seq_putcf,“\n”;我只是尝试了一下,虽然我在查看文件时确实看到了新行,但之后系统仍然冻结。无论如何谢谢你!