All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ocfs2: fix check if list iterator did find an element
@ 2022-03-19 20:31 Jakob Koschel
  2022-03-21  1:50   ` [Ocfs2-devel] " Joseph Qi via Ocfs2-devel
  0 siblings, 1 reply; 12+ messages in thread
From: Jakob Koschel @ 2022-03-19 20:31 UTC (permalink / raw)
  To: Mark Fasheh
  Cc: Jakob Koschel, linux-kernel, ocfs2-devel, Joel Becker, Joseph Qi,
	Andrew Morton, Geert Uytterhoeven, Masahiro Yamada, Miguel Ojeda,
	Mike Rapoport, Brian Johannesmeyer, Cristiano Giuffrida, Bos,
	H.J.

Instead of setting 'res' to NULL, it should only be set if
the suitable element was found.

In the original code 'res' would have been set to an incorrect pointer
if the list is empty.

In preparation to limit the scope of the list iterator to the list
traversal loop, use a dedicated pointer pointing to the found element [1].

Link: https://lore.kernel.org/all/YhdfEIwI4EdtHdym@kroah.com/
Signed-off-by: Jakob Koschel <jakobkoschel@gmail.com>
---
 fs/ocfs2/dlm/dlmdebug.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/fs/ocfs2/dlm/dlmdebug.c b/fs/ocfs2/dlm/dlmdebug.c
index d442cf5dda8a..be5e9ed7da8d 100644
--- a/fs/ocfs2/dlm/dlmdebug.c
+++ b/fs/ocfs2/dlm/dlmdebug.c
@@ -541,7 +541,7 @@ static void *lockres_seq_start(struct seq_file *m, loff_t *pos)
 	struct debug_lockres *dl = m->private;
 	struct dlm_ctxt *dlm = dl->dl_ctxt;
 	struct dlm_lock_resource *oldres = dl->dl_res;
-	struct dlm_lock_resource *res = NULL;
+	struct dlm_lock_resource *res = NULL, *iter;
 	struct list_head *track_list;

 	spin_lock(&dlm->track_lock);
@@ -556,11 +556,11 @@ static void *lockres_seq_start(struct seq_file *m, loff_t *pos)
 		}
 	}

-	list_for_each_entry(res, track_list, tracking) {
-		if (&res->tracking == &dlm->tracking_list)
-			res = NULL;
-		else
-			dlm_lockres_get(res);
+	list_for_each_entry(iter, track_list, tracking) {
+		if (&iter->tracking != &dlm->tracking_list) {
+			dlm_lockres_get(iter);
+			res = iter;
+		}
 		break;
 	}
 	spin_unlock(&dlm->track_lock);

base-commit: 34e047aa16c0123bbae8e2f6df33e5ecc1f56601
--
2.25.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2022-03-22  2:16 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-19 20:31 [PATCH] ocfs2: fix check if list iterator did find an element Jakob Koschel
2022-03-21  1:50 ` Joseph Qi
2022-03-21  1:50   ` [Ocfs2-devel] " Joseph Qi via Ocfs2-devel
2022-03-21 13:34   ` Jakob Koschel
2022-03-21 13:54     ` [Ocfs2-devel] " Dan Carpenter via Ocfs2-devel
2022-03-21 13:54       ` Dan Carpenter
2022-03-21 16:00       ` David Laight
2022-03-21 16:00         ` [Ocfs2-devel] " David Laight via Ocfs2-devel
2022-03-21 16:22         ` Dan Carpenter
2022-03-21 16:22           ` [Ocfs2-devel] " Dan Carpenter via Ocfs2-devel
2022-03-22  2:15     ` Joseph Qi via Ocfs2-devel
2022-03-22  2:15       ` Joseph Qi

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.