Commit 2ba4746b authored by Kent Gibson's avatar Kent Gibson Committed by Bartosz Golaszewski

gpiolib: cdev: Cleanup kfifo_out() error handling

The handling of kfifo_out() errors in read functions obscures any error.
The error condition should never occur but, while a ret is set to -EIO, it
is subsequently ignored and the read functions instead return the number
of bytes copied to that point, potentially masking the fact that any error
occurred.

Log a warning and return -EIO in the case of a kfifo_out() error to make
it clear something very odd is going on here.
Signed-off-by: default avatarKent Gibson <warthog618@gmail.com>
Link: https://lore.kernel.org/r/20240529131953.195777-4-warthog618@gmail.comSigned-off-by: default avatarBartosz Golaszewski <bartosz.golaszewski@linaro.org>
parent 4ce5ca65
...@@ -1642,16 +1642,15 @@ static ssize_t linereq_read(struct file *file, char __user *buf, ...@@ -1642,16 +1642,15 @@ static ssize_t linereq_read(struct file *file, char __user *buf,
return ret; return ret;
} }
ret = kfifo_out(&lr->events, &le, 1); if (kfifo_out(&lr->events, &le, 1) != 1) {
}
if (ret != 1) {
/* /*
* This should never happen - we were holding the * This should never happen - we hold the
* lock from the moment we learned the fifo is no * lock from the moment we learned the fifo
* longer empty until now. * is no longer empty until now.
*/ */
ret = -EIO; WARN(1, "failed to read from non-empty kfifo");
break; return -EIO;
}
} }
if (copy_to_user(buf + bytes_read, &le, sizeof(le))) if (copy_to_user(buf + bytes_read, &le, sizeof(le)))
...@@ -1995,16 +1994,15 @@ static ssize_t lineevent_read(struct file *file, char __user *buf, ...@@ -1995,16 +1994,15 @@ static ssize_t lineevent_read(struct file *file, char __user *buf,
return ret; return ret;
} }
ret = kfifo_out(&le->events, &ge, 1); if (kfifo_out(&le->events, &ge, 1) != 1) {
}
if (ret != 1) {
/* /*
* This should never happen - we were holding the lock * This should never happen - we hold the
* from the moment we learned the fifo is no longer * lock from the moment we learned the fifo
* empty until now. * is no longer empty until now.
*/ */
ret = -EIO; WARN(1, "failed to read from non-empty kfifo");
break; return -EIO;
}
} }
if (copy_to_user(buf + bytes_read, &ge, ge_size)) if (copy_to_user(buf + bytes_read, &ge, ge_size))
...@@ -2707,12 +2705,15 @@ static ssize_t lineinfo_watch_read(struct file *file, char __user *buf, ...@@ -2707,12 +2705,15 @@ static ssize_t lineinfo_watch_read(struct file *file, char __user *buf,
if (count < event_size) if (count < event_size)
return -EINVAL; return -EINVAL;
#endif #endif
ret = kfifo_out(&cdev->events, &event, 1); if (kfifo_out(&cdev->events, &event, 1) != 1) {
/*
* This should never happen - we hold the
* lock from the moment we learned the fifo
* is no longer empty until now.
*/
WARN(1, "failed to read from non-empty kfifo");
return -EIO;
} }
if (ret != 1) {
ret = -EIO;
break;
/* We should never get here. See lineevent_read(). */
} }
#ifdef CONFIG_GPIO_CDEV_V1 #ifdef CONFIG_GPIO_CDEV_V1
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment