summaryrefslogtreecommitdiff
path: root/drivers/tty/serdev
diff options
context:
space:
mode:
authorJohan Hovold <johan@kernel.org>2018-11-14 18:09:02 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2018-11-27 21:44:21 +0300
commit0bbf0a88fa29de6a043ba40058409c7e550fc8be (patch)
treeba3ee078527db443cd492fa12f5c4d6862269e47 /drivers/tty/serdev
parent22d66c85fde3b1ca27ab596357e8e2505af7e388 (diff)
downloadlinux-0bbf0a88fa29de6a043ba40058409c7e550fc8be.tar.xz
serdev: make synchronous write return bytes written
Make the synchronous serdev_device_write() helper behave analogous to the asynchronous serdev_device_write_buf() by returning the number of bytes written (or rather buffered) also on timeout. This will allow drivers to distinguish the case where data was partially written from the case where no data was written. Also update the only two users that checked the return value. Signed-off-by: Johan Hovold <johan@kernel.org> Reviewed-by: Rob Herring <robh@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/tty/serdev')
-rw-r--r--drivers/tty/serdev/core.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/drivers/tty/serdev/core.c b/drivers/tty/serdev/core.c
index c7d637d2bc56..ee4c40336633 100644
--- a/drivers/tty/serdev/core.c
+++ b/drivers/tty/serdev/core.c
@@ -234,6 +234,7 @@ int serdev_device_write(struct serdev_device *serdev,
unsigned long timeout)
{
struct serdev_controller *ctrl = serdev->ctrl;
+ int written = 0;
int ret;
if (!ctrl || !ctrl->ops->write_buf || !serdev->ops->write_wakeup)
@@ -250,14 +251,21 @@ int serdev_device_write(struct serdev_device *serdev,
if (ret < 0)
break;
+ written += ret;
buf += ret;
count -= ret;
-
} while (count &&
(timeout = wait_for_completion_timeout(&serdev->write_comp,
timeout)));
mutex_unlock(&serdev->write_lock);
- return ret < 0 ? ret : (count ? -ETIMEDOUT : 0);
+
+ if (ret < 0)
+ return ret;
+
+ if (timeout == 0 && written == 0)
+ return -ETIMEDOUT;
+
+ return written;
}
EXPORT_SYMBOL_GPL(serdev_device_write);