Skip to content

Commit

Permalink
iiod: fix read_line() for USB
Browse files Browse the repository at this point in the history
Commit aad53e3 ("iiod: Update read_line() to work with UART") made IIOD
able to read its input from UART, but broke USB support at the same
time.

This commit changes the read_line() function so that it works as
expected with both UART and USB transports.

The bug was reported on EZ:
https://ez.analog.com/linux-software-drivers/f/q-a/550894/modifying-libiio-recipe/436242

Signed-off-by: Paul Cercueil <paul@crapouillou.net>
  • Loading branch information
pcercuei committed Nov 3, 2021
1 parent 8402b80 commit 4e57454
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions iiod/ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -1401,6 +1401,9 @@ ssize_t read_line(struct parser_pdata *pdata, char *buf, size_t len)
ssize_t ret;
bool found;

if (pdata->is_usb)
return pdata->readfd(pdata, buf, len);

if (pdata->fd_in_is_socket) {
struct pollfd pfd[2];

Expand Down Expand Up @@ -1445,10 +1448,6 @@ ssize_t read_line(struct parser_pdata *pdata, char *buf, size_t len)

bytes_read += to_trunc;
} while (!found && len);
} else if (pdata->is_usb) {
ret = pdata->readfd(pdata, buf, len);

found = buf[ret - 1] == '\n';
} else {
while (len) {
ret = pdata->readfd(pdata, buf, 1);
Expand All @@ -1467,13 +1466,7 @@ ssize_t read_line(struct parser_pdata *pdata, char *buf, size_t len)
found = !!len;
}

/* No \n found? Just garbage data */
if (!found)
ret = -EIO;
else
ret = bytes_read;

return ret;
return found ? (ssize_t) bytes_read : -EIO;
}

void interpreter(struct iio_context *ctx, int fd_in, int fd_out, bool verbose,
Expand Down

0 comments on commit 4e57454

Please sign in to comment.