From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 96E953B100A; Tue, 6 Oct 2026 07:03:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791270199; cv=none; b=eujAS00Q2PYgxp2Kzi2X8xc94jybhRR7tSGLTR3I0nTVYJVEcK61KbFwHLSS5nI4iejOP+pIEpMFplaRbX3Wlu/td28Zz4q07Idfs9gZE7JJjbPTeI7fkRBm+LQJOc1KLbZ/e4aLYHCh4qVnHW2+/9zgCBFjD5WU8fXoMQvJUA0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791270199; c=relaxed/simple; bh=cyIjSgiZBCj6qCcFCL7fETCO1R7toajPATwE4IXsxhw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=e11hc6ph4sN0G6DMQz4loDxebnXXByKuRlPyRVZFINuXkIStU1iSiPHgBCkt6czgP8CLh37+XEsdPU9HXZUcKqhDcyZuu1w9xXnAHX9xLeHVaJbuw9Vhm2KUdIdNhifNlTGDPlymNyhyClE5DMNB9Jy1p2OyUw3YGbRcproNPvI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WRHVCplf; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="WRHVCplf" Received: by smtp.kernel.org (Postfix) with ESMTPS id F1F6DC4AF61; Tue, 6 Oct 2026 07:03:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1791270199; bh=cyIjSgiZBCj6qCcFCL7fETCO1R7toajPATwE4IXsxhw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=WRHVCplf0RtJE5iq+RnT2aalRiuBACxZU2ZPiZNV4dltLlIVgmxhz2f9gQ7zd9iEp bkTfkBt3MwI/c4Lv7aMlGlN7AFsIWVXU+wkAE4+ERxZRVZD9wMLfdv0EPAnPdtLz5Q rgh+m+1UPhWMBA64vK0EJ3ywfTFLce0wtlYY8qiCdmeJQ7Lv8S3OKl1QjS9Z+K3hjf ZFu/0i1azpBzc/W16AIBMzIw6ob9IWatXio+Nltcdbh5qXisyUgR2K752dllJ6mupW ZY2vXhnH33hF+iGMB50LIBOuULgD8z1DK7qPHkLgk6WPfJPBoAqmWTNLulfVTAsgfW jV2gPQrOZGwDA== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id D2805CA5FED; Tue, 6 Oct 2026 07:03:18 +0000 (UTC) From: Michael Reeves via B4 Relay Date: Tue, 06 Oct 2026 18:03:15 +1100 Subject: [PATCH v3 1/2] regmap: Remove debugfs before cache teardown Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261006-regcache-lifecycle-submit-v3-1-37bdd82fd47c@gmail.com> References: <20261006-regcache-lifecycle-submit-v3-0-37bdd82fd47c@gmail.com> In-Reply-To: <20261006-regcache-lifecycle-submit-v3-0-37bdd82fd47c@gmail.com> To: Mark Brown , Alice Ryhl , Andrew Ballance Cc: Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich , "Liam R. Howlett" , linux-kernel@vger.kernel.org, driver-core@lists.linux.dev, maple-tree@lists.infradead.org, asahi@lists.linux.dev, linux-mm@kvack.org, Michael Reeves X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1791270197; l=2394; i=michael.reeves077@gmail.com; s=fedora-20260918; h=from:subject:message-id; bh=zFAOzXLct8D+NOZeYw7b3fI/ausJUSmG186K8w5WDHA=; b=VG8lSoGwLN4wbL7/VfkD0KRIMazF1RCvOO959lmDM+49vcgPxdzSDnJxUquAxrHKVHfvTmkFG 2T35AAhmJPNCmPKmopDCx18FC7Wex1MAsgMXon+PsqxqAX7TBAjVHU9 X-Developer-Key: i=michael.reeves077@gmail.com; a=ed25519; pk=VJ0TvyQ9TvfzYZa908YSE9kpkjFLLD5luv0bERu+boc= X-Endpoint-Received: by B4 Relay for michael.reeves077@gmail.com/fedora-20260918 with auth_id=1035 X-Original-From: Michael Reeves Reply-To: michael.reeves077@gmail.com From: Michael Reeves regmap_exit() and regmap_reinit_cache() destroy the register cache before removing debugfs. A concurrent debugfs cache operation can therefore access cache state after the backend exit callback starts freeing it. Remove debugfs before cache teardown, and clear the debugfs pointer after removal. During cache reinitialization, recreate debugfs only after the new cache initializes successfully. Signed-off-by: Michael Reeves --- drivers/base/regmap/regmap-debugfs.c | 1 + drivers/base/regmap/regmap.c | 15 +++++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/drivers/base/regmap/regmap-debugfs.c b/drivers/base/regmap/regmap-debugfs.c index 18f1c60749..9a09df2ba8 100644 --- a/drivers/base/regmap/regmap-debugfs.c +++ b/drivers/base/regmap/regmap-debugfs.c @@ -664,6 +664,7 @@ void regmap_debugfs_exit(struct regmap *map) { if (map->debugfs) { debugfs_remove_recursive(map->debugfs); + map->debugfs = NULL; mutex_lock(&map->cache_lock); regmap_debugfs_free_dump_cache(map); mutex_unlock(&map->cache_lock); diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c index e6e022b026..8e50a05ff0 100644 --- a/drivers/base/regmap/regmap.c +++ b/drivers/base/regmap/regmap.c @@ -1422,8 +1422,8 @@ int regmap_reinit_cache(struct regmap *map, const struct regmap_config *config) { int ret; - regcache_exit(map); regmap_debugfs_exit(map); + regcache_exit(map); map->max_register = config->max_register; map->max_register_is_set = map->max_register ?: config->max_register_is_0; @@ -1440,12 +1440,16 @@ int regmap_reinit_cache(struct regmap *map, const struct regmap_config *config) if (ret) return ret; - regmap_debugfs_init(map); - map->cache_bypass = false; map->cache_only = false; - return regcache_init(map, config); + ret = regcache_init(map, config); + if (ret) + return ret; + + regmap_debugfs_init(map); + + return 0; } EXPORT_SYMBOL_GPL(regmap_reinit_cache); @@ -1459,9 +1463,8 @@ void regmap_exit(struct regmap *map) struct regmap_async *async; regmap_detach_dev(map->dev, map); - regcache_exit(map); - regmap_debugfs_exit(map); + regcache_exit(map); regmap_range_exit(map); if (map->bus && map->bus->free_context) map->bus->free_context(map->bus_context); -- 2.55.0