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 <[email protected]>
---
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