mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
To: Krzysztof Kozlowski <krzk@kernel.org>,
	Philipp Zabel <p.zabel@pengutronix.de>
Cc: linux-kernel@vger.kernel.org,
	Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Subject: [PATCH 07/15] reset: use lock guards in reset core
Date: Mon, 05 Jan 2026 15:15:26 +0100	[thread overview]
Message-ID: <20260105-reset-core-refactor-v1-7-ac443103498d@oss.qualcomm.com> (raw)
In-Reply-To: <20260105-reset-core-refactor-v1-0-ac443103498d@oss.qualcomm.com>

Simplify the locking code in reset core by using lock guard from
linux/cleanup.h.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
---
 drivers/reset/core.c | 51 +++++++++++++++++++++++----------------------------
 1 file changed, 23 insertions(+), 28 deletions(-)

diff --git a/drivers/reset/core.c b/drivers/reset/core.c
index 39bedf990223212998fa8ed4cda517529f94ee23..ffb811cbc6460b48dd833d3560d6538eea2fd5c0 100644
--- a/drivers/reset/core.c
+++ b/drivers/reset/core.c
@@ -130,9 +130,9 @@ int reset_controller_register(struct reset_controller_dev *rcdev)
 
 	INIT_LIST_HEAD(&rcdev->reset_control_head);
 
-	mutex_lock(&reset_list_mutex);
+	guard(mutex)(&reset_list_mutex);
+
 	list_add(&rcdev->list, &reset_controller_list);
-	mutex_unlock(&reset_list_mutex);
 
 	return 0;
 }
@@ -144,9 +144,9 @@ EXPORT_SYMBOL_GPL(reset_controller_register);
  */
 void reset_controller_unregister(struct reset_controller_dev *rcdev)
 {
-	mutex_lock(&reset_list_mutex);
+	guard(mutex)(&reset_list_mutex);
+
 	list_del(&rcdev->list);
-	mutex_unlock(&reset_list_mutex);
 }
 EXPORT_SYMBOL_GPL(reset_controller_unregister);
 
@@ -647,25 +647,20 @@ int reset_control_acquire(struct reset_control *rstc)
 	if (reset_control_is_array(rstc))
 		return reset_control_array_acquire(rstc_to_array(rstc));
 
-	mutex_lock(&reset_list_mutex);
+	guard(mutex)(&reset_list_mutex);
 
-	if (rstc->acquired) {
-		mutex_unlock(&reset_list_mutex);
+	if (rstc->acquired)
 		return 0;
-	}
 
 	list_for_each_entry(rc, &rstc->rcdev->reset_control_head, list) {
 		if (rstc != rc && rstc->id == rc->id) {
-			if (rc->acquired) {
-				mutex_unlock(&reset_list_mutex);
+			if (rc->acquired)
 				return -EBUSY;
-			}
 		}
 	}
 
 	rstc->acquired = true;
 
-	mutex_unlock(&reset_list_mutex);
 	return 0;
 }
 EXPORT_SYMBOL_GPL(reset_control_acquire);
@@ -1069,22 +1064,23 @@ __of_reset_control_get(struct device_node *node, const char *id, int index,
 		}
 	}
 
-	mutex_lock(&reset_list_mutex);
+	guard(mutex)(&reset_list_mutex);
+
 	rcdev = __reset_find_rcdev(&args, gpio_fallback);
 	if (!rcdev) {
 		rstc = ERR_PTR(-EPROBE_DEFER);
-		goto out_unlock;
+		goto out_put;
 	}
 
 	if (WARN_ON(args.args_count != rcdev->of_reset_n_cells)) {
 		rstc = ERR_PTR(-EINVAL);
-		goto out_unlock;
+		goto out_put;
 	}
 
 	rstc_id = rcdev->of_xlate(rcdev, &args);
 	if (rstc_id < 0) {
 		rstc = ERR_PTR(rstc_id);
-		goto out_unlock;
+		goto out_put;
 	}
 
 	flags &= ~RESET_CONTROL_FLAGS_BIT_OPTIONAL;
@@ -1092,8 +1088,6 @@ __of_reset_control_get(struct device_node *node, const char *id, int index,
 	/* reset_list_mutex also protects the rcdev's reset_control list */
 	rstc = __reset_control_get_internal(rcdev, rstc_id, flags);
 
-out_unlock:
-	mutex_unlock(&reset_list_mutex);
 out_put:
 	of_node_put(args.np);
 
@@ -1135,10 +1129,11 @@ int __reset_control_bulk_get(struct device *dev, int num_rstcs,
 	return 0;
 
 err:
-	mutex_lock(&reset_list_mutex);
+	guard(mutex)(&reset_list_mutex);
+
 	while (i--)
 		__reset_control_put_internal(rstcs[i].rstc);
-	mutex_unlock(&reset_list_mutex);
+
 	return ret;
 }
 EXPORT_SYMBOL_GPL(__reset_control_bulk_get);
@@ -1147,10 +1142,10 @@ static void reset_control_array_put(struct reset_control_array *resets)
 {
 	int i;
 
-	mutex_lock(&reset_list_mutex);
+	guard(mutex)(&reset_list_mutex);
+
 	for (i = 0; i < resets->num_rstcs; i++)
 		__reset_control_put_internal(resets->rstc[i]);
-	mutex_unlock(&reset_list_mutex);
 	kfree(resets);
 }
 
@@ -1168,9 +1163,9 @@ void reset_control_put(struct reset_control *rstc)
 		return;
 	}
 
