]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
tools: env: Handle shorter read calls
authorThibault Ferrante <thibaultferrante@gmail.com>
Tue, 24 Aug 2021 15:29:50 +0000 (17:29 +0200)
committerTom Rini <trini@konsulko.com>
Thu, 2 Sep 2021 15:19:58 +0000 (11:19 -0400)
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 <thibault.ferrante@gmail.com>
tools/env/fw_env.c

index 2a61a5d6f04982708e9c814a10ee9d2774645c10..e39c39e23a175786b905e736b0f7cb97cd07b7ec 100644 (file)
@@ -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;