All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peng Fan <peng.fan@oss.nxp.com>
To: Mark Brown <broonie@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	Danilo Krummrich <dakr@kernel.org>
Cc: linux-kernel@vger.kernel.org, driver-core@lists.linux.dev,
	Peng Fan <peng.fan@nxp.com>
Subject: Re: [PATCH RFC v2 2/4] regcache: use the regmap scoped lock guard
Date: Wed, 23 Sep 2026 20:31:47 +0800	[thread overview]
Message-ID: <arPGs0VioH17XEr5@shlinux89> (raw)
In-Reply-To: <20260922-regmap-lock-guard-v2-2-0c9d426427bd@nxp.com>

On Tue, Sep 22, 2026 at 07:10:56PM +0800, Peng Fan (OSS) wrote:
>From: Peng Fan <peng.fan@nxp.com>
>
...
>diff --git a/drivers/base/regmap/regcache.c b/drivers/base/regmap/regcache.c
>index 0d58d900a2ca..d030fcbe11d9 100644
>--- a/drivers/base/regmap/regcache.c
>+++ b/drivers/base/regmap/regcache.c
>@@ -225,9 +225,8 @@ int regcache_init(struct regmap *map, const struct regmap_config *config)
> 	if (map->cache_ops->init) {
> 		dev_dbg(map->dev, "Initializing %s cache\n",
> 			map->cache_ops->name);
>-		map->lock(map->lock_arg);
>-		ret = map->cache_ops->init(map);
>-		map->unlock(map->lock_arg);
>+		scoped_guard(regmap, map)
>+			ret = map->cache_ops->init(map);
> 		if (ret)
> 			goto err_free_reg_defaults;

Sashiko reported that goto and scoped_guard should not be used in one
function per cleanup.h.

Actually goto does not break scoped_guard. Anyway, to follow cleanup.h
rule, I may need to use a helper saying:

int regmap_map_cache_ops_init(regmap)
{
	guard(regmap)(map);

	return regmap->cache_ops->init(map);
}

I will look into make the helper to support other cache_ops in V3. and
avoid mix goto and scoped_guard in one function.

Thanks
Peng


> 	}
>@@ -246,9 +245,8 @@ int regcache_init(struct regmap *map, const struct regmap_config *config)
> 	if (map->cache_ops->populate &&
> 	    (map->num_reg_defaults || map->reg_default_cb)) {
> 		dev_dbg(map->dev, "Populating %s cache\n", map->cache_ops->name);
>-		map->lock(map->lock_arg);
>-		ret = map->cache_ops->populate(map);
>-		map->unlock(map->lock_arg);
>+		scoped_guard(regmap, map)
>+			ret = map->cache_ops->populate(map);
> 		if (ret)
> 			goto err_free;
> 	}
>@@ -259,9 +257,8 @@ int regcache_init(struct regmap *map, const struct regmap_config *config)
> err_exit:
> 	if (map->cache_ops->exit) {
> 		dev_dbg(map->dev, "Destroying %s cache\n", map->cache_ops->name);
>-		map->lock(map->lock_arg);
>-		map->cache_ops->exit(map);
>-		map->unlock(map->lock_arg);
>+		scoped_guard(regmap, map)
>+			map->cache_ops->exit(map);
> 	}
> err_free_reg_defaults:
> 	kfree(map->reg_defaults);
>@@ -281,9 +278,8 @@ void regcache_exit(struct regmap *map)
> 	if (map->cache_ops->exit) {
> 		dev_dbg(map->dev, "Destroying %s cache\n",
> 			map->cache_ops->name);
>-		map->lock(map->lock_arg);
>-		map->cache_ops->exit(map);
>-		map->unlock(map->lock_arg);
>+		scoped_guard(regmap, map)
>+			map->cache_ops->exit(map);
> 	}
> 
> 	kfree(map->reg_defaults);
>@@ -584,20 +580,14 @@ EXPORT_SYMBOL_GPL(regcache_sync_region);
> int regcache_drop_region(struct regmap *map, unsigned int min,
> 			 unsigned int max)
> {
>-	int ret = 0;
>-
> 	if (!map->cache_ops || !map->cache_ops->drop)
> 		return -EINVAL;
> 
>-	map->lock(map->lock_arg);
>+	guard(regmap)(map);
> 
> 	trace_regcache_drop_region(map, min, max);
> 
>-	ret = map->cache_ops->drop(map, min, max);
>-
>-	map->unlock(map->lock_arg);
>-
>-	return ret;
>+	return map->cache_ops->drop(map, min, max);
> }
> EXPORT_SYMBOL_GPL(regcache_drop_region);
> 
>@@ -615,12 +605,11 @@ EXPORT_SYMBOL_GPL(regcache_drop_region);
>  */
> void regcache_cache_only(struct regmap *map, bool enable)
> {
>-	map->lock(map->lock_arg);
>+	guard(regmap)(map);
> 	WARN_ON(map->cache_type != REGCACHE_NONE &&
> 		map->cache_bypass && enable);
> 	map->cache_only = enable;
> 	trace_regmap_cache_only(map, enable);
>-	map->unlock(map->lock_arg);
> }
> EXPORT_SYMBOL_GPL(regcache_cache_only);
> 
>@@ -639,10 +628,9 @@ EXPORT_SYMBOL_GPL(regcache_cache_only);
>  */
> void regcache_mark_dirty(struct regmap *map)
> {
>-	map->lock(map->lock_arg);
>+	guard(regmap)(map);
> 	map->cache_dirty = true;
> 	map->no_sync_defaults = true;
>-	map->unlock(map->lock_arg);
> }
> EXPORT_SYMBOL_GPL(regcache_mark_dirty);
> 
>@@ -659,11 +647,10 @@ EXPORT_SYMBOL_GPL(regcache_mark_dirty);
>  */
> void regcache_cache_bypass(struct regmap *map, bool enable)
> {
>-	map->lock(map->lock_arg);
>+	guard(regmap)(map);
> 	WARN_ON(map->cache_only && enable);
> 	map->cache_bypass = enable;
> 	trace_regmap_cache_bypass(map, enable);
>-	map->unlock(map->lock_arg);
> }
> EXPORT_SYMBOL_GPL(regcache_cache_bypass);
> 
>@@ -680,12 +667,10 @@ bool regcache_reg_cached(struct regmap *map, unsigned int reg)
> 	unsigned int val;
> 	int ret;
> 
>-	map->lock(map->lock_arg);
>+	guard(regmap)(map);
> 
> 	ret = regcache_read(map, reg, &val);
> 
>-	map->unlock(map->lock_arg);
>-
> 	return ret == 0;
> }
> EXPORT_SYMBOL_GPL(regcache_reg_cached);
>
>-- 
>2.51.0
>
>

  reply	other threads:[~2026-09-23 12:27 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-22 11:10 [PATCH RFC v2 0/4] regmap: convert map->lock/unlock users to a scoped guard Peng Fan (OSS)
2026-09-22 11:10 ` [PATCH RFC v2 1/4] regmap: convert lock/unlock " Peng Fan (OSS)
2026-09-22 11:10 ` [PATCH RFC v2 2/4] regcache: use the regmap scoped lock guard Peng Fan (OSS)
2026-09-23 12:31   ` Peng Fan [this message]
2026-09-22 11:10 ` [PATCH RFC v2 3/4] regcache: rbtree: " Peng Fan (OSS)
2026-09-22 11:10 ` [PATCH RFC v2 4/4] regmap: debugfs: " Peng Fan (OSS)

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=arPGs0VioH17XEr5@shlinux89 \
    --to=peng.fan@oss.nxp.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=peng.fan@nxp.com \
    --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 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.