[32/33] Run igt_fortify_source.cocci

Submitted by Lyude Paul on June 10, 2019, 3:03 p.m.

Details

Message ID 20190610150321.512-32-lyude@redhat.com
State New
Headers show
Series "Series without cover letter" ( rev: 1 ) in IGT - Trybot

Not browsing as part of any series.

Commit Message

Lyude Paul June 10, 2019, 3:03 p.m.
From: Lyude Paul <lyude@redhat.com>

A couple of these changes had to be modified by hand so they wouldn't
call strlen() so often, but everything else was done by cocci.

Signed-off-by: Lyude Paul <lyude@redhat.com>
---
 lib/igt_frame.c          |  5 +++--
 lib/igt_sysfs.c          |  8 +++++---
 tests/i915/i915_pm_rps.c |  3 ++-
 tests/perf_pmu.c         |  9 ++++++---
 tests/prime_vgem.c       | 20 ++++++++++++--------
 5 files changed, 28 insertions(+), 17 deletions(-)

Patch hide | download patch | download mbox

diff --git a/lib/igt_frame.c b/lib/igt_frame.c
index 2b8dba0c..9781d1e3 100644
--- a/lib/igt_frame.c
+++ b/lib/igt_frame.c
@@ -64,7 +64,7 @@  static void igt_write_frame_to_png(cairo_surface_t *surface, int fd,
 	const char *test_name;
 	const char *subtest_name;
 	cairo_status_t status;
-	int index;
+	int index, len;
 
 	test_name = igt_test_name();
 	subtest_name = igt_subtest_name();
@@ -89,7 +89,8 @@  static void igt_write_frame_to_png(cairo_surface_t *surface, int fd,
 		path[index++] = '\n';
 		path[index] = '\0';
 
-		write(fd, path, strlen(path));
+		len = strlen(path);
+		igt_assert_eq(write(fd, path, len), len);
 	}
 }
 
diff --git a/lib/igt_sysfs.c b/lib/igt_sysfs.c
index 2d8ae0ab..c8ecfaf5 100644
--- a/lib/igt_sysfs.c
+++ b/lib/igt_sysfs.c
@@ -616,8 +616,10 @@  static char fbcon_cursor_blink_prev_value[2];
 
 static void fbcon_cursor_blink_restore(int sig)
 {
-	write(fbcon_cursor_blink_fd, fbcon_cursor_blink_prev_value,
-	      strlen(fbcon_cursor_blink_prev_value) + 1);
+	const size_t len = strlen(fbcon_cursor_blink_prev_value) + 1;
+
+	igt_assert_eq(write(fbcon_cursor_blink_fd,
+			    fbcon_cursor_blink_prev_value, len), len);
 	close(fbcon_cursor_blink_fd);
 }
 
@@ -650,6 +652,6 @@  void fbcon_blink_enable(bool enable)
 	}
 
 	r = snprintf(buffer, sizeof(buffer), enable ? "1" : "0");
-	write(fd, buffer, r + 1);
+	igt_assert_eq(write(fd, buffer, r + 1), r + 1);
 	close(fd);
 }
diff --git a/tests/i915/i915_pm_rps.c b/tests/i915/i915_pm_rps.c
index 478c7be7..0194e28c 100644
--- a/tests/i915/i915_pm_rps.c
+++ b/tests/i915/i915_pm_rps.c
@@ -279,7 +279,8 @@  static void load_helper_run(enum load load)
 			spin[high_load] = __igt_spin_new(drm_fd);
 
 			if (lh.signal && high_load != prev_load) {
-				write(lh.link, &lh.signal, sizeof(lh.signal));
+				igt_assert_eq(write(lh.link, &lh.signal, sizeof(lh.signal)),
+					      sizeof(lh.signal));
 				lh.signal = false;
 			}
 			prev_load = high_load;
diff --git a/tests/perf_pmu.c b/tests/perf_pmu.c
index a967d369..edff854f 100644
--- a/tests/perf_pmu.c
+++ b/tests/perf_pmu.c
@@ -1640,7 +1640,8 @@  accuracy(int gem_fd, const struct intel_execution_engine2 *e,
 				 100 * expected, target_busy_pct,
 				 avg, sqrt(var / n));
 
