Skip to content

Commit 0911393

Browse files
authored
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
1 parent d974a3b commit 0911393

File tree

1 file changed

+4
-3
lines changed
  • src/rp2_common/hardware_sync/include/hardware

1 file changed

+4
-3
lines changed

src/rp2_common/hardware_sync/include/hardware/sync.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,10 @@ inline static spin_lock_t *spin_lock_instance(uint lock_num) {
204204
* \return The Spinlock ID
205205
*/
206206
inline static uint spin_lock_get_num(spin_lock_t *lock) {
207-
int lock_num = lock - (spin_lock_t *) (SIO_BASE + SIO_SPINLOCK0_OFFSET);
208-
invalid_params_if(SYNC, lock_num < 0 || lock_num >= NUM_SPIN_LOCKS);
209-
return (uint) lock_num;
207+
invalid_params_if(SYNC, (uint) lock < SIO_BASE + SIO_SPINLOCK0_OFFSET ||
208+
(uint) lock >= NUM_SPIN_LOCKS * sizeof(spin_lock_t) + SIO_BASE + SIO_SPINLOCK0_OFFSET ||
209+
((uint) lock - SIO_BASE + SIO_SPINLOCK0_OFFSET) % sizeof(spin_lock_t) != 0);
210+
return (uint) (lock - (spin_lock_t *) (SIO_BASE + SIO_SPINLOCK0_OFFSET));
210211
}
211212

212213
/*! \brief Acquire a spin lock without disabling interrupts (hence unsafe)

0 commit comments

Comments
 (0)