Fix some errors from -fanalyzer.

Includes a genuine bug in multicore_doorbell_claim() which seemed to use the wrong bit for the second core.
This commit is contained in:
Luke Wren 2025-10-15 13:04:56 +01:00
parent 8fcd44a171
commit 21e00db871
4 changed files with 8 additions and 6 deletions

View file

@ -18,10 +18,10 @@ void __weak runtime_init_mutex(void) {
static_assert(!(sizeof(recursive_mutex_t)&3), "");
static_assert(!offsetof(mutex_t, core), "");
static_assert(!offsetof(recursive_mutex_t, core), "");
extern lock_core_t __mutex_array_start;
extern lock_core_t __mutex_array_start[];
extern lock_core_t __mutex_array_end;
for (lock_core_t *l = &__mutex_array_start; l < &__mutex_array_end; ) {
for (lock_core_t *l = &__mutex_array_start[0]; l < &__mutex_array_end; ) {
if (l->spin_lock) {
assert(1 == (uintptr_t)l->spin_lock); // indicator for a recursive mutex
recursive_mutex_t *rm = (recursive_mutex_t *)l;
@ -225,4 +225,4 @@ void __time_critical_func(recursive_mutex_exit)(recursive_mutex_t *mtx) {
} else {
spin_unlock(mtx->core.spin_lock, save);
}
}
}

View file

@ -112,6 +112,7 @@ alarm_pool_t *alarm_pool_create_on_timer(alarm_pool_timer_t *timer, uint hardwar
alarm_pool_t *pool = (alarm_pool_t *) malloc(sizeof(alarm_pool_t));
if (pool) {
pool->entries = (alarm_pool_entry_t *) calloc(max_timers, sizeof(alarm_pool_entry_t));
if (!pool->entries) panic("Failed to allocate alarm pool entries");
ta_hardware_alarm_claim(timer, hardware_alarm_num);
alarm_pool_post_alloc_init(pool, timer, hardware_alarm_num, max_timers);
}
@ -122,6 +123,7 @@ alarm_pool_t *alarm_pool_create_on_timer_with_unused_hardware_alarm(alarm_pool_t
alarm_pool_t *pool = (alarm_pool_t *) malloc(sizeof(alarm_pool_t));
if (pool) {
pool->entries = (alarm_pool_entry_t *) calloc(max_timers, sizeof(alarm_pool_entry_t));
if (!pool->entries) panic("Failed to allocate alarm pool entries");
alarm_pool_post_alloc_init(pool, timer, (uint) ta_hardware_alarm_claim_unused(timer, true), max_timers);
}
return pool;
@ -567,4 +569,4 @@ int64_t remaining_alarm_time_us(alarm_id_t alarm_id) {
int32_t remaining_alarm_time_ms(alarm_id_t alarm_id) {
return alarm_pool_remaining_alarm_time_ms(alarm_pool_get_default(), alarm_id);
}
#endif
#endif

View file

@ -367,7 +367,7 @@ static inline void clear_claimed_bit(uint8_t *bits, uint bit_index) {
static bool multicore_doorbell_claim_under_lock(uint doorbell_num, uint core_mask, bool required) {
static_assert(NUM_CORES == 2, "");
uint claimed_cores_for_doorbell = (uint) (is_bit_claimed(doorbell_claimed[0], doorbell_num) |
(is_bit_claimed(doorbell_claimed[1], doorbell_num + 1u) << 1));
(is_bit_claimed(doorbell_claimed[1], doorbell_num) << 1));
if (claimed_cores_for_doorbell & core_mask) {
if (required) {
panic( "Multicore doorbell %d already claimed on core mask 0x%x; requested core mask 0x%x\n",

View file

@ -239,7 +239,7 @@ static uint64_t capture_additional_rosc_samples(uint n) {
#endif
static void initialise_rand(void) {
rng_128_t local_rng_state = local_rng_state;
rng_128_t local_rng_state = {0};
uint which = 0;
#if PICO_RAND_SEED_ENTROPY_SRC_RAM_HASH
ram_hash = sdbm_hash64_sram(ram_hash);