mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [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

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®