* [PATCH v2] perf tests: use strdup() in "Object code reading"
@ 2025-10-08 12:42 James Clark
2025-10-14 14:03 ` Namhyung Kim
0 siblings, 1 reply; 2+ messages in thread
From: James Clark @ 2025-10-08 12:42 UTC (permalink / raw)
To: linux-perf-users, irogers, namhyung, acme
Cc: James Clark, Peter Zijlstra, Ingo Molnar, Mark Rutland,
Alexander Shishkin, Jiri Olsa, Adrian Hunter, Charlie Jenkins,
linux-kernel
Use strdup() instead of fixed PATH_MAX buffer for storing paths to not
waste memory.
Suggested-by: Ian Rogers <irogers@google.com>
Reviewed-by: Ian Rogers <irogers@google.com>
Signed-off-by: James Clark <james.clark@linaro.org>
---
Applies on top of: https://lore.kernel.org/linux-perf-users/CAP-5=fV1N-j+f4GBFnDWsmoMZcz_k0U=nu1A7NZz-g4gzCH4KA@mail.gmail.com/T/#t
Changes since v1: handle strdup() failure
tools/perf/tests/code-reading.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-reading.c
index 4c9fbf6965c4..1acb12b1a2eb 100644
--- a/tools/perf/tests/code-reading.c
+++ b/tools/perf/tests/code-reading.c
@@ -43,7 +43,7 @@
struct tested_section {
struct rb_node rb_node;
u64 addr;
- char path[PATH_MAX];
+ char *path;
};
static bool tested_code_insert_or_exists(const char *path, u64 addr,
@@ -79,7 +79,11 @@ static bool tested_code_insert_or_exists(const char *path, u64 addr,
return true;
data->addr = addr;
- strlcpy(data->path, path, sizeof(data->path));
+ data->path = strdup(path);
+ if (!data->path) {
+ free(data);
+ return true;
+ }
rb_link_node(&data->rb_node, parent, node);
rb_insert_color(&data->rb_node, tested_sections);
return false;
@@ -94,6 +98,7 @@ static void tested_sections__free(struct rb_root *root)
rb_node);
rb_erase(node, root);
+ free(ts->path);
free(ts);
}
}
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] perf tests: use strdup() in "Object code reading"
2025-10-08 12:42 [PATCH v2] perf tests: use strdup() in "Object code reading" James Clark
@ 2025-10-14 14:03 ` Namhyung Kim
0 siblings, 0 replies; 2+ messages in thread
From: Namhyung Kim @ 2025-10-14 14:03 UTC (permalink / raw)
To: James Clark
Cc: linux-perf-users, irogers, acme, Peter Zijlstra, Ingo Molnar,
Mark Rutland, Alexander Shishkin, Jiri Olsa, Adrian Hunter,
Charlie Jenkins, linux-kernel
On Wed, Oct 08, 2025 at 01:42:00PM +0100, James Clark wrote:
> Use strdup() instead of fixed PATH_MAX buffer for storing paths to not
> waste memory.
>
> Suggested-by: Ian Rogers <irogers@google.com>
> Reviewed-by: Ian Rogers <irogers@google.com>
> Signed-off-by: James Clark <james.clark@linaro.org>
Applied to perf-tools-next, thanks!
Best regards,
Namhyung
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-10-14 14:03 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-08 12:42 [PATCH v2] perf tests: use strdup() in "Object code reading" James Clark
2025-10-14 14:03 ` Namhyung Kim
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox