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 1/3] lib/igt_facts: Remove NULL and bool comparisions
Date: Fri, 25 Apr 2025 11:49:02 +0200	[thread overview]
Message-ID: <20250425094904.221857-1-peter.senna@linux.intel.com> (raw)

Remove comparisons to NULL, true, and false using ! when appropriate.
For example, from if (old_value == NULL && new_value != NULL)
               to if (!old_value && new_value)

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

diff --git a/lib/igt_facts.c b/lib/igt_facts.c
index 2e04a7c86..d38be0726 100644
--- a/lib/igt_facts.c
+++ b/lib/igt_facts.c
@@ -85,7 +85,7 @@ static void igt_facts_log(const char *last_test, const char *name,
 	char *uptime = NULL;
 	const char *before_tests = "before any test";
 
-	if (old_value == NULL && new_value == NULL)
+	if (!old_value && !new_value)
 		return;
 
 	if (clock_gettime(CLOCK_BOOTTIME, &uptime_ts) != 0)
@@ -97,7 +97,7 @@ static void igt_facts_log(const char *last_test, const char *name,
 		 uptime_ts.tv_nsec / 1000);
 
 	/* New fact */
-	if (old_value == NULL && new_value != NULL) {
+	if (!old_value && new_value) {
 		igt_info("[%s] [FACT %s] new: %s: %s\n",
 			 uptime,
 			 last_test ? last_test : before_tests,
@@ -107,7 +107,7 @@ static void igt_facts_log(const char *last_test, const char *name,
 	}
 
 	/* Update fact */
-	if (old_value != NULL && new_value != NULL) {
+	if (old_value && new_value) {
 		igt_info("[%s] [FACT %s] changed: %s: %s -> %s\n",
 			 uptime,
 			 last_test ? last_test : before_tests,
@@ -118,7 +118,7 @@ static void igt_facts_log(const char *last_test, const char *name,
 	}
 
 	/* Deleted fact */
-	if (old_value != NULL && new_value == NULL) {
+	if (old_value && !new_value) {
 		igt_info("[%s] [FACT %s] deleted: %s: %s\n",
 			 uptime,
 			 last_test ? last_test : before_tests,
@@ -213,7 +213,7 @@ static bool igt_facts_list_add(const char *name,
 	igt_fact *new_fact = NULL, *old_fact = NULL;
 	bool logged = false;
 
-	if (name == NULL || value == NULL)
+	if (!name || !value)
 		return false;
 
 	old_fact = igt_facts_list_get(name, head);
@@ -228,7 +228,7 @@ static bool igt_facts_list_add(const char *name,
 	}
 
 	new_fact = malloc(sizeof(igt_fact));
-	if (new_fact == NULL)
+	if (!new_fact)
 		return false;
 
 	new_fact->name = strdup(name);
@@ -523,7 +523,7 @@ static void igt_facts_scan_pci_drm_cards(const char *last_test)
 		 * If the device has '-' in the name, contine
 		 */
 		if (strncmp(drm_name, "card", 4) != 0 ||
-		    strchr(drm_name, '-') != NULL) {
+		    strchr(drm_name, '-')) {
 			udev_device_unref(drm_dev);
 			continue;
 		}
@@ -586,7 +586,7 @@ static void igt_facts_scan_kernel_taints(const char *last_test)
 
 	igt_facts_list_mark(head);
 
-	while ((reason = igt_explain_taints(&taints)) != NULL) {
+	while ((reason = igt_explain_taints(&taints))) {
 		/* Cut at the ':' to get only the taint name */
 		taint_name = strtok(strdup(reason), ":");
 		if (!taint_name)
@@ -677,18 +677,18 @@ static void igt_facts_test_add_get(struct igt_list_head *head)
 	const char *last_test = NULL;
 
 	ret = igt_facts_list_add(name, value, last_test, head);
-	igt_assert(ret == true);
+	igt_assert(ret);
 
 	/* Assert that there is one element in the linked list */
 	igt_assert_eq(igt_list_length(head), 1);
 
 	/* Assert that the element in the linked list is the one we added */
 	fact = igt_facts_list_get(name, head);
-	igt_assert(fact != NULL);
+	igt_assert(fact);
 	igt_assert_eq(strcmp(fact->name, name), 0);
 	igt_assert_eq(strcmp(fact->value, value), 0);
-	igt_assert(fact->present == true);
-	igt_assert(fact->last_test == NULL);
+	igt_assert(fact->present);
+	igt_assert(!fact->last_test);
 }
 
 /**
@@ -730,11 +730,11 @@ static void igt_facts_test_mark_and_sweep(struct igt_list_head *head)
 	/* Assert that the two updated elements are present */
 	fact = igt_facts_list_get(name1, head);
 	igt_assert(fact != NULL);
-	igt_assert(fact->present == true);
+	igt_assert(fact->present);
 
 	fact = igt_facts_list_get(name2, head);
 	igt_assert(fact != NULL);
-	igt_assert(fact->present == true);
+	igt_assert(fact->present);
 
 	/* Assert that the third element was deleted */
 	fact = igt_facts_list_get(name3, head);
@@ -764,9 +764,9 @@ void igt_facts_test(void)
 	igt_facts_test_add_get(&igt_facts_list_pci_gpu_head);
 
 	/* Assert that igt_facts_list_mark_and_sweep() cleans up the list */
-	igt_assert(igt_list_empty(&igt_facts_list_pci_gpu_head) == false);
+	igt_assert(!igt_list_empty(&igt_facts_list_pci_gpu_head));
 	igt_facts_list_mark_and_sweep(&igt_facts_list_pci_gpu_head);
-	igt_assert(igt_list_empty(&igt_facts_list_pci_gpu_head) == true);
+	igt_assert(igt_list_empty(&igt_facts_list_pci_gpu_head));
 
 	/* Test the mark and sweep pattern used to delete elements
 	 * from the list
-- 
2.43.0


             reply	other threads:[~2025-04-25  9:49 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-25  9:49 Peter Senna Tschudin [this message]
2025-04-25  9:49 ` [PATCH i-g-t 2/3] lib/igt_facts: Remove unnecessary extern from header Peter Senna Tschudin
2025-04-25 13:17   ` Kamil Konieczny
2025-04-25  9:49 ` [PATCH i-g-t 3/3] lib/igt_facts: Fix potential NULL pointer dereference Peter Senna Tschudin
2025-04-25 13:20   ` Kamil Konieczny
2025-04-25 12:08 ` ✓ Xe.CI.BAT: success for series starting with [i-g-t,1/3] lib/igt_facts: Remove NULL and bool comparisions Patchwork
2025-04-25 13:17 ` [PATCH i-g-t 1/3] " Kamil Konieczny
2025-04-25 18:43 ` ✓ i915.CI.BAT: success for series starting with [i-g-t,1/3] " Patchwork
2025-04-26  0:07 ` ✗ i915.CI.Full: failure " Patchwork
2025-04-26  8:05   ` Peter Senna Tschudin

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=20250425094904.221857-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.