mirror of
				https://review.coreboot.org/flashrom.git
				synced 2025-10-31 13:20:42 +01:00 
			
		
		
		
	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>
This commit is contained in:
		 Edward O'Callaghan
					Edward O'Callaghan
				
			
				
					committed by
					
						 Anastasia Klimchuk
						Anastasia Klimchuk
					
				
			
			
				
	
			
			
			 Anastasia Klimchuk
						Anastasia Klimchuk
					
				
			
						parent
						
							673cb357d4
						
					
				
				
					commit
					20400d6656
				
			
							
								
								
									
										16
									
								
								tests/chip.c
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								tests/chip.c
									
									
									
									
									
								
							| @@ -243,7 +243,7 @@ void erase_chip_with_dummyflasher_test_success(void **state) | |||||||
| 	 * Dummyflasher is capable to emulate W25Q128.V, so we ask it to do this. | 	 * Dummyflasher is capable to emulate W25Q128.V, so we ask it to do this. | ||||||
| 	 * Nothing to mock, dummy is taking care of this already. | 	 * 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); | 	setup_chip(&flashctx, &layout, &mock_chip, param_dup, &chip_io); | ||||||
|  |  | ||||||
| @@ -252,8 +252,6 @@ void erase_chip_with_dummyflasher_test_success(void **state) | |||||||
| 	printf("Erase chip operation done.\n"); | 	printf("Erase chip operation done.\n"); | ||||||
|  |  | ||||||
| 	teardown(&layout); | 	teardown(&layout); | ||||||
|  |  | ||||||
| 	free(param_dup); |  | ||||||
| } | } | ||||||
|  |  | ||||||
| void read_chip_test_success(void **state) | void read_chip_test_success(void **state) | ||||||
| @@ -311,7 +309,7 @@ void read_chip_with_dummyflasher_test_success(void **state) | |||||||
| 	 * Dummyflasher is capable to emulate W25Q128.V, so we ask it to do this. | 	 * Dummyflasher is capable to emulate W25Q128.V, so we ask it to do this. | ||||||
| 	 * Nothing to mock, dummy is taking care of this already. | 	 * 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); | 	setup_chip(&flashctx, &layout, &mock_chip, param_dup, &chip_io); | ||||||
|  |  | ||||||
| @@ -326,7 +324,6 @@ void read_chip_with_dummyflasher_test_success(void **state) | |||||||
|  |  | ||||||
| 	teardown(&layout); | 	teardown(&layout); | ||||||
|  |  | ||||||
| 	free(param_dup); |  | ||||||
| 	free(buf); | 	free(buf); | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -398,7 +395,7 @@ void write_chip_with_dummyflasher_test_success(void **state) | |||||||
| 	 * Dummyflasher is capable to emulate W25Q128.V, so we ask it to do this. | 	 * Dummyflasher is capable to emulate W25Q128.V, so we ask it to do this. | ||||||
| 	 * Nothing to mock, dummy is taking care of this already. | 	 * 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); | 	setup_chip(&flashctx, &layout, &mock_chip, param_dup, &chip_io); | ||||||
|  |  | ||||||
| @@ -414,7 +411,6 @@ void write_chip_with_dummyflasher_test_success(void **state) | |||||||
|  |  | ||||||
| 	teardown(&layout); | 	teardown(&layout); | ||||||
|  |  | ||||||
| 	free(param_dup); |  | ||||||
| 	free(newcontents); | 	free(newcontents); | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -438,7 +434,7 @@ void write_nonaligned_region_with_dummyflasher_test_success(void **state) | |||||||
| 	 * Dummyflasher is capable to emulate W25Q128.V, so we ask it to do this. | 	 * Dummyflasher is capable to emulate W25Q128.V, so we ask it to do this. | ||||||
| 	 * Nothing to mock, dummy is taking care of this already. | 	 * 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 | 	/* 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 | 	 * not be either 0x00 or 0xFF as those are specific values related to | ||||||
| @@ -505,7 +501,6 @@ void write_nonaligned_region_with_dummyflasher_test_success(void **state) | |||||||
| 	printf("Entire chip verify op done.\n"); | 	printf("Entire chip verify op done.\n"); | ||||||
|  |  | ||||||
| 	teardown(&layout); | 	teardown(&layout); | ||||||
| 	free(param_dup); |  | ||||||
| 	free(newcontents); | 	free(newcontents); | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -578,7 +573,7 @@ void verify_chip_with_dummyflasher_test_success(void **state) | |||||||
| 	 * Dummyflasher is capable to emulate W25Q128.V, so we ask it to do this. | 	 * Dummyflasher is capable to emulate W25Q128.V, so we ask it to do this. | ||||||
| 	 * Nothing to mock, dummy is taking care of this already. | 	 * 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); | 	setup_chip(&flashctx, &layout, &mock_chip, param_dup, &verify_chip_io); | ||||||
|  |  | ||||||
| @@ -605,6 +600,5 @@ void verify_chip_with_dummyflasher_test_success(void **state) | |||||||
|  |  | ||||||
| 	teardown(&layout); | 	teardown(&layout); | ||||||
|  |  | ||||||
| 	free(param_dup); |  | ||||||
| 	free(newcontents); | 	free(newcontents); | ||||||
| } | } | ||||||
|   | |||||||
| @@ -106,7 +106,7 @@ void invalid_wp_range_dummyflasher_test_success(void **state) | |||||||
| { | { | ||||||
| 	(void) state; /* unused */ | 	(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 flashrom_flashctx flash = { 0 }; | ||||||
| 	struct flashchip mock_chip = chip_W25Q128_V; | 	struct flashchip mock_chip = chip_W25Q128_V; | ||||||
| @@ -123,7 +123,6 @@ void invalid_wp_range_dummyflasher_test_success(void **state) | |||||||
| 	teardown(NULL); | 	teardown(NULL); | ||||||
|  |  | ||||||
| 	flashrom_wp_cfg_release(wp_cfg); | 	flashrom_wp_cfg_release(wp_cfg); | ||||||
| 	free(param_dup); |  | ||||||
| } | } | ||||||
|  |  | ||||||
| /* Enabling hardware WP with a valid range succeeds */ | /* Enabling hardware WP with a valid range succeeds */ | ||||||
| @@ -131,7 +130,7 @@ void set_wp_range_dummyflasher_test_success(void **state) | |||||||
| { | { | ||||||
| 	(void) state; /* unused */ | 	(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 flashrom_flashctx flash = { 0 }; | ||||||
| 	struct flashchip mock_chip = chip_W25Q128_V; | 	struct flashchip mock_chip = chip_W25Q128_V; | ||||||
| @@ -158,7 +157,6 @@ void set_wp_range_dummyflasher_test_success(void **state) | |||||||
| 	teardown(NULL); | 	teardown(NULL); | ||||||
|  |  | ||||||
| 	flashrom_wp_cfg_release(wp_cfg); | 	flashrom_wp_cfg_release(wp_cfg); | ||||||
| 	free(param_dup); |  | ||||||
| } | } | ||||||
|  |  | ||||||
| /* Enable hardware WP and verify that it can not be unset */ | /* Enable hardware WP and verify that it can not be unset */ | ||||||
| @@ -166,7 +164,7 @@ void switch_wp_mode_dummyflasher_test_success(void **state) | |||||||
| { | { | ||||||
| 	(void) state; /* unused */ | 	(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 flashrom_flashctx flash = { 0 }; | ||||||
| 	struct flashchip mock_chip = chip_W25Q128_V; | 	struct flashchip mock_chip = chip_W25Q128_V; | ||||||
| @@ -198,7 +196,6 @@ void switch_wp_mode_dummyflasher_test_success(void **state) | |||||||
| 	teardown(NULL); | 	teardown(NULL); | ||||||
|  |  | ||||||
| 	flashrom_wp_cfg_release(wp_cfg); | 	flashrom_wp_cfg_release(wp_cfg); | ||||||
| 	free(param_dup); |  | ||||||
| } | } | ||||||
|  |  | ||||||
| /* WP state is decoded correctly from status registers */ | /* WP state is decoded correctly from status registers */ | ||||||
| @@ -220,7 +217,7 @@ void wp_init_from_status_dummyflasher_test_success(void **state) | |||||||
| 	 * Multiplaying that by base unit gives 16 KiB protected region at the | 	 * Multiplaying that by base unit gives 16 KiB protected region at the | ||||||
| 	 * bottom (start of the chip), which is then complemented. | 	 * 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 flashrom_flashctx flash = { 0 }; | ||||||
| 	struct flashchip mock_chip = chip_W25Q128_V; | 	struct flashchip mock_chip = chip_W25Q128_V; | ||||||
| @@ -243,7 +240,6 @@ void wp_init_from_status_dummyflasher_test_success(void **state) | |||||||
| 	teardown(NULL); | 	teardown(NULL); | ||||||
|  |  | ||||||
| 	flashrom_wp_cfg_release(wp_cfg); | 	flashrom_wp_cfg_release(wp_cfg); | ||||||
| 	free(param_dup); |  | ||||||
| } | } | ||||||
|  |  | ||||||
| /* Enabled WP makes full chip erasure fail */ | /* Enabled WP makes full chip erasure fail */ | ||||||
| @@ -256,7 +252,7 @@ void full_chip_erase_with_wp_dummyflasher_test_success(void **state) | |||||||
| 	struct flashchip mock_chip = chip_W25Q128_V; | 	struct flashchip mock_chip = chip_W25Q128_V; | ||||||
| 	struct flashrom_wp_cfg *wp_cfg; | 	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); | 	setup_chip(&flash, &layout, &mock_chip, param_dup); | ||||||
| 	/* Layout regions are created by setup_chip(). */ | 	/* Layout regions are created by setup_chip(). */ | ||||||
| @@ -293,7 +289,6 @@ void full_chip_erase_with_wp_dummyflasher_test_success(void **state) | |||||||
| 	teardown(&layout); | 	teardown(&layout); | ||||||
|  |  | ||||||
| 	flashrom_wp_cfg_release(wp_cfg); | 	flashrom_wp_cfg_release(wp_cfg); | ||||||
| 	free(param_dup); |  | ||||||
| } | } | ||||||
|  |  | ||||||
| /* Enabled WP does not block erasing unprotected parts of the chip */ | /* Enabled WP does not block erasing unprotected parts of the chip */ | ||||||
| @@ -306,7 +301,7 @@ void partial_chip_erase_with_wp_dummyflasher_test_success(void **state) | |||||||
| 	struct flashchip mock_chip = chip_W25Q128_V; | 	struct flashchip mock_chip = chip_W25Q128_V; | ||||||
| 	struct flashrom_wp_cfg *wp_cfg; | 	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); | 	setup_chip(&flash, &layout, &mock_chip, param_dup); | ||||||
| 	/* Layout region is created by setup_chip(). */ | 	/* Layout region is created by setup_chip(). */ | ||||||
| @@ -330,5 +325,4 @@ void partial_chip_erase_with_wp_dummyflasher_test_success(void **state) | |||||||
| 	teardown(&layout); | 	teardown(&layout); | ||||||
|  |  | ||||||
| 	flashrom_wp_cfg_release(wp_cfg); | 	flashrom_wp_cfg_release(wp_cfg); | ||||||
| 	free(param_dup); |  | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user