aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimur Golubovich <timur.golubovich@syntacore.com>2024-06-07 16:42:16 +0300
committerAntonio Borneo <borneo.antonio@gmail.com>2024-06-23 09:32:08 +0000
commit23ba602ca5be4a4c0841a178775bc82b3be0b38f (patch)
tree7a98717c6d8635c73c4f2d36a6daf0703c962e03
parentdde096e03fa4912aa44b2b72cfbdb7676340a3d1 (diff)
downloadriscv-openocd-23ba602ca5be4a4c0841a178775bc82b3be0b38f.zip
riscv-openocd-23ba602ca5be4a4c0841a178775bc82b3be0b38f.tar.gz
riscv-openocd-23ba602ca5be4a4c0841a178775bc82b3be0b38f.tar.bz2
remote_bitbang: fix assertion failure for the cases when connection is abruptly terminated
Changes affect the function remote_bitbang_fill_buf. When read_socket returns 0, socket reached EOF and there is no data to read. But if request was blocking, the caller expected some data. Such situations should be treated as ERROR. Change-Id: I02ed484e61fb776c1625f6e36ab14c85891939b2 Signed-off-by: Timur Golubovich <timur.golubovich@syntacore.com> Reviewed-on: https://review.openocd.org/c/openocd/+/8325 Tested-by: jenkins Reviewed-by: Tomas Vanek <vanekt@fbl.cz> Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
-rw-r--r--src/jtag/drivers/remote_bitbang.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/jtag/drivers/remote_bitbang.c b/src/jtag/drivers/remote_bitbang.c
index 53d2151..edd36f2 100644
--- a/src/jtag/drivers/remote_bitbang.c
+++ b/src/jtag/drivers/remote_bitbang.c
@@ -114,12 +114,18 @@ static int remote_bitbang_fill_buf(enum block_bool block)
contiguous_available_space);
if (first && block == BLOCK)
socket_nonblock(remote_bitbang_fd);
- first = false;
if (count > 0) {
remote_bitbang_recv_buf_end += count;
if (remote_bitbang_recv_buf_end == sizeof(remote_bitbang_recv_buf))
remote_bitbang_recv_buf_end = 0;
} else if (count == 0) {
+ /* When read_socket returns 0, socket reached EOF and there is
+ * no data to read. But if request was blocking, the caller
+ * expected some data. Such situations should be treated as ERROR. */
+ if (first && block == BLOCK) {
+ LOG_ERROR("remote_bitbang: socket closed by remote");
+ return ERROR_FAIL;
+ }
return ERROR_OK;
} else if (count < 0) {
#ifdef _WIN32
@@ -133,6 +139,7 @@ static int remote_bitbang_fill_buf(enum block_bool block)
return ERROR_FAIL;
}
}
+ first = false;
}
return ERROR_OK;