linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mfd: dln2: replace usage of found with dedicated list iterator variable
@ 2022-03-24  7:14 Jakob Koschel
  0 siblings, 0 replies; only message in thread
From: Jakob Koschel @ 2022-03-24  7:14 UTC (permalink / raw)
  To: Lee Jones
  Cc: linux-kernel, Mike Rapoport, Brian Johannesmeyer,
	Cristiano Giuffrida, Bos, H.J.,
	Jakob Koschel

To move the list iterator variable into the list_for_each_entry_*()
macro in the future it should be avoided to use the list iterator
variable after the loop body.

To *never* use the list iterator variable after the loop it was
concluded to use a separate iterator variable instead of a
found boolean [1].

This removes the need to use a found variable and simply checking if
the variable was set, can determine if the break/goto was hit.

Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/
Signed-off-by: Jakob Koschel <jakobkoschel@gmail.com>
---
 drivers/mfd/dln2.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/mfd/dln2.c b/drivers/mfd/dln2.c
index 852129ea0766..741e8ae2d89d 100644
--- a/drivers/mfd/dln2.c
+++ b/drivers/mfd/dln2.c
@@ -163,23 +163,22 @@ EXPORT_SYMBOL(dln2_register_event_cb);
 void dln2_unregister_event_cb(struct platform_device *pdev, u16 id)
 {
 	struct dln2_dev *dln2 = dev_get_drvdata(pdev->dev.parent);
-	struct dln2_event_cb_entry *i;
+	struct dln2_event_cb_entry *i = NULL, *iter;
 	unsigned long flags;
-	bool found = false;
 
 	spin_lock_irqsave(&dln2->event_cb_lock, flags);
 
-	list_for_each_entry(i, &dln2->event_cb_list, list) {
-		if (i->id == id) {
-			list_del_rcu(&i->list);
-			found = true;
+	list_for_each_entry(iter, &dln2->event_cb_list, list) {
+		if (iter->id == id) {
+			list_del_rcu(&iter->list);
+			i = iter;
 			break;
 		}
 	}
 
 	spin_unlock_irqrestore(&dln2->event_cb_lock, flags);
 
-	if (found) {
+	if (i) {
 		synchronize_rcu();
 		kfree(i);
 	}

base-commit: f443e374ae131c168a065ea1748feac6b2e76613
-- 
2.25.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2022-03-24  7:15 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-24  7:14 [PATCH] mfd: dln2: replace usage of found with dedicated list iterator variable Jakob Koschel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).