From 4e574547cb935d131fc60c2acdaec9ddb500defc Mon Sep 17 00:00:00 2001 From: Paul Cercueil Date: Thu, 21 Oct 2021 14:57:36 +0100 Subject: [PATCH] iiod: fix read_line() for USB 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 --- iiod/ops.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/iiod/ops.c b/iiod/ops.c index d1c1cdae5..4184872f3 100644 --- a/iiod/ops.c +++ b/iiod/ops.c @@ -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]; @@ -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); @@ -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,