mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-12-27 18:25:05 +00:00
ec_uartd: bugfix for buffer pointer on partial write to FD.
Previously I neglected to increment the buffer pointer which would allow double writing of same data and exclude tail if write didn't complete in one call. Also fixing bug with EAGAIN/EWOULDBLOCK to retry in those cases. Previously we'd just have just failed for those errno values. Signed-off-by: Todd Broch <tbroch@chromium.org> BRANCH=none BUG=chromium:371147 TEST=still compiles Change-Id: I30dbe56b2a4c735c487464349786a9db430130a8 Reviewed-on: https://chromium-review.googlesource.com/199052 Reviewed-by: Vincent Palatin <vpalatin@chromium.org> Commit-Queue: Todd Broch <tbroch@chromium.org> Tested-by: Todd Broch <tbroch@chromium.org>
This commit is contained in:
committed by
chrome-internal-fetch
parent
b5f3455a98
commit
479aa8b1bc
@@ -18,6 +18,7 @@
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#pragma GCC diagnostic ignored "-Wstrict-prototypes"
|
||||
#include <ftdi.h>
|
||||
@@ -128,8 +129,19 @@ int main(int argc, char **argv)
|
||||
bytes = ftdi_read_data(&fcontext, buf, sizeof(buf));
|
||||
if (bytes > 0) {
|
||||
int bytes_remaining = bytes;
|
||||
while ((bytes = write(fd, buf, bytes_remaining)) > 0)
|
||||
char *buf_ptr = buf;
|
||||
|
||||
retry_write:
|
||||
while (bytes_remaining &&
|
||||
((bytes = write(fd, buf_ptr,
|
||||
bytes_remaining)) > 0)) {
|
||||
buf_ptr += bytes;
|
||||
bytes_remaining -= bytes;
|
||||
}
|
||||
|
||||
if ((bytes == -1) &&
|
||||
((errno == EAGAIN) || (errno == EWOULDBLOCK)))
|
||||
goto retry_write;
|
||||
|
||||
if (bytes == -1)
|
||||
perror("writing ftdi data to pty");
|
||||
|
||||
Reference in New Issue
Block a user