From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Alan Maguire <alan.maguire@oracle.com>
Cc: Jiri Olsa <jolsa@kernel.org>,
Clark Williams <williams@redhat.com>,
dwarves@vger.kernel.org, bpf@vger.kernel.org,
Andrii Nakryiko <andrii@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 02/31] Fix -Wsign-compare warnings across the codebase
Date: Wed, 29 Jul 2026 16:07:02 -0300 [thread overview]
Message-ID: <20260729190733.72876-3-acme@kernel.org> (raw)
In-Reply-To: <20260729190733.72876-1-acme@kernel.org>
From: Arnaldo Carvalho de Melo <acme@redhat.com>
Fix all 15 signed/unsigned comparison warnings triggered by
-Wsign-compare:
pahole.c: use size_t for ARRAY_SIZE() loop iterators in
init_btf_features(), find_btf_feature(),
show_supported_btf_features() and btf_features__enable_default(),
moving declarations into the for statements.
btf_encoder.c: use size_t for ARRAY_SIZE() loops in
should_skip_decl() and btf_encoder__should_skip_kfunc(), use
size_t for the offset in is_sym_kfunc_set(), and unsigned int
for the loop counter matching ranges_cnt.
btf_loader.c: cast bitfield arithmetic to size_t in ternary
where the other branch is pos->byte_size (size_t).
dwarf_loader.c: cast int8_t bitfield_offset to uint32_t before
comparing against uint32_t bit_size — by this point the value
has already been corrected to non-negative.
dwarves.c: use uint16_t for byte_hole_size to match the int
hole field it compares against, and add an id >= 0 guard before
the ARRAY_SIZE() comparison in lang__int2str().
dwarves_fprintf.c: use uint64_t for loop variable matching
attributes->cnt type.
dwarves_reorganize.c: use int for remainder/inc (bounded by
addr_size), and cast byte_size comparison to size_t where the
hole value is known non-negative.
Fixes: 7bc9b9975545ab53 ("pahole: Add --btf_features support")
Assisted-by: Claude:claude-sonnet-4-5
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
btf_encoder.c | 12 +++++-------
btf_loader.c | 2 +-
dwarf_loader.c | 2 +-
dwarves.c | 4 ++--
dwarves_fprintf.c | 3 +--
dwarves_reorganize.c | 6 +++---
pahole.c | 14 ++++----------
7 files changed, 17 insertions(+), 26 deletions(-)
diff --git a/btf_encoder.c b/btf_encoder.c
index 993a61cf320c6d92..9f8cd279fa92af1c 100644
--- a/btf_encoder.c
+++ b/btf_encoder.c
@@ -1211,14 +1211,13 @@ static struct btf_encoder_func_state *btf_encoder__alloc_func_state(struct btf_e
return state;
}
-static bool str_contains_suffix(const char *str, const char * const *suffixes, int nr_suffixes)
+static bool str_contains_suffix(const char *str, const char * const *suffixes, size_t nr_suffixes)
{
const char *suffix = strchr(str, '.');
- int i;
if (!suffix)
return false;
- for (i = 0; i < nr_suffixes; i++) {
+ for (size_t i = 0; i < nr_suffixes; i++) {
if (strstr(suffix, suffixes[i]))
return true;
}
@@ -2087,7 +2086,7 @@ static int is_sym_kfunc_set(GElf_Sym *sym, const char *name, Elf_Data *idlist, s
{
void *ptr = idlist->d_buf;
struct btf_id_set8 *set;
- int off;
+ size_t off;
/* kfuncs are only found in BTF_SET8's */
if (!strstarts(name, BTF_ID_SET8_PFX))
@@ -2282,7 +2281,7 @@ static int btf_encoder__collect_kfuncs(struct btf_encoder *encoder)
ptrdiff_t off;
GElf_Sym sym;
bool found;
- int j;
+ unsigned int j;
if (!gelf_getsym(symbols, i, &sym)) {
elf_error("Failed to get ELF symbol(%d)", i);
@@ -2568,12 +2567,11 @@ static bool filter_variable_name(const char *name)
X("__func_stack_frame_non_standard_")
#undef X
};
- int i;
if (*name != '_')
return false;
- for (i = 0; i < ARRAY_SIZE(skip); i++) {
+ for (size_t i = 0; i < ARRAY_SIZE(skip); i++) {
if (strncmp(name, skip[i].s, skip[i].len) == 0)
return true;
}
diff --git a/btf_loader.c b/btf_loader.c
index 92d4832c47af21a0..caead39775da54da 100644
--- a/btf_loader.c
+++ b/btf_loader.c
@@ -744,7 +744,7 @@ static int class__fixup_btf_bitfields(const struct conf_load *conf, struct tag *
*/
smallest_offset = pos->byte_offset;
smallest_offset += pos->bitfield_size ?
- (pos->bitfield_offset + pos->bitfield_size + 7) / 8 :
+ (size_t)(pos->bitfield_offset + pos->bitfield_size + 7) / 8 :
pos->byte_size;
}
diff --git a/dwarf_loader.c b/dwarf_loader.c
index a4cd91178bccde99..14c90080f538e10d 100644
--- a/dwarf_loader.c
+++ b/dwarf_loader.c
@@ -3786,7 +3786,7 @@ static int class_member__cache_byte_size(struct tag *tag, struct cu *cu,
/* align on underlying base type natural alignment boundary */
member->bitfield_offset += (member->byte_offset % member->byte_size) * 8;
member->byte_offset = member->bit_offset / member->bit_size * member->bit_size / 8;
- if (member->bitfield_offset >= member->bit_size) {
+ if ((uint32_t)member->bitfield_offset >= member->bit_size) {
member->bitfield_offset -= member->bit_size;
member->byte_offset += member->byte_size;
}
diff --git a/dwarves.c b/dwarves.c
index ef93239d26827711..f05c4d3b4b669335 100644
--- a/dwarves.c
+++ b/dwarves.c
@@ -1577,7 +1577,7 @@ const struct class_member *class__find_bit_hole(const struct class *class,
const uint16_t bit_hole_size)
{
struct class_member *pos;
- const size_t byte_hole_size = bit_hole_size / 8;
+ const uint16_t byte_hole_size = bit_hole_size / 8;
type__for_each_data_member(&class->type, pos)
if (pos == trailer)
@@ -2449,7 +2449,7 @@ const char *lang__int2str(int id)
{
const char *lang = NULL;
- if (id < ARRAY_SIZE(languages))
+ if (id >= 0 && (size_t)id < ARRAY_SIZE(languages))
lang = languages[id];
else if (id == DW_LANG_Mips_Assembler)
return "asm";
diff --git a/dwarves_fprintf.c b/dwarves_fprintf.c
index ab1c381db64651c6..e44ac05c3b9e7e73 100644
--- a/dwarves_fprintf.c
+++ b/dwarves_fprintf.c
@@ -1206,10 +1206,9 @@ const char *function__prototype(const struct function *func,
static size_t tag__attributes_fprintf(const struct tag *tag, FILE *fp)
{
size_t printed = 0;
- int i;
if (tag->attributes)
- for (i = 0; i < tag->attributes->cnt; ++i)
+ for (uint64_t i = 0; i < tag->attributes->cnt; ++i)
printed += fprintf(fp, "%s ", tag->attributes->values[i]);
return printed;
diff --git a/dwarves_reorganize.c b/dwarves_reorganize.c
index 14f5e8228fa8a95d..50652fefcf14cbb2 100644
--- a/dwarves_reorganize.c
+++ b/dwarves_reorganize.c
@@ -82,7 +82,7 @@ void class__fixup_alignment(struct class *class, const struct cu *cu)
class->type.size -= dec;
class__subtract_offsets_from(class, pos, dec);
} else for (power2 = cu->addr_size; power2 >= 2; power2 /= 2) {
- const size_t remainder = pos->byte_offset % power2;
+ const int remainder = pos->byte_offset % power2;
if (pos->byte_size == power2) {
if (remainder == 0) /* perfectly aligned */
@@ -95,7 +95,7 @@ void class__fixup_alignment(struct class *class, const struct cu *cu)
pos->bit_offset -= remainder * 8;
class__subtract_offsets_from(class, pos, remainder);
} else {
- const size_t inc = power2 - remainder;
+ const int inc = power2 - remainder;
if (last_member->hole == 0)
++class->nr_holes;
@@ -811,7 +811,7 @@ restart:
if (class->padding > 0 &&
member != last_member &&
last_member->byte_size != 0 &&
- last_member->byte_size <= member->hole) {
+ last_member->byte_size <= (size_t)member->hole) {
if (class__move_member(class, member, last_member, cu, 1, verbose, fp))
goto restart;
}
diff --git a/pahole.c b/pahole.c
index 033baedcc602cc75..390d5f2dd20e4dfd 100644
--- a/pahole.c
+++ b/pahole.c
@@ -1249,8 +1249,6 @@ bool set_btf_features_initial;
static void init_btf_features(void)
{
- int i;
-
/* Only set initial values once, as multiple --btf_features=
* may be specified on command-line, and setting values
* again could clobber values. The aim is to enable
@@ -1258,16 +1256,14 @@ static void init_btf_features(void)
*/
if (set_btf_features_initial)
return;
- for (i = 0; i < ARRAY_SIZE(btf_features); i++)
+ for (size_t i = 0; i < ARRAY_SIZE(btf_features); i++)
*btf_features[i].conf_value = btf_features[i].initial_value;
set_btf_features_initial = true;
}
static struct btf_feature *find_btf_feature(char *name)
{
- int i;
-
- for (i = 0; i < ARRAY_SIZE(btf_features); i++) {
+ for (size_t i = 0; i < ARRAY_SIZE(btf_features); i++) {
if (strcmp(name, btf_features[i].name) == 0)
return &btf_features[i];
}
@@ -1285,9 +1281,7 @@ static void enable_btf_feature(struct btf_feature *feature)
static void show_supported_btf_features(FILE *output)
{
- int i;
-
- for (i = 0; i < ARRAY_SIZE(btf_features); i++) {
+ for (size_t i = 0; i < ARRAY_SIZE(btf_features); i++) {
if (btf_features[i].feature_check && !btf_features[i].feature_check())
continue;
if (i > 0)
@@ -1299,7 +1293,7 @@ static void show_supported_btf_features(FILE *output)
static void btf_features__enable_default(void)
{
- for (int i = 0; i < ARRAY_SIZE(btf_features); i++) {
+ for (size_t i = 0; i < ARRAY_SIZE(btf_features); i++) {
if (btf_features[i].default_enabled)
enable_btf_feature(&btf_features[i]);
}
--
2.55.0
next prev parent reply other threads:[~2026-07-29 19:07 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-29 19:07 [PATCHES 00/31] pahole: Bug fixes and small improvements Arnaldo Carvalho de Melo
2026-07-29 19:07 ` [PATCH 01/31] cmake: Update minimum required version from 3.5 to 3.10 Arnaldo Carvalho de Melo
2026-07-29 19:07 ` Arnaldo Carvalho de Melo [this message]
2026-07-29 19:07 ` [PATCH 03/31] btf_encoder: Fix interior pointer free and missing NULL check Arnaldo Carvalho de Melo
2026-07-29 19:07 ` [PATCH 04/31] dwarves: Fix missing list head initialization in type__clone_members Arnaldo Carvalho de Melo
2026-07-29 19:07 ` [PATCH 05/31] pahole: Fix instance memory leak on early returns in prototype__stdio_fprintf_value Arnaldo Carvalho de Melo
2026-07-29 19:07 ` [PATCH 06/31] ctf_loader, libctf: Fix error path resource leaks Arnaldo Carvalho de Melo
2026-07-29 19:07 ` [PATCH 07/31] dwarves: Don't search for holes before member byte sizes are cached Arnaldo Carvalho de Melo
2026-07-29 19:07 ` [PATCH 08/31] dwarf_loader: Allocate type_dcu via dwarf_cu__new to fix dangling stack pointer Arnaldo Carvalho de Melo
2026-07-29 19:07 ` [PATCH 09/31] dwarf_loader: Fix annotation failure leaks in variable and typedef creation Arnaldo Carvalho de Melo
2026-07-29 19:07 ` [PATCH 10/31] btf_encoder: Use btf_encoder__tag_type() for all type ID computations Arnaldo Carvalho de Melo
2026-07-29 19:07 ` [PATCH 11/31] pahole: Fix --errno typo that decrements instead of negating Arnaldo Carvalho de Melo
2026-07-29 19:07 ` [PATCH 12/31] dwarves: Fix heap buffer overflow in languages__parse realloc Arnaldo Carvalho de Melo
2026-07-29 19:07 ` [PATCH 13/31] btf_encoder: Fix early cleanup crashes in btf_encoder__new/delete Arnaldo Carvalho de Melo
2026-07-29 19:07 ` [PATCH 14/31] btf_encoder, libctf: Add elf_strptr NULL checks and fix kfunc bounds Arnaldo Carvalho de Melo
2026-07-29 19:07 ` [PATCH 15/31] dwarf_loader: Fix --fixup_silly_bitfields condition check Arnaldo Carvalho de Melo
2026-07-29 19:07 ` [PATCH 16/31] dwarf_loader: Skip libdw__lock when elfutils is built thread-safe Arnaldo Carvalho de Melo
2026-07-29 19:07 ` [PATCH 17/31] dwarf_loader: Fix data race in tag__init() decl_file string cache Arnaldo Carvalho de Melo
2026-07-29 19:07 ` [PATCH 18/31] pahole: Fix parse_btf_features("all") being a silent no-op Arnaldo Carvalho de Melo
2026-07-29 19:07 ` [PATCH 19/31] dwarves: Fix variable shadowing in __cus__find_struct_by_name() Arnaldo Carvalho de Melo
2026-07-29 19:07 ` [PATCH 20/31] dutil: Add exec_objcopy() shell-injection-safe helper Arnaldo Carvalho de Melo
2026-07-29 19:07 ` [PATCH 21/31] btf_encoder: Fall back to objcopy when llvm-objcopy is not available Arnaldo Carvalho de Melo
2026-07-29 19:07 ` [PATCH 22/31] dwarf_loader, btf_loader: Replace stale FIXME/XXX comments with explanations Arnaldo Carvalho de Melo
2026-07-29 19:07 ` [PATCH 23/31] pahole: Skip inline expansions during BTF encoding Arnaldo Carvalho de Melo
2026-07-29 19:07 ` [PATCH 24/31] pahole: Use fseek for seekable files in --prettify and --seek_bytes Arnaldo Carvalho de Melo
2026-07-29 19:07 ` [PATCH 25/31] pahole: Guard pipe_seek() against negative offsets Arnaldo Carvalho de Melo
2026-07-29 19:07 ` [PATCH 26/31] gobuffer: Remove 5 dead functions found via coverage analysis Arnaldo Carvalho de Melo
2026-07-29 19:07 ` [PATCH 27/31] dwarves: Remove 6 " Arnaldo Carvalho de Melo
2026-07-29 19:07 ` [PATCH 28/31] pfunct, dwarves_fprintf: Mark file-local functions as static Arnaldo Carvalho de Melo
2026-07-29 19:07 ` [PATCH 29/31] btf_encoder: Fix multi-dimensional array encoding Arnaldo Carvalho de Melo
2026-07-29 19:07 ` [PATCH 30/31] btf_loader: Fix multi-dimensional array loading Arnaldo Carvalho de Melo
2026-07-29 19:07 ` [PATCH 31/31] btfdiff: Remove --flat_arrays now that pahole encodes multi dim arrays in BTF Arnaldo Carvalho de Melo
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=20260729190733.72876-3-acme@kernel.org \
--to=acme@kernel.org \
--cc=acme@redhat.com \
--cc=alan.maguire@oracle.com \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=dwarves@vger.kernel.org \
--cc=jolsa@kernel.org \
--cc=williams@redhat.com \
--cc=yonghong.song@linux.dev \
/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