From: Arun Iyengar via B4 Relay <devnull+aiyengar1990.gmail.com@kernel.org>
To: Mark Brown <broonie@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Danilo Krummrich <dakr@kernel.org>,
Johan Hovold <johan@kernel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>,
linux-kernel@vger.kernel.org, driver-core@lists.linux.dev,
Guenter Roeck <linux@roeck-us.net>,
linux-hwmon@vger.kernel.org, Xu Yilun <yilun.xu@intel.com>,
Arun Iyengar <aiyengar1990@gmail.com>
Subject: [PATCH 1/2] regmap: Don't free the bus context when devm init fails
Date: Mon, 30 Nov 2026 20:21:21 +0000 [thread overview]
Message-ID: <20261130-regmap-devm-ctx-v1-1-cfabbeaadee8@gmail.com> (raw)
In-Reply-To: <20261130-regmap-devm-ctx-v1-0-cfabbeaadee8@gmail.com>
From: Arun Iyengar <aiyengar1990@gmail.com>
Since the devres is added after __regmap_init(), a failure to add it
runs regmap_exit(), which frees the bus context. Callers that free
their context when __devm_regmap_init() fails (spi-avmm, sch56xx) then
free it twice.
Allocate the devres before __regmap_init() again.
Fixes: b1ef855c6260 ("regmap: Simplify devres handling")
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
drivers/base/regmap/regmap.c | 20 ++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)
diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index 0ba82fcc55bf..b4e07f8d6e91 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -1212,9 +1212,9 @@ struct regmap *__regmap_init(struct device *dev,
}
EXPORT_SYMBOL_GPL(__regmap_init);
-static void devm_regmap_release(void *regmap)
+static void devm_regmap_release(struct device *dev, void *res)
{
- regmap_exit(regmap);
+ regmap_exit(*(struct regmap **)res);
}
struct regmap *__devm_regmap_init(struct device *dev,
@@ -1224,17 +1224,21 @@ struct regmap *__devm_regmap_init(struct device *dev,
struct lock_class_key *lock_key,
const char *lock_name)
{
- struct regmap *regmap;
- int ret;
+ struct regmap **ptr, *regmap;
+
+ ptr = devres_alloc(devm_regmap_release, sizeof(*ptr), GFP_KERNEL);
+ if (!ptr)
+ return ERR_PTR(-ENOMEM);
regmap = __regmap_init(dev, bus, bus_context, config,
lock_key, lock_name);
- if (IS_ERR(regmap))
+ if (IS_ERR(regmap)) {
+ devres_free(ptr);
return regmap;
+ }
- ret = devm_add_action_or_reset(dev, devm_regmap_release, regmap);
- if (ret)
- return ERR_PTR(ret);
+ *ptr = regmap;
+ devres_add(dev, ptr);
return regmap;
}
--
2.55.0
next prev parent reply other threads:[~2026-11-30 20:21 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 20:21 [PATCH 0/2] regmap: Fix bus context frees on init failure Arun Iyengar via B4 Relay
2026-11-30 20:21 ` Arun Iyengar via B4 Relay [this message]
2026-11-30 20:21 ` [PATCH 2/2] regmap: mmio: Free the context if regmap init fails Arun Iyengar via B4 Relay
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261130-regmap-devm-ctx-v1-1-cfabbeaadee8@gmail.com \
--to=devnull+aiyengar1990.gmail.com@kernel.org \
--cc=aiyengar1990@gmail.com \
--cc=broonie@kernel.org \
--cc=dakr@kernel.org \
--cc=driver-core@lists.linux.dev \
--cc=gregkh@linuxfoundation.org \
--cc=johan@kernel.org \
--cc=krzysztof.kozlowski@oss.qualcomm.com \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=rafael@kernel.org \
--cc=yilun.xu@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox