From 13a9a75f79a97569d00a00b3ee395afabe7e5f9e Mon Sep 17 00:00:00 2001 From: "andrey.bychkov" Date: Wed, 5 Aug 2026 17:38:22 +0300 Subject: [PATCH] fix(PISerial): break infinite loop when readDevice returns <= 0 In the blocking read path (timeout_ms <= 0), the while loop had no exit condition for readDevice() returning 0 (EOF) or -1 (error). This caused an infinite busy-loop at 100% CPU. Added 'else break' to exit the loop on read failure, matching the timeout branch which already handles this case. --- libs/main/io_devices/piserial.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libs/main/io_devices/piserial.cpp b/libs/main/io_devices/piserial.cpp index 9859ef68..401d5dfc 100644 --- a/libs/main/io_devices/piserial.cpp +++ b/libs/main/io_devices/piserial.cpp @@ -513,7 +513,10 @@ bool PISerial::read(void * data, int size, double timeout_ms) { all = readDevice(data, 1); while (all < size) { ret = readDevice(&((uchar *)data)[all], size - all); - if (ret > 0) all += ret; + if (ret > 0) + all += ret; + else + break; } setOption(BlockingRead, br); received(data, all); @@ -1235,8 +1238,8 @@ PIVector PISerial::availableDevicesInfo(bool test) { for (const auto & e: de) { // TODO changes in FileInfo for (const auto & p: prefixes) { if (e.name().startsWith(p)) { - di = DeviceInfo(); - di.path = e.path; + di = DeviceInfo(); + di.path = e.path; # ifdef LINUX ssize_t lsz = readlink(("/sys/class/tty/" + e.name()).dataAscii(), linkbuf, 1024); if (lsz > 0) {