[PATCH i-g-t v2 4/4] lib: fix calloc calls with inverted arguments

Mauro Carvalho Chehab mauro.chehab at linux.intel.com
Wed Apr 10 14:42:38 UTC 2024


From: Mauro Carvalho Chehab <mchehab at kernel.org>

The new gcc version 14 now complains when calloc is called
with inverted arguments. use the script from:
a0ee73a8f359 ("benchmarks: fix calloc calls with inverted arguments")

To fix it.

Signed-off-by: Mauro Carvalho Chehab <mchehab at kernel.org>
---
 lib/igt_chamelium.c | 4 ++--
 lib/igt_kms.c       | 6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/lib/igt_chamelium.c b/lib/igt_chamelium.c
index 881e1892cf87..016d5356630c 100644
--- a/lib/igt_chamelium.c
+++ b/lib/igt_chamelium.c
@@ -153,7 +153,7 @@ struct chamelium_port **chamelium_get_ports(struct chamelium *chamelium,
 {
 	int i;
 	struct chamelium_port **ret =
-		calloc(sizeof(void*), chamelium->port_count);
+		calloc(chamelium->port_count, sizeof(void*));
 
 	*count = chamelium->port_count;
 	for (i = 0; i < chamelium->port_count; i++)
@@ -1516,7 +1516,7 @@ igt_crc_t *chamelium_read_captured_crcs(struct chamelium *chamelium,
 	res = chamelium_rpc(chamelium, NULL, "GetCapturedChecksums", "(in)", 0);
 
 	*frame_count = xmlrpc_array_size(&chamelium->env, res);
-	ret = calloc(sizeof(igt_crc_t), *frame_count);
+	ret = calloc(*frame_count, sizeof(igt_crc_t));
 
 	for (i = 0; i < *frame_count; i++) {
 		xmlrpc_array_read_item(&chamelium->env, res, i, &elem);
diff --git a/lib/igt_kms.c b/lib/igt_kms.c
index 2a518eb8d936..60339565a192 100644
--- a/lib/igt_kms.c
+++ b/lib/igt_kms.c
@@ -2778,7 +2778,7 @@ void igt_display_require(igt_display_t *display, int drm_fd)
 		     resources->count_crtcs, IGT_MAX_PIPES);
 
 	display->n_pipes = IGT_MAX_PIPES;
-	display->pipes = calloc(sizeof(igt_pipe_t), display->n_pipes);
+	display->pipes = calloc(display->n_pipes, sizeof(igt_pipe_t));
 	igt_assert_f(display->pipes, "Failed to allocate memory for %d pipes\n", display->n_pipes);
 
 	for (i = 0; i < resources->count_crtcs; i++) {
@@ -2806,7 +2806,7 @@ void igt_display_require(igt_display_t *display, int drm_fd)
 	igt_assert(plane_resources);
 
 	display->n_planes = plane_resources->count_planes;
-	display->planes = calloc(sizeof(igt_plane_t), display->n_planes);
+	display->planes = calloc(display->n_planes, sizeof(igt_plane_t));
 	igt_assert_f(display->planes, "Failed to allocate memory for %d planes\n", display->n_planes);
 
 	for (i = 0; i < plane_resources->count_planes; ++i) {
@@ -2855,7 +2855,7 @@ void igt_display_require(igt_display_t *display, int drm_fd)
 		}
 
 		igt_assert_lt(0, n_planes);
-		pipe->planes = calloc(sizeof(igt_plane_t), n_planes);
+		pipe->planes = calloc(n_planes, sizeof(igt_plane_t));
 		igt_assert_f(pipe->planes, "Failed to allocate memory for %d planes\n", n_planes);
 		last_plane = n_planes - 1;
 
-- 
2.44.0



More information about the igt-dev mailing list