From: Thibault Ferrante Date: Tue, 24 Aug 2021 15:29:50 +0000 (+0200) Subject: tools: env: Handle shorter read calls X-Git-Tag: v2022.01~102^2~27^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6628813f9d400c49da4926f01833063a30151cdb;p=platform%2Fkernel%2Fu-boot.git tools: env: Handle shorter read calls On some cases, the actual number of bytes read can be shorter than what was requested. This can be handled gracefully by taking this difference into account instead of exiting. Signed-off-by: Thibault Ferrante --- diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c index 2a61a5d..e39c39e 100644 --- a/tools/env/fw_env.c +++ b/tools/env/fw_env.c @@ -951,21 +951,23 @@ static int flash_read_buf(int dev, int fd, void *buf, size_t count, DEVNAME(dev), strerror(errno)); return -1; } - if (rc != readlen) { - fprintf(stderr, - "Read error on %s: Attempted to read %zd bytes but got %d\n", - DEVNAME(dev), readlen, rc); - return -1; - } #ifdef DEBUG fprintf(stderr, "Read 0x%x bytes at 0x%llx on %s\n", rc, (unsigned long long)blockstart + block_seek, DEVNAME(dev)); #endif - processed += readlen; - readlen = min(blocklen, count - processed); - block_seek = 0; - blockstart += blocklen; + processed += rc; + if (rc != readlen) { + fprintf(stderr, + "Warning on %s: Attempted to read %zd bytes but got %d\n", + DEVNAME(dev), readlen, rc); + readlen -= rc; + block_seek += rc; + } else { + blockstart += blocklen; + readlen = min(blocklen, count - processed); + block_seek = 0; + } } return processed;