drivers/base/regmap/regmap.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
From: Cheng-Yu Lee <cylee12@realtek.com>
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: 8698b9364710 ("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>
---
v3:
- Actually apply the code change mentioned in v2.
v2:
- Initialize 'flags' to 0. This fixes a -Werror build failure when
CONFIG_HWSPINLOCK is disabled, as the stub function in that case does
not initialize the pointer.
Link: https://lore.kernel.org/lkml/20260107032610.13166-1-eleanor.lin@realtek.com/
v1:
Link: https://lore.kernel.org/lkml/20260106021501.30682-1-eleanor.lin@realtek.com/
drivers/base/regmap/regmap.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index ce9be3989a21..ae2215d4e61c 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -408,9 +408,11 @@ static void regmap_lock_hwlock_irq(void *__map)
static void regmap_lock_hwlock_irqsave(void *__map)
{
struct regmap *map = __map;
+ unsigned long flags = 0;
hwspin_lock_timeout_irqsave(map->hwlock, UINT_MAX,
- &map->spinlock_flags);
+ &flags);
+ map->spinlock_flags = flags;
}
static void regmap_unlock_hwlock(void *__map)
--
2.34.1
On Fri, 09 Jan 2026 11:26:33 +0800, Yu-Chun Lin wrote:
> 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.
>
> [...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap.git for-next
Thanks!
[1/1] regmap: Fix race condition in hwspinlock irqsave routine
commit: 4b58aac989c1e3fafb1c68a733811859df388250
All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying
to this mail.
Thanks,
Mark
© 2016 - 2026 Red Hat, Inc.