Skip to content

Commit 9475dac

Browse files
Yonghong SongAlexei Starovoitov
authored andcommitted
selftests/bpf: Refactor trace helper func load_kallsyms_local()
Refactor trace helper function load_kallsyms_local() such that it invokes a common function with a compare function as input. The common function will be used later for other local functions. Signed-off-by: Yonghong Song <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent d132064 commit 9475dac

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

tools/testing/selftests/bpf/trace_helpers.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,7 @@ void free_kallsyms_local(struct ksyms *ksyms)
6161
free(ksyms);
6262
}
6363

64-
static int ksym_cmp(const void *p1, const void *p2)
65-
{
66-
return ((struct ksym *)p1)->addr - ((struct ksym *)p2)->addr;
67-
}
68-
69-
struct ksyms *load_kallsyms_local(void)
64+
static struct ksyms *load_kallsyms_local_common(ksym_cmp_t cmp_cb)
7065
{
7166
FILE *f;
7267
char func[256], buf[256];
@@ -100,7 +95,7 @@ struct ksyms *load_kallsyms_local(void)
10095
goto error;
10196
}
10297
fclose(f);
103-
qsort(ksyms->syms, ksyms->sym_cnt, sizeof(struct ksym), ksym_cmp);
98+
qsort(ksyms->syms, ksyms->sym_cnt, sizeof(struct ksym), cmp_cb);
10499
return ksyms;
105100

106101
error:
@@ -109,6 +104,16 @@ struct ksyms *load_kallsyms_local(void)
109104
return NULL;
110105
}
111106

107+
static int ksym_cmp(const void *p1, const void *p2)
108+
{
109+
return ((struct ksym *)p1)->addr - ((struct ksym *)p2)->addr;
110+
}
111+
112+
struct ksyms *load_kallsyms_local(void)
113+
{
114+
return load_kallsyms_local_common(ksym_cmp);
115+
}
116+
112117
int load_kallsyms(void)
113118
{
114119
pthread_mutex_lock(&ksyms_mutex);

tools/testing/selftests/bpf/trace_helpers.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ struct ksym {
1313
};
1414
struct ksyms;
1515

16+
typedef int (*ksym_cmp_t)(const void *p1, const void *p2);
17+
1618
int load_kallsyms(void);
1719
struct ksym *ksym_search(long key);
1820
long ksym_get_addr(const char *name);

0 commit comments

Comments
 (0)