summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorPali Rohár <pali@kernel.org>2021-09-25 00:06:43 +0300
committerStefan Roese <sr@denx.de>2021-10-01 12:07:13 +0300
commit00a1deed1c8d5005499ac7a3c1c337de27102eee (patch)
tree51d2b215d7f65738a4f4055b38d98086099e0807 /tools
parenta050a862a76de1203e59f4c8793affdc5a0d34db (diff)
downloadu-boot-00a1deed1c8d5005499ac7a3c1c337de27102eee.tar.xz
tools: kwboot: Fix kwboot_xm_sendblock() function when kwboot_tty_recv() fails
When kwboot_tty_recv() fails or times out, it does not set the `c` variable to NAK. The variable is then compared, while it holds either an undefined value or a value from previous iteration. Set `c` to NAK so that the other side will try to resend current block, and remove the now unnecessary break. In other failure cases return immediately. Signed-off-by: Pali Rohár <pali@kernel.org> Reviewed-by: Marek Behún <marek.behun@nic.cz> Reviewed-by: Stefan Roese <sr@denx.de>
Diffstat (limited to 'tools')
-rw-r--r--tools/kwboot.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/tools/kwboot.c b/tools/kwboot.c
index 454339db14..b9a402ca91 100644
--- a/tools/kwboot.c
+++ b/tools/kwboot.c
@@ -380,12 +380,15 @@ kwboot_xm_sendblock(int fd, struct kwboot_block *block)
do {
rc = kwboot_tty_send(fd, block, sizeof(*block));
if (rc)
- break;
+ return rc;
do {
rc = kwboot_tty_recv(fd, &c, 1, blk_rsp_timeo);
- if (rc)
- break;
+ if (rc) {
+ if (errno != ETIMEDOUT)
+ return rc;
+ c = NAK;
+ }
if (c != ACK && c != NAK && c != CAN)
printf("%c", c);