Changed the parameter check to avoid tripping -Werror on spin locks (#307)

This prevents a comparison between a signed and an unsigned number which
will create a warning tripping -Werror.

Also added a check for the alignment of the spin lock structure
This commit is contained in:
Lyle Cheatham 2021-04-06 17:41:57 -04:00 committed by GitHub
parent d974a3b0e9
commit 0911393fe2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -204,9 +204,10 @@ inline static spin_lock_t *spin_lock_instance(uint lock_num) {
* \return The Spinlock ID
*/
inline static uint spin_lock_get_num(spin_lock_t *lock) {
int lock_num = lock - (spin_lock_t *) (SIO_BASE + SIO_SPINLOCK0_OFFSET);
invalid_params_if(SYNC, lock_num < 0 || lock_num >= NUM_SPIN_LOCKS);
return (uint) lock_num;
invalid_params_if(SYNC, (uint) lock < SIO_BASE + SIO_SPINLOCK0_OFFSET ||
(uint) lock >= NUM_SPIN_LOCKS * sizeof(spin_lock_t) + SIO_BASE + SIO_SPINLOCK0_OFFSET ||
((uint) lock - SIO_BASE + SIO_SPINLOCK0_OFFSET) % sizeof(spin_lock_t) != 0);
return (uint) (lock - (spin_lock_t *) (SIO_BASE + SIO_SPINLOCK0_OFFSET));
}
/*! \brief Acquire a spin lock without disabling interrupts (hence unsafe)