public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Danilo Krummrich <dakr@kernel.org>
To: gregkh@linuxfoundation.org, rafael@kernel.org
Cc: driver-core@lists.linux.dev, linux-kernel@vger.kernel.org,
	Danilo Krummrich <dakr@kernel.org>
Subject: [PATCH 6/7] devres: use guard(spinlock_irqsave) where applicable
Date: Tue,  3 Feb 2026 00:48:19 +0100	[thread overview]
Message-ID: <20260202235210.55176-7-dakr@kernel.org> (raw)
In-Reply-To: <20260202235210.55176-1-dakr@kernel.org>

Use guard(spinlock_irqsave)(&dev->devres_lock) where it improves the
code.

Some places still use manual spin_lock_irqsave() and spin_unlock() as
changing it to use a scoped_guard() would result in unnecessary churn.

Signed-off-by: Danilo Krummrich <dakr@kernel.org>
---
 drivers/base/devres.c | 23 ++++++-----------------
 1 file changed, 6 insertions(+), 17 deletions(-)

diff --git a/drivers/base/devres.c b/drivers/base/devres.c
index 2006fe411b49..58e2f82a30f6 100644
--- a/drivers/base/devres.c
+++ b/drivers/base/devres.c
@@ -228,12 +228,11 @@ void devres_for_each_res(struct device *dev, dr_release_t release,
 {
 	struct devres_node *node;
 	struct devres_node *tmp;
-	unsigned long flags;
 
 	if (!fn)
 		return;
 
-	spin_lock_irqsave(&dev->devres_lock, flags);
+	guard(spinlock_irqsave)(&dev->devres_lock);
 	list_for_each_entry_safe_reverse(node, tmp,
 			&dev->devres_head, entry) {
 		struct devres *dr = container_of(node, struct devres, node);
@@ -244,7 +243,6 @@ void devres_for_each_res(struct device *dev, dr_release_t release,
 			continue;
 		fn(dev, dr->data, data);
 	}
-	spin_unlock_irqrestore(&dev->devres_lock, flags);
 }
 EXPORT_SYMBOL_GPL(devres_for_each_res);
 
@@ -330,14 +328,12 @@ void *devres_find(struct device *dev, dr_release_t release,
 		  dr_match_t match, void *match_data)
 {
 	struct devres *dr;
-	unsigned long flags;
 
-	spin_lock_irqsave(&dev->devres_lock, flags);
+	guard(spinlock_irqsave)(&dev->devres_lock);
 	dr = find_dr(dev, release, match, match_data);
-	spin_unlock_irqrestore(&dev->devres_lock, flags);
-
 	if (dr)
 		return dr->data;
+
 	return NULL;
 }
 EXPORT_SYMBOL_GPL(devres_find);
@@ -396,18 +392,15 @@ void *devres_remove(struct device *dev, dr_release_t release,
 		    dr_match_t match, void *match_data)
 {
 	struct devres *dr;
-	unsigned long flags;
 
-	spin_lock_irqsave(&dev->devres_lock, flags);
+	guard(spinlock_irqsave)(&dev->devres_lock);
 	dr = find_dr(dev, release, match, match_data);
 	if (dr) {
 		list_del_init(&dr->node.entry);
 		devres_log(dev, &dr->node, "REM");
+		return dr->data;
 	}
-	spin_unlock_irqrestore(&dev->devres_lock, flags);
 
-	if (dr)
-		return dr->data;
 	return NULL;
 }
 EXPORT_SYMBOL_GPL(devres_remove);
@@ -655,17 +648,13 @@ static struct devres_group *find_group(struct device *dev, void *id)
 void devres_close_group(struct device *dev, void *id)
 {
 	struct devres_group *grp;
-	unsigned long flags;
-
-	spin_lock_irqsave(&dev->devres_lock, flags);
 
+	guard(spinlock_irqsave)(&dev->devres_lock);
 	grp = find_group(dev, id);
 	if (grp)
 		add_dr(dev, &grp->node[1]);
 	else
 		WARN_ON(1);
-
-	spin_unlock_irqrestore(&dev->devres_lock, flags);
 }
 EXPORT_SYMBOL_GPL(devres_close_group);
 
-- 
2.52.0


  parent reply	other threads:[~2026-02-02 23:52 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-02 23:48 [PATCH 0/7] Miscellaneous devres improvements Danilo Krummrich
2026-02-02 23:48 ` [PATCH 1/7] devres: fix missing node debug info in devm_krealloc() Danilo Krummrich
2026-02-02 23:48 ` [PATCH 2/7] devres: add devres_node_add() Danilo Krummrich
2026-02-02 23:48 ` [PATCH 3/7] devres: add devres_node_init() Danilo Krummrich
2026-02-02 23:48 ` [PATCH 4/7] devres: don't require ARCH_DMA_MINALIGN for devres actions Danilo Krummrich
2026-02-02 23:48 ` [PATCH 5/7] devres: add free_node callback to struct devres_node Danilo Krummrich
2026-02-02 23:48 ` Danilo Krummrich [this message]
2026-02-02 23:48 ` [PATCH 7/7] devres: remove unnecessary unlocks in devres_release_group() Danilo Krummrich
2026-03-12 15:13 ` [PATCH 0/7] Miscellaneous devres improvements Greg KH
2026-03-17 22:59 ` Danilo Krummrich

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=20260202235210.55176-7-dakr@kernel.org \
    --to=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