[PATCH v2 2/2] console: Don't start/stop console if stdio device invalid

Nicolas Saenz Julienne nsaenzjulienne at suse.de
Thu Jan 28 14:12:40 CET 2021


Don't start/stop an stdio device that might have been already freed.

Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne at suse.de>
Fixes: 70c2525c0d3c ("IOMUX: Stop dropped consoles")

---
Changes since v1:
 - Add comment stating this should be properly fixed

 common/console.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/common/console.c b/common/console.c
index f3cc45cab5..570f26d149 100644
--- a/common/console.c
+++ b/common/console.c
@@ -252,6 +252,15 @@ static bool console_needs_start_stop(int file, struct stdio_dev *sdev)
 {
 	int i, j;
 
+	/*
+	 * TODO: This is a workaround to avoid accessing freed memory:
+	 * console_stop() might be called on an stdio_dev that has already been
+	 * de-registered, due to the fact that stdio_deregister_dev()
+	 * doesn't update the global console_devices array.
+	 */
+	if (!stdio_valid(sdev))
+		return false;
+
 	for (i = 0; i < ARRAY_SIZE(cd_count); i++) {
 		if (i == file)
 			continue;
-- 
2.30.0



More information about the U-Boot mailing list