Skip to contentSkip to conversation

Memory allocation fixes

PATCH In review Robert Foss 3 participants 11 messages Jan 19, 2017 – Jan 20, 2017 Library code

lore
Share & tools
lore
#0 lore raw

cover Memory allocation fixes

This series contains a few separate fixes mostly for memory allocations but also some small unrelated small fixes.

This series can be found here under the alloc_fixes_$VERSION:
https://git.collabora.com/cgit/user/robertfoss/intel-gpu-tools.git/

Robert Foss (6):
lib/igt_kms: Check memory allocations for failures lib/igt_kms: Add missing function declaration lib/igt_debugfs: Prevent buffer overflow
lib/igt_kms: Set free'd pointer to NULL tests/kms_cursor_legacy: Switch to using for_each_pipe construct lib/igt_kms: Fixed typo

 lib/igt_debugfs.c         |  6 ++++--
 lib/igt_kms.c             | 10 +++++++---
 lib/igt_kms.h             |  1 +
 tests/kms_cursor_legacy.c | 31 ++++++++++++++-----------------
 4 files changed, 26 insertions(+), 22 deletions(-)
Signature · 6 lines
2.11.0

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#1 lore raw

PATCH 1/6 lib/igt_kms: Check memory allocations for failures

Add missing descriptive igt_assert_t calls to calloc'd memory.

---
 lib/igt_kms.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
