diff options
Diffstat (limited to 'meta-oe/recipes-test/linux-serial-test/files/0002-linux-serial-test.c-fix-potential-hang-in-while-loop.patch')
| -rw-r--r-- | meta-oe/recipes-test/linux-serial-test/files/0002-linux-serial-test.c-fix-potential-hang-in-while-loop.patch | 60 |
1 files changed, 0 insertions, 60 deletions
diff --git a/meta-oe/recipes-test/linux-serial-test/files/0002-linux-serial-test.c-fix-potential-hang-in-while-loop.patch b/meta-oe/recipes-test/linux-serial-test/files/0002-linux-serial-test.c-fix-potential-hang-in-while-loop.patch deleted file mode 100644 index f0b7f65a60..0000000000 --- a/meta-oe/recipes-test/linux-serial-test/files/0002-linux-serial-test.c-fix-potential-hang-in-while-loop.patch +++ /dev/null | |||
| @@ -1,60 +0,0 @@ | |||
| 1 | From 9cf6c1d80c2f159dbb69967fbe934bf6de73c9e8 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Max Krummenacher <max.krummenacher@toradex.com> | ||
| 3 | Date: Tue, 5 Aug 2025 09:35:06 +0200 | ||
| 4 | Subject: [PATCH 2/2] linux-serial-test.c: fix potential hang in while loop | ||
| 5 | |||
| 6 | process_read_data() assumes that we can always wait for reception | ||
| 7 | of 1024 chars. However that is not true if one sets the number of | ||
| 8 | chars with the '-w' cmdline parameter or chars are lost. Maybe there | ||
| 9 | are other reasons. | ||
| 10 | |||
| 11 | Replace the magic number of 1024 by calculating the number of expected | ||
| 12 | chars from _cl_tx_bytes. | ||
| 13 | |||
| 14 | Brake a possible infinite while loop by adding a timeout to the loop | ||
| 15 | calculated from the expected chars times chartime. | ||
| 16 | |||
| 17 | Upstream-Status: Submitted [https://github.com/cbrake/linux-serial-test/pull/61/] | ||
| 18 | Fixes: 7fd1057f8a95 ("Add loop to read all data in rcv buffer") | ||
| 19 | Signed-off-by: Max Krummenacher <max.krummenacher@toradex.com> | ||
| 20 | Signed-off-by: Emanuele Ghidoli <emanuele.ghidoli@toradex.com> | ||
| 21 | --- | ||
| 22 | linux-serial-test.c | 14 ++++++++++++-- | ||
| 23 | 1 file changed, 12 insertions(+), 2 deletions(-) | ||
| 24 | |||
| 25 | diff --git a/linux-serial-test.c b/linux-serial-test.c | ||
| 26 | index c2c8882d601b..294f53882570 100644 | ||
| 27 | --- a/linux-serial-test.c | ||
| 28 | +++ b/linux-serial-test.c | ||
| 29 | @@ -543,8 +543,13 @@ static unsigned char next_count_value(unsigned char c) | ||
| 30 | static void process_read_data(void) | ||
| 31 | { | ||
| 32 | unsigned char rb[1024]; | ||
| 33 | + int loopcounter = 0; | ||
| 34 | int actual_read_count = 0; | ||
| 35 | - while (actual_read_count < 1024) { | ||
| 36 | + int expected_read_count = _cl_tx_bytes == 0 ? 1024 : _cl_tx_bytes; | ||
| 37 | + /* time for one char at current baudrate in us */ | ||
| 38 | + int chartime = 1000000 * (8 + _cl_parity + 1 + _cl_2_stop_bit) / _cl_baud; | ||
| 39 | + | ||
| 40 | + while (actual_read_count < expected_read_count) { | ||
| 41 | int c = read(_fd, &rb, sizeof(rb)); | ||
| 42 | if (c > 0) { | ||
| 43 | if (_cl_rx_dump) { | ||
| 44 | @@ -577,7 +582,12 @@ static void process_read_data(void) | ||
| 45 | if (errno != EAGAIN) { | ||
| 46 | perror("read failed"); | ||
| 47 | } | ||
| 48 | - continue; // Retry the read | ||
| 49 | + | ||
| 50 | + if (loopcounter++ < expected_read_count) { | ||
| 51 | + usleep(chartime); | ||
| 52 | + continue; // Retry the read | ||
| 53 | + } | ||
| 54 | + break; | ||
| 55 | } else { | ||
| 56 | break; | ||
| 57 | } | ||
| 58 | -- | ||
| 59 | 2.43.0 | ||
| 60 | |||
