* [PATCH v2] regmap: Fix race condition in hwspinlock irqsave routine
@ 2026-01-07 3:26 Yu-Chun Lin
2026-01-07 11:28 ` Mark Brown
2026-01-12 21:59 ` Mark Brown
0 siblings, 2 replies; 4+ messages in thread
From: Yu-Chun Lin @ 2026-01-07 3:26 UTC (permalink / raw)
To: broonie, gregkh, rafael, dakr, baolin.wang, cylee12
Cc: linux-kernel, james.tai, cy.huang, stanley_chang, eleanor.lin
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>
---
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.
v1: 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..8d889372517f 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;
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
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH v2] regmap: Fix race condition in hwspinlock irqsave routine
2026-01-07 3:26 [PATCH v2] regmap: Fix race condition in hwspinlock irqsave routine Yu-Chun Lin
@ 2026-01-07 11:28 ` Mark Brown
2026-01-09 3:12 ` Yu-Chun Lin
2026-01-12 21:59 ` Mark Brown
1 sibling, 1 reply; 4+ messages in thread
From: Mark Brown @ 2026-01-07 11:28 UTC (permalink / raw)
To: Yu-Chun Lin
Cc: gregkh, rafael, dakr, baolin.wang, cylee12, linux-kernel,
james.tai, cy.huang, stanley_chang
[-- Attachment #1: Type: text/plain, Size: 529 bytes --]
On Wed, Jan 07, 2026 at 11:26:10AM +0800, Yu-Chun Lin wrote:
> 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.
> {
> struct regmap *map = __map;
> + unsigned long flags;
>
> hwspin_lock_timeout_irqsave(map->hwlock, UINT_MAX,
> - &map->spinlock_flags);
> + &flags);
> + map->spinlock_flags = flags;
I'm not seeing that initialisation in the actual patch?
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH v2] regmap: Fix race condition in hwspinlock irqsave routine
2026-01-07 11:28 ` Mark Brown
@ 2026-01-09 3:12 ` Yu-Chun Lin
0 siblings, 0 replies; 4+ messages in thread
From: Yu-Chun Lin @ 2026-01-09 3:12 UTC (permalink / raw)
To: broonie
Cc: baolin.wang, cy.huang, cylee12, dakr, eleanor.lin, gregkh,
james.tai, linux-kernel, rafael, stanley_chang
> On Wed, Jan 07, 2026 at 11:26:10AM +0800, Yu-Chun Lin wrote:
>
> > 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.
>
> > {
> > struct regmap *map = __map;
> > + unsigned long flags;
> >
> > hwspin_lock_timeout_irqsave(map->hwlock, UINT_MAX,
> > - &map->spinlock_flags);
> > + &flags);
> > + map->spinlock_flags = flags;
>
> I'm not seeing that initialisation in the actual patch?
Oops, sorry about that. I made a mistake and accidentally kept the v1 code.
I will fix it in v3.
Yu-Chun
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] regmap: Fix race condition in hwspinlock irqsave routine
2026-01-07 3:26 [PATCH v2] regmap: Fix race condition in hwspinlock irqsave routine Yu-Chun Lin
2026-01-07 11:28 ` Mark Brown
@ 2026-01-12 21:59 ` Mark Brown
1 sibling, 0 replies; 4+ messages in thread
From: Mark Brown @ 2026-01-12 21:59 UTC (permalink / raw)
To: gregkh, rafael, dakr, baolin.wang, cylee12, Yu-Chun Lin
Cc: linux-kernel, james.tai, cy.huang, stanley_chang
On Wed, 07 Jan 2026 11:26:10 +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
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-01-12 21:59 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-01-07 3:26 [PATCH v2] regmap: Fix race condition in hwspinlock irqsave routine Yu-Chun Lin
2026-01-07 11:28 ` Mark Brown
2026-01-09 3:12 ` Yu-Chun Lin
2026-01-12 21:59 ` Mark Brown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®