Commit 0bbf0a88 authored by Johan Hovold's avatar Johan Hovold Committed by Greg Kroah-Hartman

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: default avatarJohan Hovold <johan@kernel.org>
Reviewed-by: default avatarRob Herring <robh@kernel.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 22d66c85
...@@ -65,7 +65,7 @@ static int gnss_serial_write_raw(struct gnss_device *gdev, ...@@ -65,7 +65,7 @@ static int gnss_serial_write_raw(struct gnss_device *gdev,
/* write is only buffered synchronously */ /* write is only buffered synchronously */
ret = serdev_device_write(serdev, buf, count, MAX_SCHEDULE_TIMEOUT); ret = serdev_device_write(serdev, buf, count, MAX_SCHEDULE_TIMEOUT);
if (ret < 0) if (ret < 0 || ret < count)
return ret; return ret;
/* FIXME: determine if interrupted? */ /* FIXME: determine if interrupted? */
......
...@@ -85,7 +85,7 @@ static int sirf_write_raw(struct gnss_device *gdev, const unsigned char *buf, ...@@ -85,7 +85,7 @@ static int sirf_write_raw(struct gnss_device *gdev, const unsigned char *buf,
/* write is only buffered synchronously */ /* write is only buffered synchronously */
ret = serdev_device_write(serdev, buf, count, MAX_SCHEDULE_TIMEOUT); ret = serdev_device_write(serdev, buf, count, MAX_SCHEDULE_TIMEOUT);
if (ret < 0) if (ret < 0 || ret < count)
return ret; return ret;
/* FIXME: determine if interrupted? */ /* FIXME: determine if interrupted? */
......
...@@ -234,6 +234,7 @@ int serdev_device_write(struct serdev_device *serdev, ...@@ -234,6 +234,7 @@ int serdev_device_write(struct serdev_device *serdev,
unsigned long timeout) unsigned long timeout)
{ {
struct serdev_controller *ctrl = serdev->ctrl; struct serdev_controller *ctrl = serdev->ctrl;
int written = 0;
int ret; int ret;
if (!ctrl || !ctrl->ops->write_buf || !serdev->ops->write_wakeup) if (!ctrl || !ctrl->ops->write_buf || !serdev->ops->write_wakeup)
...@@ -250,14 +251,21 @@ int serdev_device_write(struct serdev_device *serdev, ...@@ -250,14 +251,21 @@ int serdev_device_write(struct serdev_device *serdev,
if (ret < 0) if (ret < 0)
break; break;
written += ret;
buf += ret; buf += ret;
count -= ret; count -= ret;
} while (count && } while (count &&
(timeout = wait_for_completion_timeout(&serdev->write_comp, (timeout = wait_for_completion_timeout(&serdev->write_comp,
timeout))); timeout)));
mutex_unlock(&serdev->write_lock); 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); EXPORT_SYMBOL_GPL(serdev_device_write);
......
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