-	mutex_lock(&reset_list_mutex);
+	guard(mutex)(&reset_list_mutex);
+
 	__reset_control_put_internal(rstc);
-	mutex_unlock(&reset_list_mutex);
 }
 EXPORT_SYMBOL_GPL(reset_control_put);
 
@@ -1181,10 +1176,10 @@ EXPORT_SYMBOL_GPL(reset_control_put);
  */
 void reset_control_bulk_put(int num_rstcs, struct reset_control_bulk_data *rstcs)
 {
-	mutex_lock(&reset_list_mutex);
+	guard(mutex)(&reset_list_mutex);
+
 	while (num_rstcs--)
 		__reset_control_put_internal(rstcs[num_rstcs].rstc);
-	mutex_unlock(&reset_list_mutex);
 }
 EXPORT_SYMBOL_GPL(reset_control_bulk_put);
 
@@ -1403,10 +1398,10 @@ of_reset_control_array_get(struct device_node *np, enum reset_control_flags flag
 	return &resets->base;
 
 err_rst:
-	mutex_lock(&reset_list_mutex);
+	guard(mutex)(&reset_list_mutex);
+
 	while (--i >= 0)
 		__reset_control_put_internal(resets->rstc[i]);
-	mutex_unlock(&reset_list_mutex);
 
 	kfree(resets);
 

-- 
2.47.3


  parent reply	other threads:[~2026-01-05 14:16 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-05 14:15 [PATCH 00/15] reset: major reset core refactoring Bartosz Golaszewski
2026-01-05 14:15 ` [PATCH 01/15] reset: gpio: remove unneeded OF-node put Bartosz Golaszewski
2026-01-08  9:02   ` Philipp Zabel
2026-01-05 14:15 ` [PATCH 02/15] reset: gpio: add a devlink between reset-gpio and its consumer Bartosz Golaszewski
2026-01-08  9:02   ` Philipp Zabel
2026-01-05 14:15 ` [PATCH 03/15] reset: gpio: simplify fallback device matching Bartosz Golaszewski
2026-01-08  9:26   ` Philipp Zabel
2026-01-05 14:15 ` [PATCH 04/15] reset: gpio: remove unneeded auxiliary_set_drvdata() Bartosz Golaszewski
2026-01-08  9:27   ` Philipp Zabel
2026-01-05 14:15 ` [PATCH 05/15] reset: warn on reset-gpio release Bartosz Golaszewski
2026-01-05 14:15 ` [PATCH 06/15] reset: fold ida_alloc() into reset_create_gpio_aux_device() Bartosz Golaszewski
2026-01-05 14:15 ` Bartosz Golaszewski [this message]
2026-01-08  9:39   ` [PATCH 07/15] reset: use lock guards in reset core Philipp Zabel
2026-01-05 14:15 ` [PATCH 08/15] reset: remove unneeded include Bartosz Golaszewski
2026-01-08  9:44   ` Philipp Zabel
2026-01-08 14:13     ` Bartosz Golaszewski
2026-01-05 14:15 ` [PATCH 09/15] reset: handle removing supplier before consumers Bartosz Golaszewski
2026-01-05 14:15 ` [PATCH 10/15] reset: protect struct reset_controller_dev with its own mutex Bartosz Golaszewski
2026-01-05 14:15 ` [PATCH 11/15] reset: protect struct reset_control " Bartosz Golaszewski
2026-01-05 14:15 ` [PATCH 12/15] reset: convert of_reset_control_get_count() to using firmware nodes Bartosz Golaszewski
2026-01-05 14:15 ` [PATCH 13/15] reset: convert the core API " Bartosz Golaszewski
2026-01-05 14:15 ` [PATCH 14/15] reset: convert reset core " Bartosz Golaszewski
2026-01-05 14:15 ` [PATCH 15/15] reset: gpio: make the driver fwnode-agnostic Bartosz Golaszewski

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=20260105-reset-core-refactor-v1-7-ac443103498d@oss.qualcomm.com \
    --to=bartosz.golaszewski@oss.qualcomm.com \
    --cc=krzk@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=p.zabel@pengutronix.de \
    /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

all inboxes | Powered by JetHome®