summaryrefslogtreecommitdiffstats
path: root/meta-oe/recipes-test/linux-serial-test
diff options
context:
space:
mode:
authorEmanuele Ghidoli <emanuele.ghidoli@toradex.com>2025-10-17 11:46:33 +0200
committerKhem Raj <raj.khem@gmail.com>2025-10-17 08:32:03 -0700
commite1f667ee800edf0f4e46167a24a7b7f603c51095 (patch)
treedb3a970aff8915da87f2de34adc8136ba6070c80 /meta-oe/recipes-test/linux-serial-test
parentae7092375a3d4c3d7bc1af692415901fca9cf815 (diff)
downloadmeta-openembedded-e1f667ee800edf0f4e46167a24a7b7f603c51095.tar.gz
linux-serial-test: add patch to fix potential hang in while loop
After commit 392f0f0ea76d ("linux-serial-test: Bump SRCREV to allow CMake 4+ compatibility"), an infinite while loop can occur even when the timeout has been reached. This patch fixes that regression. Signed-off-by: Emanuele Ghidoli <emanuele.ghidoli@toradex.com> Signed-off-by: Khem Raj <raj.khem@gmail.com>
Diffstat (limited to 'meta-oe/recipes-test/linux-serial-test')
-rw-r--r--meta-oe/recipes-test/linux-serial-test/files/0002-linux-serial-test.c-fix-potential-hang-in-while-loop.patch60
-rw-r--r--meta-oe/recipes-test/linux-serial-test/linux-serial-test_git.bb1
2 files changed, 61 insertions, 0 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
new file mode 100644
index 0000000000..f0b7f65a60
--- /dev/null
+++ b/meta-oe/recipes-test/linux-serial-test/files/0002-linux-serial-test.c-fix-potential-hang-in-while-loop.patch
@@ -0,0 +1,60 @@
1From 9cf6c1d80c2f159dbb69967fbe934bf6de73c9e8 Mon Sep 17 00:00:00 2001
2From: Max Krummenacher <max.krummenacher@toradex.com>
3Date: Tue, 5 Aug 2025 09:35:06 +0200
4Subject: [PATCH 2/2] linux-serial-test.c: fix potential hang in while loop
5
6process_read_data() assumes that we can always wait for reception
7of 1024 chars. However that is not true if one sets the number of
8chars with the '-w' cmdline parameter or chars are lost. Maybe there
9are other reasons.
10
11Replace the magic number of 1024 by calculating the number of expected
12chars from _cl_tx_bytes.
13
14Brake a possible infinite while loop by adding a timeout to the loop
15calculated from the expected chars times chartime.
16
17Upstream-Status: Submitted [https://github.com/cbrake/linux-serial-test/pull/61/]
18Fixes: 7fd1057f8a95 ("Add loop to read all data in rcv buffer")
19Signed-off-by: Max Krummenacher <max.krummenacher@toradex.com>
20Signed-off-by: Emanuele Ghidoli <emanuele.ghidoli@toradex.com>
21---
22 linux-serial-test.c | 14 ++++++++++++--
23 1 file changed, 12 insertions(+), 2 deletions(-)
24
25diff --git a/linux-serial-test.c b/linux-serial-test.c
26index 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--
592.43.0
60
diff --git a/meta-oe/recipes-test/linux-serial-test/linux-serial-test_git.bb b/meta-oe/recipes-test/linux-serial-test/linux-serial-test_git.bb
index 66511bd9c3..7a206319e7 100644
--- a/meta-oe/recipes-test/linux-serial-test/linux-serial-test_git.bb
+++ b/meta-oe/recipes-test/linux-serial-test/linux-serial-test_git.bb
@@ -5,6 +5,7 @@ LIC_FILES_CHKSUM = "file://LICENSES/MIT;md5=544799d0b492f119fa04641d1b8868ed"
5 5
6SRC_URI = "git://github.com/cbrake/linux-serial-test.git;protocol=https;branch=master \ 6SRC_URI = "git://github.com/cbrake/linux-serial-test.git;protocol=https;branch=master \
7 file://0001-linux-serial-test.c-fix-returned-error-code.patch \ 7 file://0001-linux-serial-test.c-fix-returned-error-code.patch \
8 file://0002-linux-serial-test.c-fix-potential-hang-in-while-loop.patch \
8" 9"
9PV = "0+git" 10PV = "0+git"
10SRCREV = "1a81f3c7be086ee01a9be8589a606426276c86d5" 11SRCREV = "1a81f3c7be086ee01a9be8589a606426276c86d5"