From nobody Sun Feb 8 01:52:00 2026 Received: from rtits2.realtek.com.tw (rtits2.realtek.com [211.75.126.72]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 68A252628D for ; Fri, 9 Jan 2026 03:26:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=211.75.126.72 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767929209; cv=none; b=UH3u6VCNHqWDAkCHhs/ZFZD5wWdODl0Fls/i0dZ4ldN5JYSm9CMK7FQMdI8AmS1fv9PTbncc3ywMJvoh0DFUz3PACK5clh3YCSot0V/VQP5NHN8rCkRRdll78ev0J+TkHPw20Rlav6wLqoaQz+gStKWI6Ympt3mJ1lDHHOV5pBw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767929209; c=relaxed/simple; bh=SVQOOyhKENUWqCuAtIS0cb2Jl+MUgAD4YMzT9Z0gWl4=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=YNY+dYSJ5NT+6tymi/KgjDFeI5AIDqY2K5aNIgbm+b96XRXIpMT41Q0lbmwxTtj0sXcYgmi5+lpWtuyCvy/kw3f1VA6CPq0ELHionbs49sAYxA1qG5kb91Rb+Hpz6xlmhFC9JSvYeQ2tpBdw7pHQ1zhEZXAyUG+WhyLBd0ffK0E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=realtek.com; spf=pass smtp.mailfrom=realtek.com; dkim=pass (2048-bit key) header.d=realtek.com header.i=@realtek.com header.b=NrJHIqBz; arc=none smtp.client-ip=211.75.126.72 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=realtek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=realtek.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=realtek.com header.i=@realtek.com header.b="NrJHIqBz" X-SpamFilter-By: ArmorX SpamTrap 5.80 with qID 6093QXJY02408900, This message is accepted by code: ctloc85258 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=realtek.com; s=dkim; t=1767929193; bh=w0LofgNleugjeVUSriqa1AVIiBmcRG935XlkwQTIcxk=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version: Content-Transfer-Encoding:Content-Type; b=NrJHIqBz7pX596KXan0Sc+fgB1rn6RurMQtrA0Xhg9OX6sAXOcscxN2wLPW9KnAC8 o65EsuUZQXmSAI0fVpuO1XBZ9r/bEGp3zl/HXS2uJrZ5M7d4CoaGDVyLc3IT4Z5TJH 2P9j1fGt66PAHJ0iGAs+Dx6rI/2ge4cwFNt+rLwEu3RPCtL6WovqEv/IRDL7anhMQ/ pL09GQA1Yu6ybzXwGtwt0uvVbQsms1osGVjLs6tpzjXteZomRTE8LJ+BUF3bEriCrU vdqjJYFB38fqSTut+90BAwfwq0Hi43RTYI8ZhSp/RaoDTUms+2546l1u7k3NOE/eN/ koP1jH56RP2mw== Received: from mail.realtek.com (rtkexhmbs04.realtek.com.tw[10.21.1.54]) by rtits2.realtek.com.tw (8.15.2/3.21/5.94) with ESMTPS id 6093QXJY02408900 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 9 Jan 2026 11:26:33 +0800 Received: from RTKEXHMBS04.realtek.com.tw (10.21.1.54) by RTKEXHMBS04.realtek.com.tw (10.21.1.54) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1748.10; Fri, 9 Jan 2026 11:26:33 +0800 Received: from cn1dhc-k02 (172.21.252.101) by RTKEXHMBS04.realtek.com.tw (10.21.1.54) with Microsoft SMTP Server id 15.2.1748.10 via Frontend Transport; Fri, 9 Jan 2026 11:26:33 +0800 From: Yu-Chun Lin To: , , , , , CC: , , , , Subject: [PATCH v3] regmap: Fix race condition in hwspinlock irqsave routine Date: Fri, 9 Jan 2026 11:26:33 +0800 Message-ID: <20260109032633.8732-1-eleanor.lin@realtek.com> X-Mailer: git-send-email 2.50.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Cheng-Yu Lee 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 Co-developed-by: Yu-Chun Lin Signed-off-by: Yu-Chun Lin --- 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@realt= ek.com/ v1: Link: https://lore.kernel.org/lkml/20260106021501.30682-1-eleanor.lin@realt= ek.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 =3D __map; + unsigned long flags =3D 0; =20 hwspin_lock_timeout_irqsave(map->hwlock, UINT_MAX, - &map->spinlock_flags); + &flags); + map->spinlock_flags =3D flags; } =20 static void regmap_unlock_hwlock(void *__map) --=20 2.34.1