]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/commitdiff
serdev: make synchronous write return bytes written
authorJohan Hovold <johan@kernel.org>
Wed, 14 Nov 2018 15:09:02 +0000 (16:09 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 27 Nov 2018 18:44:21 +0000 (19:44 +0100)
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>
drivers/gnss/serial.c
drivers/gnss/sirf.c
drivers/tty/serdev/core.c

index 31e891f00175c635a9ee92c7e0f090eb135fc29b..def64b36d9941aed970259fb39ebc5d84c1c3b15 100644 (file)
@@ -65,7 +65,7 @@ static int gnss_serial_write_raw(struct gnss_device *gdev,
 
        /* write is only buffered synchronously */
        ret = serdev_device_write(serdev, buf, count, MAX_SCHEDULE_TIMEOUT);
-       if (ret < 0)
+       if (ret < 0 || ret < count)
                return ret;
 
        /* FIXME: determine if interrupted? */
index 71d014edd16760d6c37dad72836ed9e13cbfffba..b3a4c0e9194744b5999813c3f8d048b3d6df6c39 100644 (file)
@@ -85,7 +85,7 @@ static int sirf_write_raw(struct gnss_device *gdev, const unsigned char *buf,
 
        /* write is only buffered synchronously */
        ret = serdev_device_write(serdev, buf, count, MAX_SCHEDULE_TIMEOUT);
-       if (ret < 0)
+       if (ret < 0 || ret < count)
                return ret;
 
        /* FIXME: determine if interrupted? */
index c7d637d2bc568257c424699cde3a4679ba7f0751..ee4c4033663342ee90f82f97358484b85245d8f6 100644 (file)
@@ -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);