Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Mauro Carvalho Chehab <mauro.chehab@linux.intel.com>
To: igt-dev@lists.freedesktop.org
Subject: [PATCH i-g-t v2 1/4] benchmarks: fix calloc calls with inverted arguments
Date: Wed, 10 Apr 2024 16:42:35 +0200	[thread overview]
Message-ID: <20240410144321.44766-2-mauro.chehab@linux.intel.com> (raw)
In-Reply-To: <20240410144321.44766-1-mauro.chehab@linux.intel.com>

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

The new gcc version 14 now complains when calloc is called
with inverted arguments:

	../benchmarks/gem_exec_reloc.c:85:31: warning: ‘calloc’ sizes specified with ‘sizeof’ in the earlier argument and not in the later argument [-Wcalloc-transposed-args]
	   85 |         target = calloc(sizeof(*target), num_relocs);
	      |                               ^
	../benchmarks/gem_exec_reloc.c:85:31: note: earlier argument should specify number of elements, later size of each element

Replace all occurrences of calloc that were warned on gcc 14 by
placing the arguments at the right order.

Logic fixed using this small python script, written specifically
to catch gcc calloc warnings:

    #!/usr/bin/env python3
    import re
    warnings = [
    	"lib/igt_kms.c:2781",
    	"lib/igt_kms.c:2809",
    	"lib/igt_kms.c:2858",
    	"lib/igt_chamelium.c:156",
    	"lib/igt_chamelium.c:1519",
    	"tests/kms_atomic_transition.c:483",
    	"tests/kms_atomic_transition.c:485",
    	"tests/kms_atomic_transition.c:487",
    	"tests/kms_flip.c:426",
    	"tests/kms_flip.c:427",
    	"tests/intel/gem_exec_alignment.c:204",
    	"tests/intel/gem_exec_alignment.c:409",
    	"tests/intel/gem_exec_fair.c:1121",
    	"tests/intel/gem_exec_fair.c:1122",
    	"tests/intel/gem_fence_thrash.c:153",
    	"tests/intel/gem_fence_thrash.c:234",
    	"tests/intel/gem_ppgtt.c:432",
    	"tests/intel/gem_ppgtt.c:459",
    	"tests/intel/gem_render_tiled_blits.c:152",
    	"tests/intel/gem_userptr_blits.c:1433",
    	"tests/chamelium/kms_chamelium_frames.c:943",
    	"tests/amdgpu/amd_multidisplay_modeset.c:242",
    	"benchmarks/gem_exec_reloc.c:83",
    	"benchmarks/gem_exec_reloc.c:84",
    	"benchmarks/gem_exec_reloc.c:85",
    	"benchmarks/gem_latency.c:196",
    	"assembler/main.c:400",
    	"assembler/gram.y:219",
    	"assembler/gram.y:231",
    	"assembler/gram.y:242",
    ]
    split_file = re.compile(r"([^\:]+):(\d+)")
    calloc = re.compile(r"(calloc\s*\()(.*)\,\s*([\w\d\ \+\*\-\>]+)(\))")
    for f in warnings:
        match = split_file.match(f)
        if not match:
            continue
        fname = match.group(1)
        line_number = int(match.group(2))
        new = ""
        with open(fname, 'r', encoding = 'utf8') as fp:
            for ln, line in enumerate(fp):
                if ln + 1 == line_number:
                    new_line = calloc.sub(r"\1\3, \2\4", line)
                    if new_line != line:
                        line = new_line
                    else:
                        print(f"{fname}, line {line_number}: FAILED: {line.strip()}")
                new += line
        with open(fname, 'w', encoding = 'utf8') as fp:
            fp.write(new)

Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
---
 benchmarks/gem_exec_reloc.c | 6 +++---
 benchmarks/gem_latency.c    | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/benchmarks/gem_exec_reloc.c b/benchmarks/gem_exec_reloc.c
index dadc064f0ca4..0610308669f2 100644
--- a/benchmarks/gem_exec_reloc.c
+++ b/benchmarks/gem_exec_reloc.c
@@ -80,9 +80,9 @@ static int run(unsigned batch_size,
 	struct drm_i915_gem_relocation_entry *mem_reloc = NULL;
 	int *target;
 
-	gem_exec = calloc(sizeof(*gem_exec), num_objects + 1);
-	mem_reloc = calloc(sizeof(*mem_reloc), num_relocs);
-	target = calloc(sizeof(*target), num_relocs);
+	gem_exec = calloc(num_objects + 1, sizeof(*gem_exec));
+	mem_reloc = calloc(num_relocs, sizeof(*mem_reloc));
+	target = calloc(num_relocs, sizeof(*target));
 
 	fd = drm_open_driver(DRIVER_INTEL);
 
diff --git a/benchmarks/gem_latency.c b/benchmarks/gem_latency.c
index cc8b3de55df3..6abf366f9285 100644
--- a/benchmarks/gem_latency.c
+++ b/benchmarks/gem_latency.c
@@ -193,7 +193,7 @@ static void setup_workload(struct producer *p, int gen,
 	struct drm_i915_gem_relocation_entry *reloc;
 	int offset;
 
-	reloc = calloc(sizeof(*reloc), 2*factor);
+	reloc = calloc(2*factor, sizeof(*reloc));
 
 	p->workload_dispatch.exec[0].handle = scratch;
 	p->workload_dispatch.exec[1].relocation_count = 2*factor;
-- 
2.44.0


  reply	other threads:[~2024-04-10 14:43 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-10 14:42 [PATCH i-g-t v2 0/4] Fix warnings with gcc 14 Mauro Carvalho Chehab
2024-04-10 14:42 ` Mauro Carvalho Chehab [this message]
2024-04-10 15:06   ` [PATCH i-g-t v2 1/4] benchmarks: fix calloc calls with inverted arguments Kamil Konieczny
2024-04-10 14:42 ` [PATCH i-g-t v2 2/4] assembler: " Mauro Carvalho Chehab
2024-04-10 15:13   ` Kamil Konieczny
2024-04-10 14:42 ` [PATCH i-g-t v2 3/4] tests: " Mauro Carvalho Chehab
2024-04-10 15:15   ` Kamil Konieczny
2024-04-10 14:42 ` [PATCH i-g-t v2 4/4] lib: " Mauro Carvalho Chehab
2024-04-10 15:17   ` Kamil Konieczny
2024-04-10 23:30 ` ✗ Fi.CI.BAT: failure for Fix warnings with gcc 14 Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240410144321.44766-2-mauro.chehab@linux.intel.com \
    --to=mauro.chehab@linux.intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox