How to read / write Character device in Linux kernel module

I am writing a character device driver myself in LKM, which is simple:

dev_open(struct inode *inode, struct file *filp);
dev_read (struct file *filp, char __user *buf, size_t count, loff_t *f_pos)
dev_write(struct file *filp, const char __user *buf, size_t count, loff_t *f_pos)
dev_release(struct inode *inode, struct file *filp)

Then in my kernel module I also want to write characters to the device, and writing will actually call my function:

dev_write(struct file *filp, const char __user *buf, size_t count, loff_t *f_pos)

I found a similar link here in SE, but that way it won’t call my dev_write()write function , but a little deeper than vfs_write()that, right?

+3
source share
1 answer

Do not try to call dev_write()from your module. You need a separate way for your module to write to the device if this is really what you want to do. You do not have a valid buffer filpor user memory when doing internal writing.

, dev_write() filp , , . .

. , , , , .

+1

All Articles