summaryrefslogtreecommitdiff
path: root/drivers/tty/serdev
diff options
context:
space:
mode:
authorJohan Hovold <johan@kernel.org>2018-11-14 16:09:03 +0100
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2018-11-27 19:44:21 +0100
commit70d188041e6f1f92004f1d5d7ddfd5013273b7a5 (patch)
treea5352d3efbcdbe1bb3b152f204907e308f620b21 /drivers/tty/serdev
parent0bbf0a88fa29de6a043ba40058409c7e550fc8be (diff)
serdev: make synchronous write helper interruptible
Allow the synchronous serdev_device_write() helper to be interrupted. This is useful for cases where I/O is performed on behalf of user space and we don't want to block indefinitely when using flow control. 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.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/drivers/tty/serdev/core.c b/drivers/tty/serdev/core.c
index ee4c40336633..c7006bbb793a 100644
--- a/drivers/tty/serdev/core.c
+++ b/drivers/tty/serdev/core.c
@@ -231,7 +231,7 @@ EXPORT_SYMBOL_GPL(serdev_device_write_buf);
int serdev_device_write(struct serdev_device *serdev,
const unsigned char *buf, size_t count,
- unsigned long timeout)
+ long timeout)
{
struct serdev_controller *ctrl = serdev->ctrl;
int written = 0;
@@ -254,16 +254,24 @@ int serdev_device_write(struct serdev_device *serdev,
written += ret;
buf += ret;
count -= ret;
- } while (count &&
- (timeout = wait_for_completion_timeout(&serdev->write_comp,
- timeout)));
+
+ if (count == 0)
+ break;
+
+ timeout = wait_for_completion_interruptible_timeout(&serdev->write_comp,
+ timeout);
+ } while (timeout > 0);
mutex_unlock(&serdev->write_lock);
if (ret < 0)
return ret;
- if (timeout == 0 && written == 0)
- return -ETIMEDOUT;
+ if (timeout <= 0 && written == 0) {
+ if (timeout == -ERESTARTSYS)
+ return -ERESTARTSYS;
+ else
+ return -ETIMEDOUT;
+ }
return written;
}