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 2/2] regmap: mmio: Free the context if regmap init fails
Date: Mon, 30 Nov 2026 20:21:22 +0000 [thread overview]
Message-ID: <20261130-regmap-devm-ctx-v1-2-cfabbeaadee8@gmail.com> (raw)
In-Reply-To: <20261130-regmap-devm-ctx-v1-0-cfabbeaadee8@gmail.com>
From: Arun Iyengar <aiyengar1990@gmail.com>
The MMIO context is freed only by regmap_exit(), so it leaks, together
with its prepared clock, when __regmap_init() or __devm_regmap_init()
fails. Free it on that error.
The devm part needs the previous patch: without it a failed devres
add has already freed the context.
Fixes: 45f5ff8107a8 ("regmap: add MMIO bus support")
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
drivers/base/regmap/regmap-mmio.c | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/drivers/base/regmap/regmap-mmio.c b/drivers/base/regmap/regmap-mmio.c
index 6adbc950877c..a7eeb9498cd2 100644
--- a/drivers/base/regmap/regmap-mmio.c
+++ b/drivers/base/regmap/regmap-mmio.c
@@ -559,13 +559,18 @@ struct regmap *__regmap_init_mmio_clk(struct device *dev, const char *clk_id,
const char *lock_name)
{
struct regmap_mmio_context *ctx;
+ struct regmap *map;
ctx = regmap_mmio_gen_context(dev, clk_id, regs, config);
if (IS_ERR(ctx))
return ERR_CAST(ctx);
- return __regmap_init(dev, ®map_mmio, ctx, config,
- lock_key, lock_name);
+ map = __regmap_init(dev, ®map_mmio, ctx, config,
+ lock_key, lock_name);
+ if (IS_ERR(map))
+ regmap_mmio_free_context(ctx);
+
+ return map;
}
EXPORT_SYMBOL_GPL(__regmap_init_mmio_clk);
@@ -577,13 +582,18 @@ struct regmap *__devm_regmap_init_mmio_clk(struct device *dev,
const char *lock_name)
{
struct regmap_mmio_context *ctx;
+ struct regmap *map;
ctx = regmap_mmio_gen_context(dev, clk_id, regs, config);
if (IS_ERR(ctx))
return ERR_CAST(ctx);
- return __devm_regmap_init(dev, ®map_mmio, ctx, config,
- lock_key, lock_name);
+ map = __devm_regmap_init(dev, ®map_mmio, ctx, config,
+ lock_key, lock_name);
+ if (IS_ERR(map))
+ regmap_mmio_free_context(ctx);
+
+ return map;
}
EXPORT_SYMBOL_GPL(__devm_regmap_init_mmio_clk);
--
2.55.0
WARNING: multiple messages have this Message-ID (diff)
From: Arun Iyengar <aiyengar1990@gmail.com>
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 2/2] regmap: mmio: Free the context if regmap init fails
Date: Mon, 30 Nov 2026 20:21:22 +0000 [thread overview]
Message-ID: <20261130-regmap-devm-ctx-v1-2-cfabbeaadee8@gmail.com> (raw)
In-Reply-To: <20261130-regmap-devm-ctx-v1-0-cfabbeaadee8@gmail.com>
The MMIO context is freed only by regmap_exit(), so it leaks, together
with its prepared clock, when __regmap_init() or __devm_regmap_init()
fails. Free it on that error.
The devm part needs the previous patch: without it a failed devres
add has already freed the context.
Fixes: 45f5ff8107a8 ("regmap: add MMIO bus support")
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
drivers/base/regmap/regmap-mmio.c | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/drivers/base/regmap/regmap-mmio.c b/drivers/base/regmap/regmap-mmio.c
index 6adbc950877c..a7eeb9498cd2 100644
--- a/drivers/base/regmap/regmap-mmio.c
+++ b/drivers/base/regmap/regmap-mmio.c
@@ -559,13 +559,18 @@ struct regmap *__regmap_init_mmio_clk(struct device *dev, const char *clk_id,
const char *lock_name)
{
struct regmap_mmio_context *ctx;
+ struct regmap *map;
ctx = regmap_mmio_gen_context(dev, clk_id, regs, config);
if (IS_ERR(ctx))
return ERR_CAST(ctx);
- return __regmap_init(dev, ®map_mmio, ctx, config,
- lock_key, lock_name);
+ map = __regmap_init(dev, ®map_mmio, ctx, config,
+ lock_key, lock_name);
+ if (IS_ERR(map))
+ regmap_mmio_free_context(ctx);
+
+ return map;
}
EXPORT_SYMBOL_GPL(__regmap_init_mmio_clk);
@@ -577,13 +582,18 @@ struct regmap *__devm_regmap_init_mmio_clk(struct device *dev,
const char *lock_name)
{
struct regmap_mmio_context *ctx;
+ struct regmap *map;
ctx = regmap_mmio_gen_context(dev, clk_id, regs, config);
if (IS_ERR(ctx))
return ERR_CAST(ctx);
- return __devm_regmap_init(dev, ®map_mmio, ctx, config,
- lock_key, lock_name);
+ map = __devm_regmap_init(dev, ®map_mmio, ctx, config,
+ lock_key, lock_name);
+ if (IS_ERR(map))
+ regmap_mmio_free_context(ctx);
+
+ return map;
}
EXPORT_SYMBOL_GPL(__devm_regmap_init_mmio_clk);
--
2.55.0
next prev parent reply other threads:[~2026-11-30 20:21 UTC|newest]
Thread overview: 8+ 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
2026-11-30 20:21 ` [PATCH 1/2] regmap: Don't free the bus context when devm init fails Arun Iyengar via B4 Relay
2026-11-30 20:21 ` Arun Iyengar
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 " Arun Iyengar
2026-11-30 20:26 ` [PATCH 0/2] regmap: Fix bus context frees on init failure sashiko-bot
2026-12-01 13:42 ` Peng Fan
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-2-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.