Anastasia Klimchuk submitted this change.
tests/chip{_wp}.c: Avoid unnecessary heap allocations
Just use a static string on the stack.
Change-Id: Ic6cb4f32094ae5868912ebcffc8ab21026c48d32
Signed-off-by: Edward O'Callaghan <quasisec@google.com>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/71917
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
---
M tests/chip.c
M tests/chip_wp.c
2 files changed, 26 insertions(+), 23 deletions(-)
diff --git a/tests/chip.c b/tests/chip.c
index e82719e..dc2ca11 100644
--- a/tests/chip.c
+++ b/tests/chip.c
@@ -243,7 +243,7 @@
* Dummyflasher is capable to emulate W25Q128.V, so we ask it to do this.
* Nothing to mock, dummy is taking care of this already.
*/
- char *param_dup = strdup("bus=spi,emulate=W25Q128FV");
+ const char *param_dup = "bus=spi,emulate=W25Q128FV";
setup_chip(&flashctx, &layout, &mock_chip, param_dup, &chip_io);
@@ -252,8 +252,6 @@
printf("Erase chip operation done.\n");
teardown(&layout);
-
- free(param_dup);
}
void read_chip_test_success(void **state)
@@ -311,7 +309,7 @@
* Dummyflasher is capable to emulate W25Q128.V, so we ask it to do this.
* Nothing to mock, dummy is taking care of this already.
*/
- char *param_dup = strdup("bus=spi,emulate=W25Q128FV");
+ const char *param_dup = "bus=spi,emulate=W25Q128FV";
setup_chip(&flashctx, &layout, &mock_chip, param_dup, &chip_io);
@@ -326,7 +324,6 @@
teardown(&layout);
- free(param_dup);
free(buf);
}
@@ -398,7 +395,7 @@
* Dummyflasher is capable to emulate W25Q128.V, so we ask it to do this.
* Nothing to mock, dummy is taking care of this already.
*/
- char *param_dup = strdup("bus=spi,emulate=W25Q128FV");
+ const char *param_dup = "bus=spi,emulate=W25Q128FV";
setup_chip(&flashctx, &layout, &mock_chip, param_dup, &chip_io);
@@ -414,7 +411,6 @@
teardown(&layout);
- free(param_dup);
free(newcontents);
}
@@ -438,7 +434,7 @@
* Dummyflasher is capable to emulate W25Q128.V, so we ask it to do this.
* Nothing to mock, dummy is taking care of this already.
*/
- char *param_dup = strdup("bus=spi,emulate=W25Q128FV");
+ const char *param_dup = "bus=spi,emulate=W25Q128FV";
/* FIXME: MOCK_CHIP_CONTENT is buggy within setup_chip, it should also
* not be either 0x00 or 0xFF as those are specific values related to
@@ -505,7 +501,6 @@
printf("Entire chip verify op done.\n");
teardown(&layout);
- free(param_dup);
free(newcontents);
}
@@ -578,7 +573,7 @@
* Dummyflasher is capable to emulate W25Q128.V, so we ask it to do this.
* Nothing to mock, dummy is taking care of this already.
*/
- char *param_dup = strdup("bus=spi,emulate=W25Q128FV");
+ const char *param_dup = "bus=spi,emulate=W25Q128FV";
setup_chip(&flashctx, &layout, &mock_chip, param_dup, &verify_chip_io);
@@ -605,6 +600,5 @@
teardown(&layout);
- free(param_dup);
free(newcontents);
}
diff --git a/tests/chip_wp.c b/tests/chip_wp.c
index 40303ff..f20b500 100644
--- a/tests/chip_wp.c
+++ b/tests/chip_wp.c
@@ -106,7 +106,7 @@
{
(void) state; /* unused */
- char *param_dup = strdup("bus=spi,emulate=W25Q128FV,hwwp=no");
+ const char *param_dup = "bus=spi,emulate=W25Q128FV,hwwp=no";
struct flashrom_flashctx flash = { 0 };
struct flashchip mock_chip = chip_W25Q128_V;
@@ -123,7 +123,6 @@
teardown(NULL);
flashrom_wp_cfg_release(wp_cfg);
- free(param_dup);
}
/* Enabling hardware WP with a valid range succeeds */
@@ -131,7 +130,7 @@
{
(void) state; /* unused */
- char *param_dup = strdup("bus=spi,emulate=W25Q128FV,hwwp=no");
+ const char *param_dup = "bus=spi,emulate=W25Q128FV,hwwp=no";
struct flashrom_flashctx flash = { 0 };
struct flashchip mock_chip = chip_W25Q128_V;
@@ -158,7 +157,6 @@
teardown(NULL);
flashrom_wp_cfg_release(wp_cfg);
- free(param_dup);
}
/* Enable hardware WP and verify that it can not be unset */
@@ -166,7 +164,7 @@
{
(void) state; /* unused */
- char *param_dup = strdup("bus=spi,emulate=W25Q128FV,hwwp=yes");
+ const char *param_dup = "bus=spi,emulate=W25Q128FV,hwwp=yes";
struct flashrom_flashctx flash = { 0 };
struct flashchip mock_chip = chip_W25Q128_V;
@@ -198,7 +196,6 @@
teardown(NULL);
flashrom_wp_cfg_release(wp_cfg);
- free(param_dup);
}
/* WP state is decoded correctly from status registers */
@@ -220,7 +217,7 @@
* Multiplaying that by base unit gives 16 KiB protected region at the
* bottom (start of the chip), which is then complemented.
*/
- char *param_dup = strdup("bus=spi,emulate=W25Q128FV,spi_status=0x41ec");
+ const char *param_dup = "bus=spi,emulate=W25Q128FV,spi_status=0x41ec";
struct flashrom_flashctx flash = { 0 };
struct flashchip mock_chip = chip_W25Q128_V;
@@ -243,7 +240,6 @@
teardown(NULL);
flashrom_wp_cfg_release(wp_cfg);
- free(param_dup);
}
/* Enabled WP makes full chip erasure fail */
@@ -256,7 +252,7 @@
struct flashchip mock_chip = chip_W25Q128_V;
struct flashrom_wp_cfg *wp_cfg;
- char *param_dup = strdup("bus=spi,emulate=W25Q128FV,hwwp=yes");
+ const char *param_dup = "bus=spi,emulate=W25Q128FV,hwwp=yes";
setup_chip(&flash, &layout, &mock_chip, param_dup);
/* Layout regions are created by setup_chip(). */
@@ -293,7 +289,6 @@
teardown(&layout);
flashrom_wp_cfg_release(wp_cfg);
- free(param_dup);
}
/* Enabled WP does not block erasing unprotected parts of the chip */
@@ -306,7 +301,7 @@
struct flashchip mock_chip = chip_W25Q128_V;
struct flashrom_wp_cfg *wp_cfg;
- char *param_dup = strdup("bus=spi,emulate=W25Q128FV,hwwp=yes");
+ const char *param_dup = "bus=spi,emulate=W25Q128FV,hwwp=yes";
setup_chip(&flash, &layout, &mock_chip, param_dup);
/* Layout region is created by setup_chip(). */
@@ -330,5 +325,4 @@
teardown(&layout);
flashrom_wp_cfg_release(wp_cfg);
- free(param_dup);
}
To view, visit change 71917. To unsubscribe, or for help writing mail filters, visit settings.