lib/igt_kms.c +3 -1
index 2c5a6e89..8c10568a 100644
@@ -1107,6 +1107,7 @@ void kmstest_edid_add_3d(const unsigned char *edid, size_t length,
 	*new_length = length + 128;
 
 	new_edid = calloc(*new_length, sizeof(char));
+	igt_assert_f(new_edid, "Failed to allocate %zu bytes for edid\n", sizeof(new_length));
 	memcpy(new_edid, edid, length);
 	*new_edid_ptr = new_edid;
 
@@ -1506,6 +1507,7 @@ void igt_display_init(igt_display_t *display, int drm_fd)
 	 */
 	display->n_pipes = resources->count_crtcs;
 	display->pipes = calloc(sizeof(igt_pipe_t), display->n_pipes);
+	igt_assert_f(display->pipes, "Failed to allocate memory for %d pipes\n", display->n_pipes);
 
 	drmSetClientCap(drm_fd, DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1);
 	is_atomic = drmSetClientCap(drm_fd, DRM_CLIENT_CAP_ATOMIC, 1);
@@ -1650,7 +1652,7 @@ void igt_display_init(igt_display_t *display, int drm_fd)
 	 */
 	display->n_outputs = resources->count_connectors;
 	display->outputs = calloc(display->n_outputs, sizeof(igt_output_t));
-	igt_assert(display->outputs);
+	igt_assert_f(display->outputs, "Failed to allocate memory for %d outputs\n", display->n_outputs);
 
 	for (i = 0; i < display->n_outputs; i++) {
 		igt_output_t *output = &display->outputs[i];
Signature · 6 lines
2.11.0

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#2 lore raw

PATCH 2/6 lib/igt_kms: Add missing function declaration

In reply to Robert Foss

Add missing declaration for kmstest_pipe_to_index to header.

---
 lib/igt_kms.h | 1 +
 1 file changed, 1 insertion(+)
lib/igt_kms.h +1 -0
index 81be77f5..64414a24 100644
@@ -180,6 +180,7 @@ bool kmstest_get_connector_config(int drm_fd, uint32_t connector_id,
 bool kmstest_probe_connector_config(int drm_fd, uint32_t connector_id,
 				    unsigned long crtc_idx_mask,
 				    struct kmstest_connector_config *config);
+int kmstest_pipe_to_index(char pipe);
 void kmstest_free_connector_config(struct kmstest_connector_config *config);
 
 void kmstest_set_connector_dpms(int fd, drmModeConnector *connector, int mode);
Signature · 6 lines
2.11.0

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#3 lore raw

PATCH 3/6 lib/igt_debugfs: Prevent buffer overflow

In reply to Robert Foss

buf array may overflow with when writing '\0' if
MAX_LINE_LEN bytes are read during read().

---
 lib/igt_debugfs.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
lib/igt_debugfs.c +4 -2
index d828687a..982573d7 100644
@@ -597,10 +597,12 @@ static int read_crc(igt_pipe_crc_t *pipe_crc, igt_crc_t *out)
 	bytes_read = read(pipe_crc->crc_fd, &buf, read_len);
 	igt_reset_timeout();
 
-	if (bytes_read < 0 && errno == EAGAIN) {
+	if (bytes_read < 0 && errno == EAGAIN)
 		igt_assert(pipe_crc->flags & O_NONBLOCK);
+
+	if (bytes_read < 0)
 		bytes_read = 0;
-	}
+
 	buf[bytes_read] = '\0';
 
 	if (bytes_read && !pipe_crc_init_from_string(pipe_crc, out, buf))
Signature · 6 lines
2.11.0

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#4 lore raw

PATCH 4/6 lib/igt_kms: Set free'd pointer to NULL

In reply to Robert Foss

Avoid double free's by setting the free'd pointer to NULL after free.

---
 lib/igt_kms.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
lib/igt_kms.c +3 -1
index 8c10568a..52e1f179 100644
@@ -1700,6 +1700,7 @@ static void igt_output_fini(igt_output_t *output)
 {
 	kmstest_free_connector_config(&output->config);
 	free(output->name);
+	output->name = NULL;
 }
 
 /**
@@ -1719,8 +1720,9 @@ void igt_display_fini(igt_display_t *display)
 	for (i = 0; i < display->n_outputs; i++)
 		igt_output_fini(&display->outputs[i]);
 	free(display->outputs);
-	free(display->pipes);
 	display->outputs = NULL;
+	free(display->pipes);
+	display->pipes = NULL;
 }
 
 static void igt_display_refresh(igt_display_t *display)
Signature · 6 lines
2.11.0

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#5 lore raw

PATCH 5/6 tests/kms_cursor_legacy: Switch to using for_each_pipe construct

In reply to Robert Foss

Avoid using hand-rolled construct for iterating over all pipes.

---
 tests/kms_cursor_legacy.c | 31 ++++++++++++++-----------------
 1 file changed, 14 insertions(+), 17 deletions(-)
tests/kms_cursor_legacy.c +14 -17
index 5e9f5f39..156bd0c7 100644
@@ -1360,6 +1360,7 @@ igt_main
 {
 	const int ncpus = sysconf(_SC_NPROCESSORS_ONLN);
 	igt_display_t display = { .drm_fd = -1 };
+	enum pipe pipe;
 	int i;
 
 	igt_skip_on_simulation();
@@ -1373,27 +1374,23 @@ igt_main
 	}
 
 	igt_subtest_group {
-		for (int n = 0; n < I915_MAX_PIPES; n++) {
+		for_each_pipe(&display, pipe) {
 			errno = 0;
 
-			igt_fixture {
-				igt_skip_on(n >= display.n_pipes);
-			}
-
-			igt_subtest_f("pipe-%s-single-bo", kmstest_pipe_name(n))
-				stress(&display, n, 1, DRM_MODE_CURSOR_BO, 20);
-			igt_subtest_f("pipe-%s-single-move", kmstest_pipe_name(n))
-				stress(&display, n, 1, DRM_MODE_CURSOR_MOVE, 20);
+			igt_subtest_f("pipe-%s-single-bo", kmstest_pipe_name(pipe))
+				stress(&display, pipe, 1, DRM_MODE_CURSOR_BO, 20);
+			igt_subtest_f("pipe-%s-single-move", kmstest_pipe_name(pipe))
+				stress(&display, pipe, 1, DRM_MODE_CURSOR_MOVE, 20);
 
-			igt_subtest_f("pipe-%s-forked-bo", kmstest_pipe_name(n))
-				stress(&display, n, ncpus, DRM_MODE_CURSOR_BO, 20);
-			igt_subtest_f("pipe-%s-forked-move", kmstest_pipe_name(n))
-				stress(&display, n, ncpus, DRM_MODE_CURSOR_MOVE, 20);
+			igt_subtest_f("pipe-%s-forked-bo", kmstest_pipe_name(pipe))
+				stress(&display, pipe, ncpus, DRM_MODE_CURSOR_BO, 20);
+			igt_subtest_f("pipe-%s-forked-move", kmstest_pipe_name(pipe))
+				stress(&display, pipe, ncpus, DRM_MODE_CURSOR_MOVE, 20);
 
-			igt_subtest_f("pipe-%s-torture-bo", kmstest_pipe_name(n))
-				stress(&display, n, -ncpus, DRM_MODE_CURSOR_BO, 20);
-			igt_subtest_f("pipe-%s-torture-move", kmstest_pipe_name(n))
-				stress(&display, n, -ncpus, DRM_MODE_CURSOR_MOVE, 20);
+			igt_subtest_f("pipe-%s-torture-bo", kmstest_pipe_name(pipe))
+				stress(&display, pipe, -ncpus, DRM_MODE_CURSOR_BO, 20);
+			igt_subtest_f("pipe-%s-torture-move", kmstest_pipe_name(pipe))
+				stress(&display, pipe, -ncpus, DRM_MODE_CURSOR_MOVE, 20);
 		}
 	}
 
Signature · 6 lines
2.11.0

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#6 lore raw

Re: [PATCH i-g-t v1 5/6] tests/kms_cursor_legacy: Switch to using for_each_pipe construct

Quoted 1 line · Robert Foss

Avoid using hand-rolled construct for iterating over all pipes.

display->n_pipes is a variable and depends upon the drmModeGetResources(). It not only changes between machines, but we don't probe the resources when listing tests. Both lead to variable sets of tests. -Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#7 lore raw

Re: [PATCH i-g-t v1 5/6] tests/kms_cursor_legacy: Switch to using for_each_pipe construct

Quoted 8 lines · Chris Wilson
Quoted 1 line · Robert Foss

Avoid using hand-rolled construct for iterating over all pipes.

display->n_pipes is a variable and depends upon the drmModeGetResources(). It not only changes between machines, but we don't probe the resources when listing tests. Both lead to variable sets of tests. -Chris

Primarily I was intending to avoid the igt_skip_on()_on by using a commonly used structures that Should Just Work, for_each_pipe().

Does that make sense?

Rob.
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#8 lore raw

Re: [PATCH i-g-t v1 5/6] tests/kms_cursor_legacy: Switch to using for_each_pipe construct

Quoted 12 lines · Robert Foss
Quoted 8 lines · Chris Wilson
Quoted 1 line · Robert Foss

Avoid using hand-rolled construct for iterating over all pipes.

display->n_pipes is a variable and depends upon the drmModeGetResources(). It not only changes between machines, but we don't probe the resources when listing tests. Both lead to variable sets of tests. -Chris

Quoted 4 lines

Primarily I was intending to avoid the igt_skip_on()_on by using a commonly used structures that Should Just Work, for_each_pipe().

Does that make sense?

Sure it makes sense. It just doesn't work right now. -Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#9 lore raw

PATCH 6/6 lib/igt_kms: Fixed typo

In reply to Robert Foss
---
 lib/igt_kms.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/igt_kms.c +1 -1
index 52e1f179..d104734a 100644
@@ -308,7 +308,7 @@ const unsigned char* igt_kms_get_alt_edid(void)
  * kmstest_pipe_name:
  * @pipe: display pipe
  *
- * Returns: String represnting @pipe, e.g. "A".
+ * Returns: String representing @pipe, e.g. "A".
  */
 const char *kmstest_pipe_name(enum pipe pipe)
 {
Signature · 6 lines
2.11.0

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Reviewed-by on the v1 series
#10 lore raw
In reply to Robert Foss

Patches 1-4 and 6 are

Quoted 14 lines · Robert Foss

This series contains a few separate fixes mostly for memory allocations but also some small unrelated small fixes.

This series can be found here under the alloc_fixes_$VERSION:
https://git.collabora.com/cgit/user/robertfoss/intel-gpu-tools.git/

Robert Foss (6):
lib/igt_kms: Check memory allocations for failures lib/igt_kms: Add missing function declaration lib/igt_debugfs: Prevent buffer overflow
lib/igt_kms: Set free'd pointer to NULL tests/kms_cursor_legacy: Switch to using for_each_pipe construct lib/igt_kms: Fixed typo

Quoted 13 lines
 lib/igt_debugfs.c         |  6 ++++--
 lib/igt_kms.c             | 10 +++++++---
 lib/igt_kms.h             |  1 +
 tests/kms_cursor_legacy.c | 31 ++++++++++++++-----------------
 4 files changed, 26 insertions(+), 22 deletions(-)
Signature · 6 lines
2.11.0

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx