Skip to content

Commit 21e00db

Browse files
committed
Fix some errors from -fanalyzer.
Includes a genuine bug in multicore_doorbell_claim() which seemed to use the wrong bit for the second core.
1 parent 8fcd44a commit 21e00db

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed

src/common/pico_sync/mutex.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ void __weak runtime_init_mutex(void) {
1818
static_assert(!(sizeof(recursive_mutex_t)&3), "");
1919
static_assert(!offsetof(mutex_t, core), "");
2020
static_assert(!offsetof(recursive_mutex_t, core), "");
21-
extern lock_core_t __mutex_array_start;
21+
extern lock_core_t __mutex_array_start[];
2222
extern lock_core_t __mutex_array_end;
2323

24-
for (lock_core_t *l = &__mutex_array_start; l < &__mutex_array_end; ) {
24+
for (lock_core_t *l = &__mutex_array_start[0]; l < &__mutex_array_end; ) {
2525
if (l->spin_lock) {
2626
assert(1 == (uintptr_t)l->spin_lock); // indicator for a recursive mutex
2727
recursive_mutex_t *rm = (recursive_mutex_t *)l;
@@ -225,4 +225,4 @@ void __time_critical_func(recursive_mutex_exit)(recursive_mutex_t *mtx) {
225225
} else {
226226
spin_unlock(mtx->core.spin_lock, save);
227227
}
228-
}
228+
}

src/common/pico_time/time.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ alarm_pool_t *alarm_pool_create_on_timer(alarm_pool_timer_t *timer, uint hardwar
112112
alarm_pool_t *pool = (alarm_pool_t *) malloc(sizeof(alarm_pool_t));
113113
if (pool) {
114114
pool->entries = (alarm_pool_entry_t *) calloc(max_timers, sizeof(alarm_pool_entry_t));
115+
if (!pool->entries) panic("Failed to allocate alarm pool entries");
115116
ta_hardware_alarm_claim(timer, hardware_alarm_num);
116117
alarm_pool_post_alloc_init(pool, timer, hardware_alarm_num, max_timers);
117118
}
@@ -122,6 +123,7 @@ alarm_pool_t *alarm_pool_create_on_timer_with_unused_hardware_alarm(alarm_pool_t
122123
alarm_pool_t *pool = (alarm_pool_t *) malloc(sizeof(alarm_pool_t));
123124
if (pool) {
124125
pool->entries = (alarm_pool_entry_t *) calloc(max_timers, sizeof(alarm_pool_entry_t));
126+
if (!pool->entries) panic("Failed to allocate alarm pool entries");
125127
alarm_pool_post_alloc_init(pool, timer, (uint) ta_hardware_alarm_claim_unused(timer, true), max_timers);
126128
}
127129
return pool;
@@ -567,4 +569,4 @@ int64_t remaining_alarm_time_us(alarm_id_t alarm_id) {
567569
int32_t remaining_alarm_time_ms(alarm_id_t alarm_id) {
568570
return alarm_pool_remaining_alarm_time_ms(alarm_pool_get_default(), alarm_id);
569571
}
570-
#endif
572+
#endif

src/rp2_common/pico_multicore/multicore.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ static inline void clear_claimed_bit(uint8_t *bits, uint bit_index) {
367367
static bool multicore_doorbell_claim_under_lock(uint doorbell_num, uint core_mask, bool required) {
368368
static_assert(NUM_CORES == 2, "");
369369
uint claimed_cores_for_doorbell = (uint) (is_bit_claimed(doorbell_claimed[0], doorbell_num) |
370-
(is_bit_claimed(doorbell_claimed[1], doorbell_num + 1u) << 1));
370+
(is_bit_claimed(doorbell_claimed[1], doorbell_num) << 1));
371371
if (claimed_cores_for_doorbell & core_mask) {
372372
if (required) {
373373
panic( "Multicore doorbell %d already claimed on core mask 0x%x; requested core mask 0x%x\n",

src/rp2_common/pico_rand/rand.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ static uint64_t capture_additional_rosc_samples(uint n) {
239239
#endif
240240

241241
static void initialise_rand(void) {
242-
rng_128_t local_rng_state = local_rng_state;
242+
rng_128_t local_rng_state = {0};
243243
uint which = 0;
244244
#if PICO_RAND_SEED_ENTROPY_SRC_RAM_HASH
245245
ram_hash = sdbm_hash64_sram(ram_hash);

0 commit comments

Comments
 (0)