Edward O'Callaghan has uploaded this change for review.

View 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>
---
M tests/chip.c
M tests/chip_wp.c
2 files changed, 22 insertions(+), 21 deletions(-)

git pull ssh://review.coreboot.org:29418/flashrom refs/changes/17/71917/1
diff --git a/tests/chip.c b/tests/chip.c
index 1d9cdc9..194e114 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);
}

@@ -487,7 +483,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);

@@ -514,6 +510,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.

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: Ic6cb4f32094ae5868912ebcffc8ab21026c48d32
Gerrit-Change-Number: 71917
Gerrit-PatchSet: 1
Gerrit-Owner: Edward O'Callaghan <quasisec@chromium.org>
Gerrit-MessageType: newchange