Skip to content

Commit 4b58aac

Browse files
Cheng-Yu Leebroonie
authored andcommitted
regmap: Fix race condition in hwspinlock irqsave routine
Previously, the address of the shared member '&map->spinlock_flags' was passed directly to 'hwspin_lock_timeout_irqsave'. This creates a race condition where multiple contexts contending for the lock could overwrite the shared flags variable, potentially corrupting the state for the current lock owner. Fix this by using a local stack variable 'flags' to store the IRQ state temporarily. Fixes: 8698b93 ("regmap: Add hardware spinlock support") Signed-off-by: Cheng-Yu Lee <cylee12@realtek.com> Co-developed-by: Yu-Chun Lin <eleanor.lin@realtek.com> Signed-off-by: Yu-Chun Lin <eleanor.lin@realtek.com> Link: https://patch.msgid.link/20260109032633.8732-1-eleanor.lin@realtek.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent f3f380c commit 4b58aac

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

drivers/base/regmap/regmap.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,9 +408,11 @@ static void regmap_lock_hwlock_irq(void *__map)
408408
static void regmap_lock_hwlock_irqsave(void *__map)
409409
{
410410
struct regmap *map = __map;
411+
unsigned long flags = 0;
411412

412413
hwspin_lock_timeout_irqsave(map->hwlock, UINT_MAX,
413-
&map->spinlock_flags);
414+
&flags);
415+
map->spinlock_flags = flags;
414416
}
415417

416418
static void regmap_unlock_hwlock(void *__map)

0 commit comments

Comments
 (0)