Skip to content

Commit 92d5b6b

Browse files
committed
lib: GPT: Fix cppcheck warnings
Change-Id: Ia9e99dc59cbf869b804a24ba029f19f7170860b4 Signed-off-by: Antonio de Angelis <antonio.deangelis@arm.com>
1 parent 21ff1f8 commit 92d5b6b

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

lib/gpt/src/gpt.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* SPDX-License-Identifier: BSD-3-Clause
55
*/
66

7+
#include <assert.h>
78
#include <stdbool.h>
89
#include <stdint.h>
910
#include <stdlib.h>
@@ -194,7 +195,7 @@ static inline uint64_t gpt_entry_per_lba_count(void);
194195
static inline void swap_headers(const struct gpt_header_t *src, struct gpt_header_t *dst);
195196
static psa_status_t count_used_partitions(const struct gpt_t *table,
196197
uint32_t *num_used);
197-
static inline void parse_entry(struct gpt_entry_t *entry,
198+
static inline void parse_entry(const struct gpt_entry_t *entry,
198199
struct partition_entry_t *partition_entry);
199200
static psa_status_t read_from_flash(uint64_t required_lba);
200201
static psa_status_t read_entry_from_flash(const struct gpt_t *table,
@@ -226,7 +227,7 @@ static bool gpt_entry_cmp_name(const struct gpt_entry_t *entry, const void *name
226227
static bool gpt_entry_cmp_type(const struct gpt_entry_t *entry, const void *type);
227228
static psa_status_t validate_table(struct gpt_t *table, bool is_primary);
228229
static psa_status_t restore_table(struct gpt_t *restore_from, bool is_primary);
229-
static psa_status_t sort_partition_array(struct gpt_t *table);
230+
static psa_status_t sort_partition_array(const struct gpt_t *table);
230231

231232
/* PUBLIC API FUNCTIONS */
232233

@@ -1006,7 +1007,7 @@ static inline uint64_t gpt_entry_per_lba_count(void)
10061007
}
10071008

10081009
/* Copies information from the entry to the user visible structure */
1009-
static inline void parse_entry(struct gpt_entry_t *entry,
1010+
static inline void parse_entry(const struct gpt_entry_t *entry,
10101011
struct partition_entry_t *partition_entry)
10111012
{
10121013
partition_entry->start = entry->start;
@@ -1604,7 +1605,7 @@ static int cmp_u64(const void *a, const void *b)
16041605
}
16051606

16061607
/* bsearch but returns the index rather than the item */
1607-
static int64_t bsearch_index(uint64_t arr[], uint32_t len, uint64_t key)
1608+
static int64_t bsearch_index(const uint64_t arr[], uint32_t len, uint64_t key)
16081609
{
16091610
uint32_t l = 0;
16101611
uint32_t r = len;
@@ -1628,8 +1629,12 @@ static int64_t bsearch_index(uint64_t arr[], uint32_t len, uint64_t key)
16281629
/* Sorts the partition array for the given table by the start LBA for each
16291630
* partition. This makes defragmentation easier.
16301631
*/
1631-
static psa_status_t sort_partition_array(struct gpt_t *table)
1632+
static psa_status_t sort_partition_array(const struct gpt_t *table)
16321633
{
1634+
if (table->num_used_partitions == 0) {
1635+
assert(table->num_used_partitions > 0);
1636+
return PSA_ERROR_INVALID_ARGUMENT;
1637+
}
16331638
/* To avoid as much I/O as possible, the LBA's for each entry are sorted in
16341639
* memory and then the entries rearranged on flash after
16351640
*/

0 commit comments

Comments
 (0)