From nobody Sun Feb 8 05:59:54 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 117E12417D9 for ; Wed, 7 Jan 2026 03:26:26 +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=1767756389; cv=none; b=FeoTwWRQteLphDafXr3z/6A8YuFZavK3ih5/zINQFlVa4qVrzOf+lL0q2sl87Ta8ncBS7uh0FE1G/e+jYfICtwfZSg5YX33QmXwlbnpcY2hvvKK5qMsDWPW4zvaWj2hCnyni+2iKKokUowNKgfprbLOyQWLdoKoEd/kiGTKAI4I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767756389; c=relaxed/simple; bh=4xCYySBzQ/avttFMRxhB392OivHYilyVMKW2GO6LTdg=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=fVTWUWcrE7EvFw4SKX8JJjkFos45AQzJKKS3mqygBtpvDKUiM+BXz6l5ZerLjrX8jiMmyo28r01dWYHpscrz5H2NxYYwJp90Ctb4vEwAw9wPqszUj+Jh7kFfj7rCA10+prWstR9chW7NloGcMW7sZfYePCoLWRIfD6zLpq9xEk8= 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=TsRA6CeF; 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="TsRA6CeF" X-SpamFilter-By: ArmorX SpamTrap 5.80 with qID 6073QAHt82213371, This message is accepted by code: ctloc85258 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=realtek.com; s=dkim; t=1767756370; bh=RLMRJm1MYxeKqJZU/KyukOJL7ZxP4U2uwTqMFMhc2T8=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version: Content-Transfer-Encoding:Content-Type; b=TsRA6CeFeX6DcXdqrrjAKBZwfkdOgAHx9VrcyEDQimxD/Kcef9gQZDwOmviYVKVJI UM3b9woAvCiQi9/PGS4YitDCd2XTBSyIp61+u1GWCPWB3uNgUUyeSTyAw4ph9TFSbL H54PAQ8V0RL/tJVqFqeOKTd3mjAAn+MxScTPTHmeLVIcyc/x8GNXdItSrrhEyiYiLV oKwfXGiEICBoU49Zfwlz5vCAA4vjSaEEWm4eqTsxP71Xk1SMrc6ILeq4Q8Q/av55Bj +uCrrR4tgXHtXK0yB9mstIc/aR3NT17aQDGfVkaWihuZ4YsfehIPvz6AWUFcftzgcp ZXHKJBP47i2oA== Received: from mail.realtek.com (rtkexhmbs02.realtek.com.tw[172.21.6.41]) by rtits2.realtek.com.tw (8.15.2/3.21/5.94) with ESMTPS id 6073QAHt82213371 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 7 Jan 2026 11:26:10 +0800 Received: from RTKEXHMBS06.realtek.com.tw (10.21.1.56) by RTKEXHMBS02.realtek.com.tw (172.21.6.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1748.10; Wed, 7 Jan 2026 11:26:10 +0800 Received: from RTKEXHMBS03.realtek.com.tw (10.21.1.53) by RTKEXHMBS06.realtek.com.tw (10.21.1.56) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1748.10; Wed, 7 Jan 2026 11:26:10 +0800 Received: from cn1dhc-k02 (172.21.252.101) by RTKEXHMBS03.realtek.com.tw (10.21.1.53) with Microsoft SMTP Server id 15.2.1748.10 via Frontend Transport; Wed, 7 Jan 2026 11:26:10 +0800 From: Yu-Chun Lin To: , , , , , CC: , , , , Subject: [PATCH v2] regmap: Fix race condition in hwspinlock irqsave routine Date: Wed, 7 Jan 2026 11:26:10 +0800 Message-ID: <20260107032610.13166-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 --- 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 =3D __map; + unsigned long flags; =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