[PATCH 1/1] drm/mm/selftests: fix wrong return type casting

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Function prepare_igt_frag() and get_insert_time() were casting
signed value to unsigned value before returning error.
So error check in igt_frag() would not work with unsigned
return value from get_insert_time() compared against negative
value.

Addresses-Coverity: ("Unsigned compared against 0, no effect")
Signed-off-by: Nirmoy Das <nirmoy.das@xxxxxxx>
Reported-by: Colin Ian King <colin.king@xxxxxxxxxxxxx>
---
 drivers/gpu/drm/selftests/test-drm_mm.c | 21 +++++++--------------
 1 file changed, 7 insertions(+), 14 deletions(-)

diff --git a/drivers/gpu/drm/selftests/test-drm_mm.c b/drivers/gpu/drm/selftests/test-drm_mm.c
index 3846b0f5bae3..3306d8bd0544 100644
--- a/drivers/gpu/drm/selftests/test-drm_mm.c
+++ b/drivers/gpu/drm/selftests/test-drm_mm.c
@@ -1041,13 +1041,12 @@ static int prepare_igt_frag(struct drm_mm *mm,
 {
 	unsigned int size = 4096;
 	unsigned int i;
-	u64 ret = -EINVAL;

 	for (i = 0; i < num_insert; i++) {
 		if (!expect_insert(mm, &nodes[i], size, 0, i,
 				   mode) != 0) {
 			pr_err("%s insert failed\n", mode->name);
-			goto out;
+			return -EINVAL;
 		}
 	}

@@ -1057,8 +1056,7 @@ static int prepare_igt_frag(struct drm_mm *mm,
 			drm_mm_remove_node(&nodes[i]);
 	}

-out:
-	return ret;
+	return 0;

 }

@@ -1070,21 +1068,16 @@ static u64 get_insert_time(struct drm_mm *mm,
 	unsigned int size = 8192;
 	ktime_t start;
 	unsigned int i;
-	u64 ret = -EINVAL;

 	start = ktime_get();
 	for (i = 0; i < num_insert; i++) {
 		if (!expect_insert(mm, &nodes[i], size, 0, i, mode) != 0) {
 			pr_err("%s insert failed\n", mode->name);
-			goto out;
+			return 0;
 		}
 	}

-	ret = ktime_to_ns(ktime_sub(ktime_get(), start));
-
-out:
-	return ret;
-
+	return ktime_to_ns(ktime_sub(ktime_get(), start));
 }

 static int igt_frag(void *ignored)
@@ -1119,17 +1112,17 @@ static int igt_frag(void *ignored)
 			continue;

 		ret = prepare_igt_frag(&mm, nodes, insert_size, mode);
-		if (!ret)
+		if (ret)
 			goto err;

 		insert_time1 = get_insert_time(&mm, insert_size,
 					       nodes + insert_size, mode);
-		if (insert_time1 < 0)
+		if (insert_time1 == 0)
 			goto err;

 		insert_time2 = get_insert_time(&mm, (insert_size * 2),
 					       nodes + insert_size * 2, mode);
-		if (insert_time2 < 0)
+		if (insert_time2 == 0)
 			goto err;

 		pr_info("%s fragmented insert of %u and %u insertions took %llu and %llu nsecs\n",
--
2.27.0

_______________________________________________
dri-devel mailing list
dri-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/dri-devel



[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux