summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorThomas Wood <thomas.wood@intel.com>2015-03-25 16:42:57 +0000
committerThomas Wood <thomas.wood@intel.com>2015-03-26 15:50:59 +0000
commit47f6b1305cc3752f318a555b932e194e1500c1d8 (patch)
tree18660c1faf9eadd6ef2bcbe9730eb1fa6c5ced7f /lib
parent0c4dd28d2d3b39216f9d041119ebf34cc44b7df7 (diff)
igt.cocci: check the return values of various functions
Add rules to fix unused-result warnings when compiling with _FORTIFY_SOURCE defined and apply them to the library and tests. Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch> Signed-off-by: Thomas Wood <thomas.wood@intel.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/igt.cocci28
-rw-r--r--lib/igt_core.c20
-rw-r--r--lib/igt_debugfs.c6
-rw-r--r--lib/igt_kms.c15
-rw-r--r--lib/intel_os.c2
-rw-r--r--lib/rendercopy_gen8.c2
-rw-r--r--lib/rendercopy_gen9.c2
7 files changed, 52 insertions, 23 deletions
diff --git a/lib/igt.cocci b/lib/igt.cocci
index 7dc398d0..156f0cf2 100644
--- a/lib/igt.cocci
+++ b/lib/igt.cocci
@@ -173,3 +173,31 @@ int E3, E4;
- igt_assert(E3 < E4);
+ igt_assert_lt(E3, E4);
)
+
+// avoid unused-result warnings when compiling with _FORTIFY_SOURCE defined
+@@
+identifier func =~ "^(read|write)$";
+expression list[2] E;
+expression size;
+@@
+-func(E, size);
++igt_assert_eq(func(E, size), size);
+
+@@
+expression ptr, size, nmemb, stream;
+@@
+-fread(ptr, size, nmemb, stream);
++igt_assert_eq(fread(ptr, size, nmemb, stream), nmemb);
+
+@@
+expression list E;
+@@
+-fgets(E);
++igt_assert_neq(fgets(E), NULL);
+
+@@
+identifier func =~ "^v?asprintf$";
+expression list E;
+@@
+-func(E);
++igt_assert_neq(func(E), -1);
diff --git a/lib/igt_core.c b/lib/igt_core.c
index 4cc040f5..783a2191 100644
--- a/lib/igt_core.c
+++ b/lib/igt_core.c
@@ -417,13 +417,15 @@ static void low_mem_killer_disable(bool disable)
/* writing 9999 to this module parameter effectively diables the
* low memory killer. This is not a real file, so we dont need to
* seek to the start or truncate it */
- write(fd, no_lowmem_killer, sizeof(no_lowmem_killer));
+ igt_assert_eq(write(fd, no_lowmem_killer, sizeof(no_lowmem_killer)),
+ sizeof(no_lowmem_killer));
close(fd);
} else {
/* just re-enstate the original settings */
fd = open(adj_fname, O_WRONLY);
igt_assert(fd != -1);
- write(fd, prev_adj_scores, adj_scores_len);
+ igt_assert_eq(write(fd, prev_adj_scores, adj_scores_len),
+ adj_scores_len);
close(fd);
}
@@ -864,7 +866,8 @@ void __igt_skip_check(const char *file, const int line,
char *err_str = NULL;
if (err)
- asprintf(&err_str, "Last errno: %i, %s\n", err, strerror(err));
+ igt_assert_neq(asprintf(&err_str, "Last errno: %i, %s\n", err, strerror(err)),
+ -1);
if (f) {
static char *buf;
@@ -874,7 +877,7 @@ void __igt_skip_check(const char *file, const int line,
free(buf);
va_start(args, f);
- vasprintf(&buf, f, args);
+ igt_assert_neq(vasprintf(&buf, f, args), -1);
va_end(args);
igt_skip("Test requirement not met in function %s, file %s:%i:\n"
@@ -1407,10 +1410,11 @@ static void fatal_sig_handler(int sig)
continue;
if (handled_signals[i].name_len) {
- write(STDERR_FILENO, "Received signal ", 16);
- write(STDERR_FILENO, handled_signals[i].name,
- handled_signals[i].name_len);
- write(STDERR_FILENO, ".\n", 2);
+ igt_assert_eq(write(STDERR_FILENO, "Received signal ", 16),
+ 16);
+ igt_assert_eq(write(STDERR_FILENO, handled_signals[i].name, handled_signals[i].name_len),
+ handled_signals[i].name_len);
+ igt_assert_eq(write(STDERR_FILENO, ".\n", 2), 2);
}
break;
diff --git a/lib/igt_debugfs.c b/lib/igt_debugfs.c
index 85c3f222..df7f453d 100644
--- a/lib/igt_debugfs.c
+++ b/lib/igt_debugfs.c
@@ -273,7 +273,7 @@ static bool igt_pipe_crc_do_start(igt_pipe_crc_t *pipe_crc)
sprintf(buf, "pipe %s %s", kmstest_pipe_name(pipe_crc->pipe),
pipe_crc_source_name(pipe_crc->source));
errno = 0;
- write(pipe_crc->ctl_fd, buf, strlen(buf));
+ igt_assert_eq(write(pipe_crc->ctl_fd, buf, strlen(buf)), strlen(buf));
if (errno != 0)
return false;
@@ -285,7 +285,7 @@ static void igt_pipe_crc_pipe_off(int fd, enum pipe pipe)
char buf[32];
sprintf(buf, "pipe %s none", kmstest_pipe_name(pipe));
- write(fd, buf, strlen(buf));
+ igt_assert_eq(write(fd, buf, strlen(buf)), strlen(buf));
}
static void igt_pipe_crc_reset(void)
@@ -417,7 +417,7 @@ void igt_pipe_crc_stop(igt_pipe_crc_t *pipe_crc)
char buf[32];
sprintf(buf, "pipe %s none", kmstest_pipe_name(pipe_crc->pipe));
- write(pipe_crc->ctl_fd, buf, strlen(buf));
+ igt_assert_eq(write(pipe_crc->ctl_fd, buf, strlen(buf)), strlen(buf));
}
static bool pipe_crc_init_from_string(igt_crc_t *crc, const char *line)
diff --git a/lib/igt_kms.c b/lib/igt_kms.c
index 9c131f08..6cb1f088 100644
--- a/lib/igt_kms.c
+++ b/lib/igt_kms.c
@@ -434,9 +434,8 @@ bool kmstest_force_connector(int drm_fd, drmModeConnector *connector,
break;
}
- asprintf(&path, "%s-%d/force",
- kmstest_connector_type_str(connector->connector_type),
- connector->connector_type_id);
+ igt_assert_neq(asprintf(&path, "%s-%d/force", kmstest_connector_type_str(connector->connector_type), connector->connector_type_id),
+ -1);
debugfs_fd = igt_debugfs_open(path, O_WRONLY | O_TRUNC);
if (debugfs_fd == -1) {
@@ -494,9 +493,8 @@ void kmstest_force_edid(int drm_fd, drmModeConnector *connector,
char *path;
int debugfs_fd, ret;
- asprintf(&path, "%s-%d/edid_override",
- kmstest_connector_type_str(connector->connector_type),
- connector->connector_type_id);
+ igt_assert_neq(asprintf(&path, "%s-%d/edid_override", kmstest_connector_type_str(connector->connector_type), connector->connector_type_id),
+ -1);
debugfs_fd = igt_debugfs_open(path, O_WRONLY | O_TRUNC);
free(path);
@@ -910,9 +908,8 @@ static void igt_output_refresh(igt_output_t *output)
if (!output->name) {
drmModeConnector *c = output->config.connector;
- asprintf(&output->name, "%s-%d",
- kmstest_connector_type_str(c->connector_type),
- c->connector_type_id);
+ igt_assert_neq(asprintf(&output->name, "%s-%d", kmstest_connector_type_str(c->connector_type), c->connector_type_id),
+ -1);
}
LOG(display, "%s: Selecting pipe %s\n", output->name,
diff --git a/lib/intel_os.c b/lib/intel_os.c
index 1badd3ec..3321a8de 100644
--- a/lib/intel_os.c
+++ b/lib/intel_os.c
@@ -255,7 +255,7 @@ intel_purge_vm_caches(void)
if (fd < 0)
return;
- write(fd, "3\n", 2);
+ igt_assert_eq(write(fd, "3\n", 2), 2);
close(fd);
}
diff --git a/lib/rendercopy_gen8.c b/lib/rendercopy_gen8.c
index baed7623..a7fc2c48 100644
--- a/lib/rendercopy_gen8.c
+++ b/lib/rendercopy_gen8.c
@@ -30,7 +30,7 @@
static void dump_batch(struct intel_batchbuffer *batch) {
int fd = open("/tmp/i965-batchbuffers.dump", O_WRONLY | O_CREAT, 0666);
if (fd != -1) {
- write(fd, batch->buffer, 4096);
+ igt_assert_eq(write(fd, batch->buffer, 4096), 4096);
fd = close(fd);
}
}
diff --git a/lib/rendercopy_gen9.c b/lib/rendercopy_gen9.c
index b7b133ca..0766192d 100644
--- a/lib/rendercopy_gen9.c
+++ b/lib/rendercopy_gen9.c
@@ -31,7 +31,7 @@
static void dump_batch(struct intel_batchbuffer *batch) {
int fd = open("/tmp/i965-batchbuffers.dump", O_WRONLY | O_CREAT, 0666);
if (fd != -1) {
- write(fd, batch->buffer, 4096);
+ igt_assert_eq(write(fd, batch->buffer, 4096), 4096);
fd = close(fd);
}
}