I am working on simple character device driver. I have implemented read and write functions in the module, the problem is when I try to read the device file using cat /dev/devicefile it is going into infinite loop i.e. reading the same data repeatedly. Can someone suggest me any solution to this problem? Below is my driver code.
#include #include #include #include #include MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("character device driver"); MODULE_AUTHOR("Srinivas"); static char msg[100]={0}; static int t; static int dev_open(struct inode *, struct file *); static int dev_rls(struct inode *, struct file *); static ssize_t dev_read(struct file *, char *,size_t, loff_t *); static ssize_t dev_write(struct file *, const char *, size_t,loff_t *); static struct file_operations fops = { .read = dev_read, .open = dev_open, .write = dev_write, .release = dev_rls, }; static int himodule( void ) { t = 0; t = register_chrdev(0, "chardevdriver", &fops); if (t 0) { msg[count] = buff[count]; len--; count++; } return count; } static int dev_rls(struct inode *inod,struct file *fil) { printk(KERN_ALERT"device closed\n"); return 0; } module_init(himodule); module_exit(byemodule);