storage/stream: allow NULL data pointer

This is done to support the idiomatic way of performing flush
operations, where the caller might not have access to the proper data
pointer. Also, there is no reason why reading from address 0 should
not be allowed.

Signed-off-by: Håkon Øye Amundsen <haakon.amundsen@nordicsemi.no>
This commit is contained in:
Håkon Øye Amundsen 2020-05-28 09:23:51 +02:00 committed by Carles Cufí
commit a4957be25b
2 changed files with 13 additions and 1 deletions

View file

@ -115,7 +115,7 @@ int stream_flash_buffered_write(struct stream_flash_ctx *ctx, const uint8_t *dat
size_t fill_length;
uint8_t filler;
if (!ctx || !data) {
if (!ctx) {
return -EFAULT;
}

View file

@ -306,6 +306,17 @@ static void test_stream_flash_buffered_write_callback(void)
zassert_equal(rc, -EFAULT, "expected failure from callback");
}
static void test_stream_flash_flush(void)
{
int rc;
init_target();
/* Perform flush with NULL data pointer and 0 lentgth */
rc = stream_flash_buffered_write(&ctx, NULL, 0, true);
zassert_equal(rc, 0, "expected success");
}
#ifdef CONFIG_STREAM_FLASH_ERASE
static void test_stream_flash_buffered_write_whole_page(void)
{
@ -381,6 +392,7 @@ void test_main(void)
ztest_unit_test(test_stream_flash_buffered_write_multi_page),
ztest_unit_test(test_stream_flash_buf_size_greater_than_page_size),
ztest_unit_test(test_stream_flash_buffered_write_callback),
ztest_unit_test(test_stream_flash_flush),
ztest_unit_test(test_stream_flash_buffered_write_whole_page),
ztest_unit_test(test_stream_flash_erase_page),
ztest_unit_test(test_stream_flash_bytes_written)