Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Johan Hovold and committed by
Greg Kroah-Hartman
0bbf0a88 22d66c85

+12 -4
+1 -1
drivers/gnss/serial.c
··· 65 65 66 66 /* write is only buffered synchronously */ 67 67 ret = serdev_device_write(serdev, buf, count, MAX_SCHEDULE_TIMEOUT); 68 - if (ret < 0) 68 + if (ret < 0 || ret < count) 69 69 return ret; 70 70 71 71 /* FIXME: determine if interrupted? */
+1 -1
drivers/gnss/sirf.c
··· 85 85 86 86 /* write is only buffered synchronously */ 87 87 ret = serdev_device_write(serdev, buf, count, MAX_SCHEDULE_TIMEOUT); 88 - if (ret < 0) 88 + if (ret < 0 || ret < count) 89 89 return ret; 90 90 91 91 /* FIXME: determine if interrupted? */
+10 -2
drivers/tty/serdev/core.c
··· 234 234 unsigned long timeout) 235 235 { 236 236 struct serdev_controller *ctrl = serdev->ctrl; 237 + int written = 0; 237 238 int ret; 238 239 239 240 if (!ctrl || !ctrl->ops->write_buf || !serdev->ops->write_wakeup) ··· 251 250 if (ret < 0) 252 251 break; 253 252 253 + written += ret; 254 254 buf += ret; 255 255 count -= ret; 256 - 257 256 } while (count && 258 257 (timeout = wait_for_completion_timeout(&serdev->write_comp, 259 258 timeout))); 260 259 mutex_unlock(&serdev->write_lock); 261 - return ret < 0 ? ret : (count ? -ETIMEDOUT : 0); 260 + 261 + if (ret < 0) 262 + return ret; 263 + 264 + if (timeout == 0 && written == 0) 265 + return -ETIMEDOUT; 266 + 267 + return written; 262 268 } 263 269 EXPORT_SYMBOL_GPL(serdev_device_write); 264 270