From: Dongwoo Lee Date: Tue, 1 Sep 2020 10:11:28 +0000 (+0900) Subject: usb: Read until buffer is fully filled X-Git-Tag: submit/tizen/20200902.012141^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4f1157dc54bf221d4e986886dbaec8ebb3a41daa;p=platform%2Fcore%2Fsystem%2Finitrd-flash.git usb: Read until buffer is fully filled Since a single read may not fill the buffer entirely, this makes try to fill the buffer fully with loop. Change-Id: Ic73daf50b060f37c773774108952dbdf30de07e1 Signed-off-by: Dongwoo Lee --- diff --git a/src/usb.c b/src/usb.c index 9705b90..0c36fa0 100644 --- a/src/usb.c +++ b/src/usb.c @@ -198,7 +198,20 @@ static const struct { static ssize_t usb_rx_data(int fd, void *buf, ssize_t len) { - return read(fd, buf, len); + ssize_t r, count = 0; + + do { + r = read(fd, buf + count, len - count); + if (r < 0) { + if (errno == EINTR) + continue; + else + return r; + } + count += r; + } while (count < len); + + return count; } static ssize_t usb_tx_data(int fd, void *buf, ssize_t len)