[PATCH 2/5] test: bootflow: Avoid a confusing error condition
Simon Glass
sjg at chromium.org
Fri Dec 20 05:01:17 CET 2024
The prep_mmc_bootdev() function replaces bootstd's bootdev_order with
its own static version, then returns it.
>From then on std->bootdev_order cannot be freed, since it was not
allocated.
So long as the test passes, all is well. But if a test fails, the test
system will try to free std->bootdev_order and this will fail.
Adjust prep_mmc_bootdev() to allocate the boot_dev order, instead.
Signed-off-by: Simon Glass <sjg at chromium.org>
---
test/boot/bootflow.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c
index 35580cee90c..4d7d795cbe1 100644
--- a/test/boot/bootflow.c
+++ b/test/boot/bootflow.c
@@ -540,12 +540,15 @@ BOOTSTD_TEST(bootflow_cmd_boot, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE);
static int prep_mmc_bootdev(struct unit_test_state *uts, const char *mmc_dev,
bool bind_cros_android, const char ***old_orderp)
{
- static const char *order[] = {"mmc2", "mmc1", NULL, NULL};
+ static const char **order;
struct udevice *dev, *bootstd;
struct bootstd_priv *std;
const char **old_order;
ofnode root, node;
+ order = calloc(sizeof(void *), 4);
+ order[0] = "mmc2";
+ order[1] = "mmc1";
order[2] = mmc_dev;
/* Enable the requested mmc node since we need a second bootflow */
@@ -605,6 +608,7 @@ static int scan_mmc_bootdev(struct unit_test_state *uts, const char *mmc_dev,
/* Restore the order used by the device tree */
ut_assertok(uclass_first_device_err(UCLASS_BOOTSTD, &bootstd));
std = dev_get_priv(bootstd);
+ free(std->bootdev_order);
std->bootdev_order = old_order;
return 0;
@@ -635,6 +639,7 @@ static int scan_mmc_android_bootdev(struct unit_test_state *uts, const char *mmc
/* Restore the order used by the device tree */
ut_assertok(uclass_first_device_err(UCLASS_BOOTSTD, &bootstd));
std = dev_get_priv(bootstd);
+ free(std->bootdev_order);
std->bootdev_order = old_order;
return 0;
@@ -726,6 +731,7 @@ static int bootflow_scan_menu(struct unit_test_state *uts)
std->bootdev_order = new_order; /* Blue Monday */
ut_assertok(run_command("bootflow scan -lm", 0));
+ free(std->bootdev_order);
std->bootdev_order = old_order;
ut_assertnull(std->cur_bootflow);
--
2.34.1
More information about the U-Boot
mailing list