BACKPORT: 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>
(cherry picked from commit 0bbf0a88fa29de6a043ba40058409c7e550fc8be)
[adelva: dropped changes to driver that was not backported]
Bug: 146062677
Change-Id: Ib9fb6041808e59f57d78fa23088bf37a8a8d4518
Signed-off-by: Alistair Delva <adelva@google.com>
This commit is contained in:
Johan Hovold
2018-11-14 16:09:02 +01:00
committed by Alistair Delva
parent 4818e17215
commit 2982283bb0
2 changed files with 11 additions and 3 deletions

View 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? */

View File

@@ -153,6 +153,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 ||
@@ -167,14 +168,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);