public inbox for igt-dev@lists.freedesktop.org
 help / color / mirror / Atom feed
* [igt-dev] [PATCH i-g-t] tools/i915-perf: Fix compiler warning
@ 2020-02-20 13:12 Petri Latvala
  2020-02-20 14:47 ` [igt-dev] ✓ Fi.CI.BAT: success for " Patchwork
  2020-02-22 18:01 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork
  0 siblings, 2 replies; 4+ messages in thread
From: Petri Latvala @ 2020-02-20 13:12 UTC (permalink / raw)
  To: igt-dev; +Cc: Petri Latvala

Use flexible array member in the first struct instead of two structs
and a 0-length array so compiler knows we really meant to read and
write past it.

Signed-off-by: Petri Latvala <petri.latvala@intel.com>
Cc: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
---
 tools/i915-perf/i915_perf_control.c           | 24 +++++++------------
 tools/i915-perf/i915_perf_recorder.c          |  7 ++++--
 tools/i915-perf/i915_perf_recorder_commands.h |  5 +---
 3 files changed, 15 insertions(+), 21 deletions(-)

diff --git a/tools/i915-perf/i915_perf_control.c b/tools/i915-perf/i915_perf_control.c
index a8d0d30f..3722f2b1 100644
--- a/tools/i915-perf/i915_perf_control.c
+++ b/tools/i915-perf/i915_perf_control.c
@@ -91,28 +91,22 @@ main(int argc, char *argv[])
 		if (dump_file[0] == '/') {
 			uint32_t total_len =
 				sizeof(struct recorder_command_base) + strlen(dump_file) + 1;
-			struct {
-				struct recorder_command_base base;
-				struct recorder_command_dump dump;
-			} *data = malloc(total_len);
+			struct recorder_command_base *data = malloc(total_len);
 
-			data->base.command = RECORDER_COMMAND_DUMP;
-			data->base.size = total_len;
-			snprintf((char *) data->dump.path, strlen(dump_file) + 1, "%s", dump_file);
+			data->command = RECORDER_COMMAND_DUMP;
+			data->size = total_len;
+			snprintf((char *) data->path, strlen(dump_file) + 1, "%s", dump_file);
 
 			fwrite(data, total_len, 1, command_fifo_file);
 		} else {
 			char *cwd = get_current_dir_name();
 			uint32_t path_len = strlen(cwd) + 1 + strlen(dump_file) + 1;
 			uint32_t total_len = sizeof(struct recorder_command_base) + path_len;
-			struct {
-				struct recorder_command_base base;
-				struct recorder_command_dump dump;
-			} *data = malloc(total_len);
-
-			data->base.command = RECORDER_COMMAND_DUMP;
-			data->base.size = total_len;
-			snprintf((char *) data->dump.path, path_len, "%s/%s", cwd, dump_file);
+			struct recorder_command_base *data = malloc(total_len);
+
+			data->command = RECORDER_COMMAND_DUMP;
+			data->size = total_len;
+			snprintf((char *) data->path, path_len, "%s/%s", cwd, dump_file);
 
 			fwrite(data, total_len, 1, command_fifo_file);
 		}
diff --git a/tools/i915-perf/i915_perf_recorder.c b/tools/i915-perf/i915_perf_recorder.c
index 760cabf1..bd477746 100644
--- a/tools/i915-perf/i915_perf_recorder.c
+++ b/tools/i915-perf/i915_perf_recorder.c
@@ -605,12 +605,15 @@ read_command_file(struct recording_context *ctx)
 	switch (header.command) {
 	case RECORDER_COMMAND_DUMP: {
 		uint32_t len = header.size - sizeof(header), offset = 0;
-		struct recorder_command_dump *dump = malloc(len);
+		struct recorder_command_base *dump = malloc(sizeof(header) + len);
 		FILE *file;
 
+		/* Not really needed since current code only accesses dump->path but for completeness... */
+		memcpy(dump, &header, sizeof(header));
+
 		while (offset < len &&
 		       ((ret = read(ctx->command_fifo_fd,
-				    (void *) dump + offset, len - offset)) > 0
+				    (void *) dump->path + offset, len - offset)) > 0
 			|| errno == EAGAIN)) {
 			if (ret > 0)
 				offset += ret;
diff --git a/tools/i915-perf/i915_perf_recorder_commands.h b/tools/i915-perf/i915_perf_recorder_commands.h
index 4855d80f..5d84ca82 100644
--- a/tools/i915-perf/i915_perf_recorder_commands.h
+++ b/tools/i915-perf/i915_perf_recorder_commands.h
@@ -32,8 +32,5 @@ enum recorder_command {
 struct recorder_command_base {
 	uint32_t command;
 	uint32_t size;
-};
-
-struct recorder_command_dump {
-	uint8_t path[0];
+	uint8_t path[];
 };
-- 
2.20.1

_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

^ permalink raw reply related	[flat|nested] 4+ messages in thread
* [igt-dev] [PATCH i-g-t] tools/i915-perf: Fix compiler warning
@ 2020-02-21 10:38 Petri Latvala
  0 siblings, 0 replies; 4+ messages in thread
From: Petri Latvala @ 2020-02-21 10:38 UTC (permalink / raw)
  To: igt-dev; +Cc: Petri Latvala

Remove the _dump half of the pair of recorder command structs and use
a plain array of uint8_ts instead. Leave the struct in a comment to
act as documentation.

As a drive-by fix, add include guards to i915_perf_recorder_commands.h

Signed-off-by: Petri Latvala <petri.latvala@intel.com>
Acked-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
---
 tools/i915-perf/i915_perf_control.c           |  8 ++++----
 tools/i915-perf/i915_perf_recorder.c          | 10 +++++-----
 tools/i915-perf/i915_perf_recorder_commands.h | 11 ++++++++++-
 3 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/tools/i915-perf/i915_perf_control.c b/tools/i915-perf/i915_perf_control.c
index a8d0d30f..be5996c0 100644
--- a/tools/i915-perf/i915_perf_control.c
+++ b/tools/i915-perf/i915_perf_control.c
@@ -93,12 +93,12 @@ main(int argc, char *argv[])
 				sizeof(struct recorder_command_base) + strlen(dump_file) + 1;
 			struct {
 				struct recorder_command_base base;
-				struct recorder_command_dump dump;
+				uint8_t dump[];
 			} *data = malloc(total_len);
 
 			data->base.command = RECORDER_COMMAND_DUMP;
 			data->base.size = total_len;
-			snprintf((char *) data->dump.path, strlen(dump_file) + 1, "%s", dump_file);
+			snprintf((char *) data->dump, strlen(dump_file) + 1, "%s", dump_file);
 
 			fwrite(data, total_len, 1, command_fifo_file);
 		} else {
@@ -107,12 +107,12 @@ main(int argc, char *argv[])
 			uint32_t total_len = sizeof(struct recorder_command_base) + path_len;
 			struct {
 				struct recorder_command_base base;
-				struct recorder_command_dump dump;
+				uint8_t dump[];
 			} *data = malloc(total_len);
 
 			data->base.command = RECORDER_COMMAND_DUMP;
 			data->base.size = total_len;
-			snprintf((char *) data->dump.path, path_len, "%s/%s", cwd, dump_file);
+			snprintf((char *) data->dump, path_len, "%s/%s", cwd, dump_file);
 
 			fwrite(data, total_len, 1, command_fifo_file);
 		}
diff --git a/tools/i915-perf/i915_perf_recorder.c b/tools/i915-perf/i915_perf_recorder.c
index 760cabf1..6bbc451e 100644
--- a/tools/i915-perf/i915_perf_recorder.c
+++ b/tools/i915-perf/i915_perf_recorder.c
@@ -605,7 +605,7 @@ read_command_file(struct recording_context *ctx)
 	switch (header.command) {
 	case RECORDER_COMMAND_DUMP: {
 		uint32_t len = header.size - sizeof(header), offset = 0;
-		struct recorder_command_dump *dump = malloc(len);
+		uint8_t *dump = malloc(len);
 		FILE *file;
 
 		while (offset < len &&
@@ -616,9 +616,9 @@ read_command_file(struct recording_context *ctx)
 				offset += ret;
 		}
 
-		fprintf(stdout, "Writing circular buffer to %s\n", dump->path);
+		fprintf(stdout, "Writing circular buffer to %s\n", dump);
 
-		file = fopen((const char *) dump->path, "w+");
+		file = fopen((const char *) dump, "w+");
 		if (file) {
 			struct chunk chunks[2];
 
@@ -634,11 +634,11 @@ read_command_file(struct recording_context *ctx)
 			     fwrite(chunks[1].data, chunks[1].len, 1, file) != 1) ||
 			    !write_correlation_timestamps(file, ctx->drm_fd)) {
 				fprintf(stderr, "Unable to write circular buffer data in file '%s'\n",
-					dump->path);
+					dump);
 			}
 			fclose(file);
 		} else
-			fprintf(stderr, "Unable to write dump file '%s'\n", dump->path);
+			fprintf(stderr, "Unable to write dump file '%s'\n", dump);
 
 		free(dump);
 		break;
diff --git a/tools/i915-perf/i915_perf_recorder_commands.h b/tools/i915-perf/i915_perf_recorder_commands.h
index 4855d80f..d9353cfa 100644
--- a/tools/i915-perf/i915_perf_recorder_commands.h
+++ b/tools/i915-perf/i915_perf_recorder_commands.h
@@ -20,6 +20,9 @@
  * SOFTWARE.
  */
 
+#ifndef I915_PERF_RECORDER_COMMANDS_H
+#define I915_PERF_RECORDER_COMMANDS_H
+
 #include <stdint.h>
 
 #define I915_PERF_RECORD_FIFO_PATH "/tmp/.i915-perf-record"
@@ -31,9 +34,15 @@ enum recorder_command {
 
 struct recorder_command_base {
 	uint32_t command;
-	uint32_t size;
+	uint32_t size; /* size of recorder_command_base + dump in bytes */
 };
 
+/*
+ The dump after the recorder_command_base header:
+
 struct recorder_command_dump {
 	uint8_t path[0];
 };
+*/
+
+#endif
-- 
2.20.1

_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-02-22 18:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-02-20 13:12 [igt-dev] [PATCH i-g-t] tools/i915-perf: Fix compiler warning Petri Latvala
2020-02-20 14:47 ` [igt-dev] ✓ Fi.CI.BAT: success for " Patchwork
2020-02-22 18:01 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork
  -- strict thread matches above, loose matches on Subject: below --
2020-02-21 10:38 [igt-dev] [PATCH i-g-t] " Petri Latvala

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox