debugfs question ...

rdq at rdq at
Tue Apr 30 07:45:08 EDT 2019


My I2C sensor driver has a debugfs entry for development purposes.
Everything works fine with the exception of the read operation. When 'cat'
is used, the read operation is called repeatedly and indefinitely. If the
read() is changed to return 0 then, as expected, nothing is displayed. 

The pattern for the implementation is (AFAICT) right out of  the book (shown

What am I missing? Any thoughts much appreciated.



static ssize_t sc031gs_reg_read_file(struct file *file, char __user
				   size_t count, loff_t *ppos)
	char *buf = 0;
	ssize_t total = 0;
	struct sc031gs_dev *sensor = file->private_data;
	if (!sensor)
		return -EINVAL;
	if (*ppos < 0 || !count)
		return -EINVAL;
	buf = kmalloc(count, GFP_KERNEL);
	if (!buf)
		return -ENOMEM;
	total = snprintf(buf,count,"Hello world\n");
	if (total >= 0) {
		if (copy_to_user(user_buf, buf, total)) {
			return -EFAULT;
		*ppos += total;
	return total;

More information about the Kernelnewbies mailing list