From 0911393fe2a81d1c96a7336f7cfd328f1d290d2b Mon Sep 17 00:00:00 2001 From: Lyle Cheatham <66628590+Lyle-Alloy@users.noreply.github.com> Date: Tue, 6 Apr 2021 17:41:57 -0400 Subject: [PATCH] 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 --- src/rp2_common/hardware_sync/include/hardware/sync.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/rp2_common/hardware_sync/include/hardware/sync.h b/src/rp2_common/hardware_sync/include/hardware/sync.h index 3131375..b206346 100644 --- a/src/rp2_common/hardware_sync/include/hardware/sync.h +++ b/src/rp2_common/hardware_sync/include/hardware/sync.h @@ -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)