-			write(link[1], &expected, sizeof(expected));
+			igt_assert_eq(write(link[1], &expected, sizeof(expected)),
+				      sizeof(expected));
 		}
 
 		igt_spin_free(gem_fd, spin);
@@ -1649,12 +1650,14 @@  accuracy(int gem_fd, const struct intel_execution_engine2 *e,
 	fd = open_pmu(I915_PMU_ENGINE_BUSY(e->class, e->instance));
 
 	/* Let the child run. */
-	read(link[0], &expected, sizeof(expected));
+	igt_assert_eq(read(link[0], &expected, sizeof(expected)),
+		      sizeof(expected));
 	assert_within(100.0 * expected, target_busy_pct, 5);
 
 	/* Collect engine busyness for an interesting part of child runtime. */
 	val[0] = __pmu_read_single(fd, &ts[0]);
-	read(link[0], &expected, sizeof(expected));
+	igt_assert_eq(read(link[0], &expected, sizeof(expected)),
+		      sizeof(expected));
 	val[1] = __pmu_read_single(fd, &ts[1]);
 	close(fd);
 
diff --git a/tests/prime_vgem.c b/tests/prime_vgem.c
index 69ae8c9b..89e269e2 100644
--- a/tests/prime_vgem.c
+++ b/tests/prime_vgem.c
@@ -87,8 +87,10 @@  static void test_fence_read(int i915, int vgem)
 			gem_read(i915, handle, 4096*i, &tmp, sizeof(tmp));
 			igt_assert_eq(tmp, 0);
 		}
-		write(master[1], &child, sizeof(child));
-		read(slave[0], &child, sizeof(child));
+		igt_assert_eq(write(master[1], &child, sizeof(child)),
+			      sizeof(child));
+		igt_assert_eq(read(slave[0], &child, sizeof(child)),
+			      sizeof(child));
 		for (i = 0; i < 1024; i++) {
 			uint32_t tmp;
 			gem_read(i915, handle, 4096*i, &tmp, sizeof(tmp));
@@ -97,9 +99,9 @@  static void test_fence_read(int i915, int vgem)
 		gem_close(i915, handle);
 	}
 
-	read(master[0], &i, sizeof(i));
+	igt_assert_eq(read(master[0], &i, sizeof(i)), sizeof(i));
 	fence = vgem_fence_attach(vgem, &scratch, VGEM_FENCE_WRITE);
-	write(slave[1], &i, sizeof(i));
+	igt_assert_eq(write(slave[1], &i, sizeof(i)), sizeof(i));
 
 	ptr = vgem_mmap(vgem, &scratch, PROT_WRITE);
 	for (i = 0; i < 1024; i++)
@@ -143,8 +145,10 @@  static void test_fence_mmap(int i915, int vgem)
 		for (i = 0; i < 1024; i++)
 			igt_assert_eq(ptr[1024*i], 0);
 
-		write(master[1], &child, sizeof(child));
-		read(slave[0], &child, sizeof(child));
+		igt_assert_eq(write(master[1], &child, sizeof(child)),
+			      sizeof(child));
+		igt_assert_eq(read(slave[0], &child, sizeof(child)),
+			      sizeof(child));
 
 		gem_set_domain(i915, handle, I915_GEM_DOMAIN_GTT, 0);
 		for (i = 0; i < 1024; i++)
@@ -153,9 +157,9 @@  static void test_fence_mmap(int i915, int vgem)
 		gem_close(i915, handle);
 	}
 
-	read(master[0], &i, sizeof(i));
+	igt_assert_eq(read(master[0], &i, sizeof(i)), sizeof(i));
 	fence = vgem_fence_attach(vgem, &scratch, VGEM_FENCE_WRITE);
-	write(slave[1], &i, sizeof(i));
+	igt_assert_eq(write(slave[1], &i, sizeof(i)), sizeof(i));
 
 	ptr = vgem_mmap(vgem, &scratch, PROT_WRITE);
 	for (i = 0; i < 1024; i++)