From 5a9b77806fd2bfff3465c17b1d3d7b6e44e9673d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikael=20=C3=85gren?= Date: Tue, 13 May 2025 10:48:09 +0200 Subject: [PATCH] fw: Return 0 on sys_alloc success, -1 on error It is left to the app to keep track of whether it has had access to the allocated area before. --- hw/application_fpga/fw/tk1/storage.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/hw/application_fpga/fw/tk1/storage.c b/hw/application_fpga/fw/tk1/storage.c index b1be7b9..e2cc67a 100644 --- a/hw/application_fpga/fw/tk1/storage.c +++ b/hw/application_fpga/fw/tk1/storage.c @@ -67,20 +67,18 @@ static int storage_get_area(struct partition_table *part_table) return -1; } -// Allocate a new area for an app. Returns zero if a new area is -// allocated, one if an area already was allocated, and negative -// values for errors. +// Allocate a new area for an app. Returns zero on success. int storage_allocate_area(struct partition_table_storage *part_table_storage) { if (part_table_storage == NULL) { - return -4; + return -1; } struct partition_table *part_table = &part_table_storage->table; if (storage_get_area(part_table) != -1) { /* Already has an area */ - return 1; + return 0; } int index = get_first_empty(part_table); @@ -92,7 +90,7 @@ int storage_allocate_area(struct partition_table_storage *part_table_storage) uint32_t start_address = 0; if (index_to_address(index, &start_address) != 0) { - return -3; + return -1; } // Allocate the empty index found @@ -108,7 +106,7 @@ int storage_allocate_area(struct partition_table_storage *part_table_storage) auth_app_create(&part_table->app_storage[index].auth); if (part_table_write(part_table_storage) != 0) { - return -5; + return -1; } return 0;