public inbox for driver-core@lists.linux.dev
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Mark Brown <broonie@kernel.org>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	linux-kernel@vger.kernel.org, driver-core@lists.linux.dev
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	Danilo Krummrich <dakr@kernel.org>
Subject: [PATCH v5 1/2] regcache: Factor out regcache_hw_exit() helper
Date: Tue,  3 Mar 2026 10:26:24 +0100	[thread overview]
Message-ID: <20260303092820.2818138-2-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <20260303092820.2818138-1-andriy.shevchenko@linux.intel.com>

Factor out regcache_hw_exit() helper to make error and exit paths
clearer. This helps to avoid missing changes in case the code gets
shuffled in the future.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/base/regmap/regcache.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/drivers/base/regmap/regcache.c b/drivers/base/regmap/regcache.c
index 13c480b6e21d..329cdee1ae1c 100644
--- a/drivers/base/regmap/regcache.c
+++ b/drivers/base/regmap/regcache.c
@@ -131,6 +131,13 @@ static int regcache_hw_init(struct regmap *map, int count)
 	return ret;
 }
 
+static void regcache_hw_exit(struct regmap *map)
+{
+	kfree(map->reg_defaults);
+	if (map->cache_free)
+		kfree(map->reg_defaults_raw);
+}
+
 int regcache_init(struct regmap *map, const struct regmap_config *config)
 {
 	int count = 0;
@@ -245,9 +252,7 @@ int regcache_init(struct regmap *map, const struct regmap_config *config)
 		map->unlock(map->lock_arg);
 	}
 err_free:
-	kfree(map->reg_defaults);
-	if (map->cache_free)
-		kfree(map->reg_defaults_raw);
+	regcache_hw_exit(map);
 
 	return ret;
 }
@@ -259,9 +264,7 @@ void regcache_exit(struct regmap *map)
 
 	BUG_ON(!map->cache_ops);
 
-	kfree(map->reg_defaults);
-	if (map->cache_free)
-		kfree(map->reg_defaults_raw);
+	regcache_hw_exit(map);
 
 	if (map->cache_ops->exit) {
 		dev_dbg(map->dev, "Destroying %s cache\n",
-- 
2.50.1


  reply	other threads:[~2026-03-03  9:28 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-03  9:26 [PATCH v5 0/2] regcache: Avoid accessing non-initialised cache Andy Shevchenko
2026-03-03  9:26 ` Andy Shevchenko [this message]
2026-03-03  9:26 ` [PATCH v5 2/2] regcache: Move HW readback after cache initialisation Andy Shevchenko
2026-03-03 13:03   ` Mark Brown
2026-03-03 15:29     ` Andy Shevchenko
2026-03-03 19:20 ` [PATCH v5 0/2] regcache: Avoid accessing non-initialised cache Mark Brown

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=20260303092820.2818138-2-andriy.shevchenko@linux.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=broonie@kernel.org \
    --cc=dakr@kernel.org \
    --cc=driver-core@lists.linux.dev \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rafael@kernel.org \
    /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