From: Pali Rohár <pali@kernel.org>
Date: Fri, 23 Jul 2021 09:14:18 +0000 (+0200)
Subject: tools: kwboot: Fix restoring terminal
X-Git-Tag: v2025.01-rc5-pxa1908~1770^2~23
X-Git-Url: http://git.dujemihanovic.xyz/img/static/html/index.html?a=commitdiff_plain;h=ec0fe5b84e0bdb94bb381a2b50092b24497c2091;p=u-boot.git

tools: kwboot: Fix restoring terminal

Call tcsetattr() only if the file descriptor is valid. It may be
invalidated by previous lines (if it is not a tty descriptor).

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>
Reviewed-by: Chris Packham <judge.packham@gmail.com>
Tested-by: Chris Packham <judge.packham@gmail.com>
---

diff --git a/tools/kwboot.c b/tools/kwboot.c
index 1ba5ded5d3..7fa742d84c 100644
--- a/tools/kwboot.c
+++ b/tools/kwboot.c
@@ -558,7 +558,8 @@ kwboot_terminal(int tty)
 		}
 	} while (quit[s] != 0);
 
-	tcsetattr(in, TCSANOW, &otio);
+	if (in >= 0)
+		tcsetattr(in, TCSANOW, &otio);
 out:
 	return rc;
 }