From 5affc221f3074be4e7239ba2a0683cae06b525fd Mon Sep 17 00:00:00 2001 From: Alexander Goncharov Date: Tue, 14 Feb 2023 19:31:44 +0400 Subject: flashrom: rewrite flashbuses_to_text() The previous implementation had no error handling, as a result the flashrom could crash if the computer ran out of memory. The new version returns NULL in such cases. Also, rewrite lots of `if` conditions to one cycle, store a name of buses and `enum chipbustype` in an array by using a custom struct. The caller always expected a non-null value, so change its behavior to handle a possible null value or use the `?` symbol. As far as `free()` can handle null pointers, do nothing with such callers. TEST=ninja test Change-Id: I59b9044c99b4ba6c00d8c97f1e91af09d70dce2c Signed-off-by: Alexander Goncharov Ticket: https://ticket.coreboot.org/issues/408 Reviewed-on: https://review.coreboot.org/c/flashrom/+/73039 Tested-by: build bot (Jenkins) Reviewed-by: Anastasia Klimchuk --- cli_classic.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'cli_classic.c') diff --git a/cli_classic.c b/cli_classic.c index 787de67ad..e4db91316 100644 --- a/cli_classic.c +++ b/cli_classic.c @@ -1011,7 +1011,7 @@ int main(int argc, char *argv[]) goto out_shutdown; } tempstr = flashbuses_to_text(get_buses_supported()); - msg_pdbg("The following protocols are supported: %s.\n", tempstr); + msg_pdbg("The following protocols are supported: %s.\n", tempstr ? tempstr : "?"); free(tempstr); for (j = 0; j < registered_master_count; j++) { @@ -1082,7 +1082,8 @@ int main(int argc, char *argv[]) /* repeat for convenience when looking at foreign logs */ tempstr = flashbuses_to_text(flashes[0].chip->bustype); msg_gdbg("Found %s flash chip \"%s\" (%d kB, %s).\n", - flashes[0].chip->vendor, flashes[0].chip->name, flashes[0].chip->total_size, tempstr); + flashes[0].chip->vendor, flashes[0].chip->name, flashes[0].chip->total_size, + tempstr ? tempstr : "?"); free(tempstr); } -- cgit v1.2.3