对于家庭作业,我写了一个字符设备驱动程序.它似乎工作正常.我可以读写它.问题是,当我读取设备时,它无休止地循环,反复打印出消息缓冲区的内容.
这似乎应该是相当直接的.只需使用copy_to_user(),但事实证明这是非常有问题的.
无论如何,这是代码.我认为问题出在gdev_read()函数中.printk用作调试和谈话点,因为我必须在课堂上展示项目.
/*
* Implement a generic character pseudo-device driver
*/
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/cdev.h>
#include <linux/types.h>
#include <linux/vmalloc.h>
#include <asm/uaccess.h>
/* you need these, or the kernel will be tainted */
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("A simple sample character device driver");
/*
* function prototypes
*/
int init_module(void);
void cleanup_module(void);
static ssize_t gdev_read(struct file *, char *, size_t, loff_t *);
static ssize_t gdev_write(struct file *, const char *, size_t, loff_t *);
static int gdev_open(struct inode *, struct …Run Code Online (Sandbox Code Playgroud)