From 02197fa749e21107e3330b2a244f7d5c455e456e Mon Sep 17 00:00:00 2001 From: Ovidiu Panait Date: Sun, 5 Apr 2020 19:47:40 +0300 Subject: [PATCH 1/2] dm: dump.c: Fix segfault when entry->of_match is NULL Currently, dm drivers command produces a segfault: => dm drivers Driver Compatible -------------------------------- Segmentation fault (core dumped) This is caused by a NULL pointer dereference of entry->of_match. Add a check to prevent this. Signed-off-by: Ovidiu Panait Cc: Sean Anderson Cc: Simon Glass --- drivers/core/dump.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/core/dump.c b/drivers/core/dump.c index e73ebeabcc..b5046398d4 100644 --- a/drivers/core/dump.c +++ b/drivers/core/dump.c @@ -107,7 +107,8 @@ void dm_dump_drivers(void) puts("Driver Compatible\n"); puts("--------------------------------\n"); for (entry = d; entry < d + n_ents; entry++) { - for (match = entry->of_match; match->compatible; match++) + for (match = entry->of_match; + match && match->compatible; match++) printf("%-20.20s %s\n", match == entry->of_match ? entry->name : "", match->compatible); From 28888ca38ecc1c427d41db92c624cbf6d343df74 Mon Sep 17 00:00:00 2001 From: Ovidiu Panait Date: Sun, 5 Apr 2020 19:47:41 +0300 Subject: [PATCH 2/2] dm: dump.c: Refactor dm_dump_drivers prints Refactor the printing sequence in dm_dump_drivers to make it more clear. Signed-off-by: Ovidiu Panait Cc: Sean Anderson Cc: Simon Glass Reviewed-by: Simon Glass --- drivers/core/dump.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/drivers/core/dump.c b/drivers/core/dump.c index b5046398d4..cb8a25b9ad 100644 --- a/drivers/core/dump.c +++ b/drivers/core/dump.c @@ -107,12 +107,16 @@ void dm_dump_drivers(void) puts("Driver Compatible\n"); puts("--------------------------------\n"); for (entry = d; entry < d + n_ents; entry++) { - for (match = entry->of_match; - match && match->compatible; match++) - printf("%-20.20s %s\n", - match == entry->of_match ? entry->name : "", - match->compatible); - if (match == entry->of_match) - printf("%-20.20s\n", entry->name); + match = entry->of_match; + + printf("%-20.20s", entry->name); + if (match) { + printf(" %s", match->compatible); + match++; + } + printf("\n"); + + for (; match && match->compatible; match++) + printf("%-20.20s %s\n", "", match->compatible); } }