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>
This commit is contained in:
Johan Hovold 2018-11-14 16:09:02 +01:00 committed by Greg Kroah-Hartman
parent 22d66c85fd
commit 0bbf0a88fa
3 changed files with 12 additions and 4 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

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

View 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);