From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH 1/3] fuzz: add context pointer to call_for_each_fuzz_test
Date: Mon, 27 Oct 2025 08:42:30 +0100 [thread overview]
Message-ID: <20251027074236.2473380-1-a.fatoum@barebox.org> (raw)
In preparation for removing call_for_each_fuzz_test from the sandbox
PBL, give it a context pointer to simplify its use.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
arch/sandbox/os/common.c | 9 +++++----
include/fuzz.h | 2 +-
lib/fuzz.c | 5 +++--
3 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/arch/sandbox/os/common.c b/arch/sandbox/os/common.c
index 86aaeb24ee3d..e872a6381988 100644
--- a/arch/sandbox/os/common.c
+++ b/arch/sandbox/os/common.c
@@ -56,11 +56,11 @@ extern int barebox_loglevel;
#endif
#ifdef CONFIG_FUZZ_EXTERNAL
-int call_for_each_fuzz_test(int (*fn)(const char **test));
+int call_for_each_fuzz_test(int (*fn)(const char **test, void *), void *ctx);
int setup_external_fuzz(const char *name,
int *argc, char ***argv);
#else
-static inline int call_for_each_fuzz_test(int (*fn)(const char **test))
+static inline int call_for_each_fuzz_test(int (*fn)(const char **test, void *), void *ctx)
{
return 0;
}
@@ -558,7 +558,8 @@ static struct option long_options[] = {
static const char optstring[] = "hm:i:c:e:d:O:I:B:x:y:";
-static __attribute__((unused)) int print_fuzz_test_name(const char **test_name)
+static __attribute__((unused)) int print_fuzz_test_name(const char **test_name,
+ void *ctx)
{
printf("%s\n", *test_name);
return 0;
@@ -667,7 +668,7 @@ static int normal_main(int argc, char *argv[])
sdl_yres = strtoul(optarg, NULL, 0);
break;
case OPT_LIST_FUZZERS:
- call_for_each_fuzz_test(print_fuzz_test_name);
+ call_for_each_fuzz_test(print_fuzz_test_name, NULL);
exit(0);
break;
case OPT_FUZZ:
diff --git a/include/fuzz.h b/include/fuzz.h
index caebc284d5db..f516d86ab769 100644
--- a/include/fuzz.h
+++ b/include/fuzz.h
@@ -84,7 +84,7 @@ static inline int fuzz_test_once(const struct fuzz_test *test, const u8 *data, s
return test->func(data, len);
}
-int call_for_each_fuzz_test(int (*fn)(const struct fuzz_test *test));
+int call_for_each_fuzz_test(int (*fn)(const struct fuzz_test *test, void *), void *ctx);
int setup_external_fuzz(const char *fuzz_name,
int *argc, char ***argv);
diff --git a/lib/fuzz.c b/lib/fuzz.c
index 084455e365cd..7be7ecedd922 100644
--- a/lib/fuzz.c
+++ b/lib/fuzz.c
@@ -4,13 +4,14 @@
#include <string.h>
#include <common.h>
-int call_for_each_fuzz_test(int (*fn)(const struct fuzz_test *test))
+int call_for_each_fuzz_test(int (*fn)(const struct fuzz_test *test, void *ctx),
+ void *ctx)
{
const struct fuzz_test *test;
int ret;
for_each_fuzz_test(test) {
- ret = fn(test);
+ ret = fn(test, ctx);
if (ret)
return ret;
}
--
2.47.3
next reply other threads:[~2025-10-27 7:43 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-27 7:42 Ahmad Fatoum [this message]
2025-10-27 7:42 ` [PATCH 2/3] sandbox: export list_fuzz_tests to sandbox_main Ahmad Fatoum
2025-10-27 7:42 ` [PATCH 3/3] fuzz: do not export for_each_fuzz_test Ahmad Fatoum
2025-10-28 7:26 ` [PATCH 1/3] fuzz: add context pointer to call_for_each_fuzz_test Sascha Hauer
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=20251027074236.2473380-1-a.fatoum@barebox.org \
--to=a.fatoum@barebox.org \
--cc=barebox@lists.infradead.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