Recalling what we did in Chapter 3, Working with Char Drivers, when we talked about the read() system call and how we can implement it for our char driver (see chapter_4/chrdev/chrdev.c file on GitHub), we noticed that our implementation was tricky because data was always available:
static ssize_t chrdev_read(struct file *filp,
char __user *buf, size_t count, loff_t *ppos)
{
struct chrdev_device *chrdev = filp->private_data;
int ret;
dev_info(chrdev->dev, "should read %ld bytes (*ppos=%lld)\n",
count, *ppos);
/* Check for end-of-buffer */
if (*ppos + count >= BUF_LEN)
count = BUF_LEN - *ppos;
/* Return data to the user space */
ret = copy_to_user(buf, chrdev->buf + *ppos, count);
if (ret < 0)
return ret;
*ppos += count;
dev_info...