All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Senna Tschudin <peter.senna@linux.intel.com>
To: igt-dev@lists.freedesktop.org
Cc: Peter Senna Tschudin <peter.senna@linux.intel.com>
Subject: [PATCH i-g-t] lib/igt_list: igt_list_empty() Detect uninitialized list
Date: Mon, 22 Sep 2025 18:23:40 +0200	[thread overview]
Message-ID: <20250922162340.20034-1-peter.senna@linux.intel.com> (raw)

Add a check to igt_list_empty() to return true if the list head pointer
or its next/prev pointers are NULL, preventing segfaults when operating
on uninitialized or potentially broken lists.

Signed-off-by: Peter Senna Tschudin <peter.senna@linux.intel.com>
---
 lib/igt_list.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/lib/igt_list.c b/lib/igt_list.c
index 37ae139c4..f77aef7dd 100644
--- a/lib/igt_list.c
+++ b/lib/igt_list.c
@@ -79,5 +79,9 @@ int igt_list_length(const struct igt_list_head *head)
 
 bool igt_list_empty(const struct igt_list_head *head)
 {
+	/* Detect uninitialized / potentially broken list */
+	if (!head || !head->next || !head->prev)
+		return true;
+
 	return head->next == head;
 }
-- 
2.43.0


             reply	other threads:[~2025-09-22 16:24 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-22 16:23 Peter Senna Tschudin [this message]
2025-09-22 19:49 ` ✓ Xe.CI.BAT: success for lib/igt_list: igt_list_empty() Detect uninitialized list Patchwork
2025-09-22 19:56 ` ✗ i915.CI.BAT: failure " Patchwork
2025-09-23  1:16 ` ✓ Xe.CI.Full: success " Patchwork
2025-09-23  8:14 ` [PATCH i-g-t] " Manszewski, Christoph
2025-09-23  9:20   ` Peter Senna Tschudin
2025-09-23  9:32     ` Manszewski, Christoph

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=20250922162340.20034-1-peter.senna@linux.intel.com \
    --to=peter.senna@linux.intel.com \
    --cc=igt-dev@lists.freedesktop.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 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.