mirror of
				https://xff.cz/git/u-boot/
				synced 2025-10-31 10:26:10 +01:00 
			
		
		
		
	bloblist: Zero records when adding
It is convenient for bloblist to zero out the contents of a records when it is added. This saves the callers having to do it. Update the API accordingly. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
		| @@ -73,6 +73,9 @@ static int bloblist_addrec(uint tag, int size, struct bloblist_rec **recp) | |||||||
| 	rec->hdr_size = sizeof(*rec); | 	rec->hdr_size = sizeof(*rec); | ||||||
| 	rec->size = size; | 	rec->size = size; | ||||||
| 	rec->spare = 0; | 	rec->spare = 0; | ||||||
|  |  | ||||||
|  | 	/* Zero the record data */ | ||||||
|  | 	memset(rec + 1, '\0', rec->size); | ||||||
| 	*recp = rec; | 	*recp = rec; | ||||||
|  |  | ||||||
| 	return 0; | 	return 0; | ||||||
|   | |||||||
| @@ -56,7 +56,7 @@ API | |||||||
| --- | --- | ||||||
|  |  | ||||||
| Bloblist provides a fairly simple API which allows blobs to be created and | Bloblist provides a fairly simple API which allows blobs to be created and | ||||||
| found. All access is via the blob's tag. | found. All access is via the blob's tag. Blob records are zeroed when added. | ||||||
|  |  | ||||||
|  |  | ||||||
| Finishing the bloblist | Finishing the bloblist | ||||||
|   | |||||||
| @@ -34,13 +34,31 @@ static struct bloblist_hdr *clear_bloblist(void) | |||||||
| { | { | ||||||
| 	struct bloblist_hdr *hdr; | 	struct bloblist_hdr *hdr; | ||||||
|  |  | ||||||
| 	/* Clear out any existing bloblist so we have a clean slate */ | 	/* | ||||||
|  | 	 * Clear out any existing bloblist so we have a clean slate. Zero the | ||||||
|  | 	 * header so that existing records are removed, but set everything else | ||||||
|  | 	 * to 0xff for testing purposes. | ||||||
|  | 	 */ | ||||||
| 	hdr = map_sysmem(CONFIG_BLOBLIST_ADDR, TEST_BLOBLIST_SIZE); | 	hdr = map_sysmem(CONFIG_BLOBLIST_ADDR, TEST_BLOBLIST_SIZE); | ||||||
| 	memset(hdr, '\0', TEST_BLOBLIST_SIZE); | 	memset(hdr, '\xff', TEST_BLOBLIST_SIZE); | ||||||
|  | 	memset(hdr, '\0', sizeof(*hdr)); | ||||||
|  |  | ||||||
| 	return hdr; | 	return hdr; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | static int check_zero(void *data, int size) | ||||||
|  | { | ||||||
|  | 	u8 *ptr; | ||||||
|  | 	int i; | ||||||
|  |  | ||||||
|  | 	for (ptr = data, i = 0; i < size; i++, ptr++) { | ||||||
|  | 		if (*ptr) | ||||||
|  | 			return -EINVAL; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	return 0; | ||||||
|  | } | ||||||
|  |  | ||||||
| static int bloblist_test_init(struct unit_test_state *uts) | static int bloblist_test_init(struct unit_test_state *uts) | ||||||
| { | { | ||||||
| 	struct bloblist_hdr *hdr; | 	struct bloblist_hdr *hdr; | ||||||
| @@ -84,10 +102,14 @@ static int bloblist_test_blob(struct unit_test_state *uts) | |||||||
| 	data = bloblist_find(TEST_TAG, TEST_SIZE); | 	data = bloblist_find(TEST_TAG, TEST_SIZE); | ||||||
| 	ut_asserteq_ptr(rec + 1, data); | 	ut_asserteq_ptr(rec + 1, data); | ||||||
|  |  | ||||||
|  | 	/* Check the data is zeroed */ | ||||||
|  | 	ut_assertok(check_zero(data, TEST_SIZE)); | ||||||
|  |  | ||||||
| 	/* Check the 'ensure' method */ | 	/* Check the 'ensure' method */ | ||||||
| 	ut_asserteq_ptr(data, bloblist_ensure(TEST_TAG, TEST_SIZE)); | 	ut_asserteq_ptr(data, bloblist_ensure(TEST_TAG, TEST_SIZE)); | ||||||
| 	ut_assertnull(bloblist_ensure(TEST_TAG, TEST_SIZE2)); | 	ut_assertnull(bloblist_ensure(TEST_TAG, TEST_SIZE2)); | ||||||
| 	rec2 = (struct bloblist_rec *)(data + ALIGN(TEST_SIZE, BLOBLIST_ALIGN)); | 	rec2 = (struct bloblist_rec *)(data + ALIGN(TEST_SIZE, BLOBLIST_ALIGN)); | ||||||
|  | 	ut_assertok(check_zero(data, TEST_SIZE)); | ||||||
|  |  | ||||||
| 	/* Check for a non-existent record */ | 	/* Check for a non-existent record */ | ||||||
| 	ut_asserteq_ptr(data, bloblist_ensure(TEST_TAG, TEST_SIZE)); | 	ut_asserteq_ptr(data, bloblist_ensure(TEST_TAG, TEST_SIZE)); | ||||||
| @@ -112,6 +134,7 @@ static int bloblist_test_blob_ensure(struct unit_test_state *uts) | |||||||
| 	size = TEST_SIZE; | 	size = TEST_SIZE; | ||||||
| 	ut_assertok(bloblist_ensure_size_ret(TEST_TAG, &size, &data)); | 	ut_assertok(bloblist_ensure_size_ret(TEST_TAG, &size, &data)); | ||||||
| 	ut_asserteq(TEST_SIZE, size); | 	ut_asserteq(TEST_SIZE, size); | ||||||
|  | 	ut_assertok(check_zero(data, TEST_SIZE)); | ||||||
|  |  | ||||||
| 	/* Check that we get the same thing again */ | 	/* Check that we get the same thing again */ | ||||||
| 	ut_assertok(bloblist_ensure_size_ret(TEST_TAG, &size, &data2)); | 	ut_assertok(bloblist_ensure_size_ret(TEST_TAG, &size, &data2)); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user