From nobody Mon Jun 15 06:29:21 2026 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (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 C9E7A288C81 for ; Thu, 9 Apr 2026 03:51:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775706686; cv=none; b=GDNm2M8tJdgsvKPoBWRE3kv6eu3Qv3vuJBkA8F9G1+glNsZjzo8lC5G6vczcBRnQF1/Krz14xq4gFhwp+myFk9q63VlZ73QhHxmPNddzSBmyWqBCXHwImIChRlOm+Vd3KVEMsP8X8xD0p3n6qkP7p9RWvzGkw7eqW5XevPDK++Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775706686; c=relaxed/simple; bh=jQeg69YQKYn0VFpcS13LkJvZxFfLvhw/HHMWSe69x3Q=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=eWvDlBr008h2c/Ya4PDH1ABI2+szOCNdvr5O5MnvTcRvKpujc43HJThpf560I6p5hH6Kjs+biyxBTlr5Tv09KfBYnX6ZRjDPp5IS/VTuxT1eekUnRC6ROSbB1YPfch+Y/Dq/AbHN8LxydhjBQV1Dqh0EfVXu+1H1ciA26tmtY58= 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=Et8IScEa; arc=none smtp.client-ip=209.85.210.169 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="Et8IScEa" Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-824c9da9928so571391b3a.3 for ; Wed, 08 Apr 2026 20:51:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775706685; x=1776311485; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lJUyfGutcgNErN7QvADBH8DmYA64xB1+DKMG5W68/Ys=; b=Et8IScEaRpHyftPsKzFYbnF64ccO4vFeUCDC2GvNxYnzZN3Z8GrW3P61t/HO27dwuB 1/euAZoRyjO4eyvIMUZuqZ0JNSakFWCRhI7bpIXPjX6IfcraA85AqA1UOo/HK08hd/Zg 2zS4bP9cnllW9ukC1eLNAR3ed56vrbZ0Ibc5Vta6+zqH1tCS3AObq78L603+rdFMvLzp n7WVB17HVZx6+8s4oqnRqOze/E4FlCpvP4qJ/9xKV7nhC52/c6zLEw5RHszKyJtym3qI +nYC6YOjNJqjZ7mRKC4lsaaNbYEsK0D6zhtOyq6GD5oxQvpfuPMrZvJqyLjA/yXIdL9U 9fiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775706685; x=1776311485; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=lJUyfGutcgNErN7QvADBH8DmYA64xB1+DKMG5W68/Ys=; b=UHTyE2Lb+KsAKsRUN7uTC9LoWGVkOWO5t5K4salrPesUQYeLGMV9Knz8j2mqg83j1w 6PQ9NHTX910KHH8iHUcKAo3I5i2j7S98rAr37YNGBzjVBP4KzDs/AmziyGk0/MY5l3sw 9Izfwp6LfzaVCPPaizQ/XIXiSXZKYq37gQ4Y+YibS4GY9A6M4lSw+StSYVGI4hAAHZBT PtMDOKgVQGkavFiYSx4ajzpFTZMK5dkahipGqm/OMs+XWH7IO8rwl+pTpHMrslRauXHT hnA9ULIPiVmqa3WG8SvSRabjkTO/UoZCTdVXlRmcaCa9XP50IZTglc7beq+hMkPyEDRc ztbQ== X-Forwarded-Encrypted: i=1; AJvYcCVkb1c4GehjmRCnq2OPG/TshvXelCc4RaH2BdTv5JlMdqlDSVbkgBtmUJzjDCEG8BtmwLQL7oRVKNW9MLU=@vger.kernel.org X-Gm-Message-State: AOJu0Yw8JY2XYTnFbkkFYXOgRRR17J1KsCLxFZY+3wQPFRlIbNCwDM6m wVmOxp6hQ42bbicuemfYVOO4UacpDvenlgv0afOVhf4e6Xjxw664KC72M+0uO/kw X-Gm-Gg: AeBDieukUgZkHbLOMsBtlF+MOa2oYFma4+Th4jQIktgOrMpCKeufQ7GPJClarJKUEJZ G9vZ902zkq2Z8MgwI0Hs7iLYfEHHH1qyqVY6uW67HF/R7kzQ3Uz8kEOsvBFUERtyygqIsNwbG9p lNfsHxVEfMVNQYEs/FKprNXuAW3pon5+fE2ju97Oa5KK47lC31IZ6gSwomQWzfVZNNW1SypXbRJ B/oi3RS0tGe92gp1V4sac3KDFkGkHx1i5L5dveKtfkINxkzAYoKfaXYsdGmx8bUTpaVUdDuauZ/ Bp4PFnuaV59ukGtoROGQIdwXjaobKooXvAwUtkYvgb2Eez7pPqLRNEzFZAyhOP7UM5ub4PpfsSf R1AZx0AIkxWG8HPUj9XkgMvZeZt50N5ANwrwR6sxJqzw369Or8AE91ObvwEnHc+BBPEX352WA5a bXFQFFTrJMKmDhk08D3qX0NHYPkA== X-Received: by 2002:a05:6a00:ab87:b0:82c:24a9:d5f1 with SMTP id d2e1a72fcca58-82d0db3f376mr23845609b3a.30.1775706685085; Wed, 08 Apr 2026 20:51:25 -0700 (PDT) Received: from user.. ([39.170.101.209]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-82cf9b27313sm22703207b3a.5.2026.04.08.20.51.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Apr 2026 20:51:24 -0700 (PDT) From: Zxyan Zhu To: Mark Brown , Greg Kroah-Hartman Cc: "Rafael J . Wysocki" , Danilo Krummrich , linux-kernel@vger.kernel.org, driver-core@lists.linux.dev, Zxyan Zhu Subject: [PATCH v2] regmap: debugfs: fix race condition in dummy name allocation Date: Thu, 9 Apr 2026 11:50:15 +0800 Message-Id: <20260409035015.950764-1-zxyan0222@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <2026040834-runaround-glass-8ea6@gregkh> References: <2026040834-runaround-glass-8ea6@gregkh> 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". Signed-off-by: Zxyan Zhu --- 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