From nobody Mon Jun 15 06:29:38 2026 Received: from mail-pg1-f178.google.com (mail-pg1-f178.google.com [209.85.215.178]) (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 D00753CBE93 for ; Wed, 8 Apr 2026 13:11:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775653921; cv=none; b=NmizzNyCYO1FCMcC5m86MFauTLz0mZZ9KAqwZs0mNGPeGvxLQc07DhdV97tdQdfGdbtoKYRpAshQwINF3Df6crKUH9KvslHRQzBFX65CxFl57Bgetd3AyfZxScbkshYSS1XyDlwjuYJHFr+aldONmJM3heikbtunV4OdGCF4H20= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775653921; c=relaxed/simple; bh=iKGGoMWDzW81NUON7dibU9x2CVBdrYBVIwXpFSP2gzw=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=Wt/MtUFnA/vSVVxd29r9yh37qNYjwfTfY7vdglluk4GV8Lc16+pNFeMGjXzaNmQj9IpVrHRqHrV8YkS5MUuSWsq13LPlp9lXnXlHMMu3/fnJMaCbMu+hpCQQOTXsSMZ+DDlsS1toBBBpsgGyNVFI5jnQEDEmV+46fv1A0xV26YU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=d3jzi1Ht; arc=none smtp.client-ip=209.85.215.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="d3jzi1Ht" Received: by mail-pg1-f178.google.com with SMTP id 41be03b00d2f7-c76b95e652bso2059080a12.3 for ; Wed, 08 Apr 2026 06:11:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775653919; x=1776258719; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=ixZa3glWWcX2AwYa/ptHo0yH8cd2OWBqbPO44lhAivM=; b=d3jzi1Ht9XqML89wxjbF+SZQabWRPFnL8z1KDZnhss12Xw/O8Fyxh2yytlVyMp9MB0 xj7mvJJU8g8G8UQivHhEOiZio4tbH5NX5G0N1t9n4ZtLAMjGpwl5Yr23Me5oA4+9yere 0Ugdn5XRPZRCEVfzlIrwJntUu2MEklXI5ApsMJ9KmDVIK4fd66bxD3b3lio8RzHX9cV3 r6pbsXGAvucTxbprZm9DTBBswXa/0yLN6ifMLF01pXkrTG7oqhzKvmYHpvFhV2y1wZ0m L0jCg7DFwaRIn/7BIaqpLXySVVQGEyuF84z/OZ6AQtpVHX6hQBImekpHQ09vJO6vCnF5 iXpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775653919; x=1776258719; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=ixZa3glWWcX2AwYa/ptHo0yH8cd2OWBqbPO44lhAivM=; b=S8BMeyPxpBlgchGcP5ajRzpuWGJ3QSCdVD4bvx7vLJ9Rn/ULXpNMPrhl9JdWK1mTzf yx4jmSKBEgs89wnhCWHW7iIZ+pdYE7iWt+3RUet4ncQjOYPiIenMfGZHeA7VU0BFz1bl DXPVm/MOYRzam4/8bONgKvEH2vKjFJUx6wk4ueG6SXgsTnrRKaJ94Q4690goZNOu1oK0 /cHHzpUyBkNyn/xj5QLPox+5FC6VPtyFplSRRUJnqHPyy27j5OL9XkjKYH5DulQI2AER RTdFk3Nf/0qY5RIyn5bHEHNfdMbZUW1PxSzrvSRhzohJ7J/gM5HWncIWzcazXwb9Bkrj lo8w== X-Gm-Message-State: AOJu0YwO1W1UpKEjfBtmJ8IZ97R4ZyQqFSPP0uUoUAkmLahaMXCJMv9w 2u3jVJRHSyAUCa4o+gM8DDT0S8AV9kqI9SXqV9RQyy1mC3KVavVtH0FQ X-Gm-Gg: AeBDies+XdtxrbGZc/Otw4kmQhUDqsfLrEwwXe/AGEXCRcpk1KbQuYefCwGfUHpkXSj lX02/Amaw0t0bIOtYEKYGP/iQEdd/k231bD403V5wAa6YGQbKtrpPkOr7jx05P19BzLE1nBApMY p8M+mMbvGpq3fqr09gDxCAG//Ni+rrAsFeVViMP/Z5n8NkVea4WA+91aw++3buonGYgPgL4aY32 ki3N+NA1QKusq3mHIoMvaQ8c4mYXqzskcVchGLUKcahKKF9zIMuwx7dhn91/QdkRPVk9WIp5vk6 NGqTfz3PITVNg+bYjLJlp55+aItiCukGmqK0g6Vf9QQFug1ovHiZ038OCzxVeiGLg2IWoruR36A 48o8X0puiqZcb3oNk1X7ETcSVpaLcnY2ima3W8g+O5t+Eg/ODcjn9gBe4O8qxXv23sThU/s95L3 LHY+w/+QwgOAn0rXpFSgt5XyzkLQ== X-Received: by 2002:a17:903:17cb:b0:2b2:5a5a:4f2d with SMTP id d9443c01a7336-2b28176a472mr229498635ad.31.1775653918993; Wed, 08 Apr 2026 06:11:58 -0700 (PDT) Received: from user.. ([39.170.101.209]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2b27478d329sm197404705ad.34.2026.04.08.06.11.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Apr 2026 06:11:58 -0700 (PDT) From: Zxyan Zhu To: Mark Brown Cc: linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org, Zxyan Zhu Subject: [PATCH] regmap: debugfs: fix race condition in dummy name allocation Date: Wed, 8 Apr 2026 21:11:55 +0800 Message-Id: <20260408131155.2946395-1-zxyan0222@gmail.com> X-Mailer: git-send-email 2.34.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" Use IDA instead of a simple counter for generating unique dummy names. The previous implementation used dummy_index++ which is not atomic, leading to potential duplicate names when multiple threads call regmap_debugfs_init() concurrently with name=3D"dummy". --- drivers/base/regmap/internal.h | 1 + drivers/base/regmap/regmap-debugfs.c | 21 ++++++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/drivers/base/regmap/internal.h b/drivers/base/regmap/internal.h index 5bf993165438..e067890866c1 100644 --- a/drivers/base/regmap/internal.h +++ b/drivers/base/regmap/internal.h @@ -84,6 +84,7 @@ struct regmap { bool debugfs_disable; struct dentry *debugfs; const char *debugfs_name; + int debugfs_dummy_id; =20 unsigned int debugfs_reg_len; unsigned int debugfs_val_len; diff --git a/drivers/base/regmap/regmap-debugfs.c b/drivers/base/regmap/reg= map-debugfs.c index 5a46ce5fee72..18f1c60749fe 100644 --- a/drivers/base/regmap/regmap-debugfs.c +++ b/drivers/base/regmap/regmap-debugfs.c @@ -12,6 +12,7 @@ #include #include #include +#include =20 #include "internal.h" =20 @@ -20,7 +21,7 @@ struct regmap_debugfs_node { struct list_head link; }; =20 -static unsigned int dummy_index; +static DEFINE_IDA(dummy_ida); static struct dentry *regmap_debugfs_root; static LIST_HEAD(regmap_debugfs_early_list); static DEFINE_MUTEX(regmap_debugfs_early_lock); @@ -539,6 +540,7 @@ void regmap_debugfs_init(struct regmap *map) struct regmap_range_node *range_node; const char *devname =3D "dummy"; const char *name =3D map->name; + int id; =20 /* * Userspace can initiate reads from the hardware over debugfs. @@ -567,6 +569,7 @@ void regmap_debugfs_init(struct regmap *map) =20 INIT_LIST_HEAD(&map->debugfs_off_cache); mutex_init(&map->cache_lock); + map->debugfs_dummy_id =3D -1; =20 if (map->dev) devname =3D dev_name(map->dev); @@ -585,12 +588,16 @@ void regmap_debugfs_init(struct regmap *map) =20 if (!strcmp(name, "dummy")) { kfree(map->debugfs_name); - map->debugfs_name =3D kasprintf(GFP_KERNEL, "dummy%d", - dummy_index); - if (!map->debugfs_name) + id =3D ida_alloc(&dummy_ida, GFP_KERNEL); + if (id < 0) return; + map->debugfs_name =3D kasprintf(GFP_KERNEL, "dummy%d", id); + if (!map->debugfs_name) { + ida_free(&dummy_ida, id); + return; + } + map->debugfs_dummy_id =3D id; name =3D map->debugfs_name; - dummy_index++; } =20 map->debugfs =3D debugfs_create_dir(name, regmap_debugfs_root); @@ -660,6 +667,10 @@ void regmap_debugfs_exit(struct regmap *map) mutex_lock(&map->cache_lock); regmap_debugfs_free_dump_cache(map); mutex_unlock(&map->cache_lock); + if (map->debugfs_dummy_id >=3D 0) { + ida_free(&dummy_ida, map->debugfs_dummy_id); + map->debugfs_dummy_id =3D -1; + } kfree(map->debugfs_name); map->debugfs_name =3D NULL; } else { --=20 2.34.1