All of lore.kernel.org
 help / color / mirror / Atom feed
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 26/31] gobuffer: Remove 5 dead functions found via coverage analysis
Date: Wed, 29 Jul 2026 16:07:26 -0300	[thread overview]
Message-ID: <20260729190733.72876-27-acme@kernel.org> (raw)
In-Reply-To: <20260729190733.72876-1-acme@kernel.org>

From: Arnaldo Carvalho de Melo <acme@redhat.com>

Coverage analysis showed that 5 of 10 gobuffer functions have zero
callers anywhere in the codebase:

  gobuffer__new:      never called, dead since creation in be30be91
                      ("gobuffer: Move the non string specific bits",
                      2008)
  gobuffer__init:     only caller was gobuffer__new
  gobuffer__delete:   never called (only __gobuffer__delete is used)
  gobuffer__compress: last caller removed in 29fce8dc ("strings: use
                      BTF's string APIs for strings management", 2020)
  gobuffer__sort:     added in 2046cc50 for kfunc sorting (2024),
                      caller removed in c5677178 ("btf_encoder:
                      Refactor btf_encoder__tag_kfuncs()", 2025)

Removing them also drops the stdio.h and zlib.h includes and the
GOBUFFER__ZCHUNK constant that only gobuffer__compress used.

Before: 10 functions, 152 lines, 29% line coverage.
After: 5 functions, 77 lines, 55% line coverage.

Assisted-by: Claude:claude-sonnet-4-5
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 gobuffer.c | 74 ------------------------------------------------------
 gobuffer.h |  8 ------
 2 files changed, 82 deletions(-)

diff --git a/gobuffer.c b/gobuffer.c
index c439c48bb775593f..beeb677cfc3d7617 100644
--- a/gobuffer.c
+++ b/gobuffer.c
@@ -11,33 +11,12 @@
 #include <search.h>
 #include <stdint.h>
 #include <stdlib.h>
-#include <stdio.h>
 #include <string.h>
-#include <zlib.h>
 #include <errno.h>
 
 #include "dutil.h"
 
 #define GOBUFFER__BCHUNK (8 * 1024)
-#define GOBUFFER__ZCHUNK (8 * 1024)
-
-void gobuffer__init(struct gobuffer *gb)
-{
-	gb->entries = NULL;
-	gb->nr_entries = gb->allocated_size = 0;
-	/* 0 == NULL */
-	gb->index = 1;
-}
-
-struct gobuffer *gobuffer__new(void)
-{
-	struct gobuffer *gb = malloc(sizeof(*gb));
-
-	if (gb != NULL)
-		gobuffer__init(gb);
-
-	return gb;
-}
 
 void __gobuffer__delete(struct gobuffer *gb)
 {
@@ -47,12 +26,6 @@ void __gobuffer__delete(struct gobuffer *gb)
 	zfree(&gb->entries);
 }
 
-void gobuffer__delete(struct gobuffer *gb)
-{
-	__gobuffer__delete(gb);
-	free(gb);
-}
-
 void *gobuffer__ptr(const struct gobuffer *gb, unsigned int s)
 {
 	return s ? gb->entries + s : NULL;
@@ -102,50 +75,3 @@ void gobuffer__copy(const struct gobuffer *gb, void *dest)
 	}
 }
 
-void gobuffer__sort(struct gobuffer *gb, unsigned int size, int (*compar)(const void *, const void *))
-{
-	qsort(gb->entries, gb->nr_entries, size, compar);
-}
-
-const void *gobuffer__compress(struct gobuffer *gb, unsigned int *size)
-{
-	z_stream z = {
-		.zalloc	  = Z_NULL,
-		.zfree	  = Z_NULL,
-		.opaque	  = Z_NULL,
-		.avail_in = gobuffer__size(gb),
-		.next_in  = (Bytef *)(gobuffer__entries(gb) ? : ""),
-	};
-	void *bf = NULL;
-	unsigned int bf_size = 0;
-
-	if (deflateInit(&z, Z_BEST_COMPRESSION) != Z_OK)
-		goto out_free;
-
-	do {
-		const unsigned int new_bf_size = bf_size + GOBUFFER__ZCHUNK;
-		void *nbf = realloc(bf, new_bf_size);
-
-		if (nbf == NULL)
-			goto out_close_and_free;
-
-		bf = nbf;
-		z.avail_out = GOBUFFER__ZCHUNK;
-		z.next_out  = (Bytef *)bf + bf_size;
-		bf_size	    = new_bf_size;
-		if (deflate(&z, Z_FINISH) == Z_STREAM_ERROR)
-			goto out_close_and_free;
-	} while (z.avail_out == 0);
-
-	deflateEnd(&z);
-	*size = bf_size - z.avail_out;
-out:
-	return bf;
-
-out_close_and_free:
-	deflateEnd(&z);
-out_free:
-	free(bf);
-	bf = NULL;
-	goto out;
-}
diff --git a/gobuffer.h b/gobuffer.h
index cd218b629898307f..f9c461fec87c172f 100644
--- a/gobuffer.h
+++ b/gobuffer.h
@@ -13,16 +13,10 @@ struct gobuffer {
 	unsigned int	allocated_size;
 };
 
-struct gobuffer *gobuffer__new(void);
-
-void gobuffer__init(struct gobuffer *gb);
-void gobuffer__delete(struct gobuffer *gb);
 void __gobuffer__delete(struct gobuffer *gb);
 
 void gobuffer__copy(const struct gobuffer *gb, void *dest);
 
-void gobuffer__sort(struct gobuffer *gb, unsigned int size, int (*compar)(const void *, const void *));
-
 int gobuffer__add(struct gobuffer *gb, const void *s, unsigned int len);
 int gobuffer__allocate(struct gobuffer *gb, unsigned int len);
 
@@ -43,6 +37,4 @@ static inline unsigned int gobuffer__size(const struct gobuffer *gb)
 
 void *gobuffer__ptr(const struct gobuffer *gb, unsigned int s);
 
-const void *gobuffer__compress(struct gobuffer *gb, unsigned int *size);
-
 #endif /* _GOBUFFER_H_ */
-- 
2.55.0


  parent reply	other threads:[~2026-07-29 19:08 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 ` [PATCH 02/31] Fix -Wsign-compare warnings across the codebase Arnaldo Carvalho de Melo
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 ` Arnaldo Carvalho de Melo [this message]
2026-07-29 19:07 ` [PATCH 27/31] dwarves: Remove 6 dead functions found via coverage analysis 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-27-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.