[PATCH i-g-t v2 1/4] benchmarks: fix calloc calls with inverted arguments
Kamil Konieczny
kamil.konieczny at linux.intel.com
Wed Apr 10 15:06:43 UTC 2024
Hi Mauro,
On 2024-04-10 at 16:42:35 +0200, Mauro Carvalho Chehab wrote:
> From: Mauro Carvalho Chehab <mchehab at 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.
Thank you for fixing this,
Reviewed-by: Kamil Konieczny <kamil.konieczny at linux.intel.com>
>
> 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 at 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
>
More information about the igt-dev
mailing list