Commit 9475dacb authored by Yonghong Song's avatar Yonghong Song Committed by Alexei Starovoitov

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: default avatarYonghong Song <yonghong.song@linux.dev>
Link: https://lore.kernel.org/r/20240326041508.1199239-1-yonghong.song@linux.devSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent d1320649
...@@ -61,12 +61,7 @@ void free_kallsyms_local(struct ksyms *ksyms) ...@@ -61,12 +61,7 @@ void free_kallsyms_local(struct ksyms *ksyms)
free(ksyms); free(ksyms);
} }
static int ksym_cmp(const void *p1, const void *p2) static struct ksyms *load_kallsyms_local_common(ksym_cmp_t cmp_cb)
{
return ((struct ksym *)p1)->addr - ((struct ksym *)p2)->addr;
}
struct ksyms *load_kallsyms_local(void)
{ {
FILE *f; FILE *f;
char func[256], buf[256]; char func[256], buf[256];
...@@ -100,7 +95,7 @@ struct ksyms *load_kallsyms_local(void) ...@@ -100,7 +95,7 @@ struct ksyms *load_kallsyms_local(void)
goto error; goto error;
} }
fclose(f); fclose(f);
qsort(ksyms->syms, ksyms->sym_cnt, sizeof(struct ksym), ksym_cmp); qsort(ksyms->syms, ksyms->sym_cnt, sizeof(struct ksym), cmp_cb);
return ksyms; return ksyms;
error: error:
...@@ -109,6 +104,16 @@ struct ksyms *load_kallsyms_local(void) ...@@ -109,6 +104,16 @@ struct ksyms *load_kallsyms_local(void)
return NULL; return NULL;
} }
static int ksym_cmp(const void *p1, const void *p2)
{
return ((struct ksym *)p1)->addr - ((struct ksym *)p2)->addr;
}
struct ksyms *load_kallsyms_local(void)
{
return load_kallsyms_local_common(ksym_cmp);
}
int load_kallsyms(void) int load_kallsyms(void)
{ {
pthread_mutex_lock(&ksyms_mutex); pthread_mutex_lock(&ksyms_mutex);
......
...@@ -13,6 +13,8 @@ struct ksym { ...@@ -13,6 +13,8 @@ struct ksym {
}; };
struct ksyms; struct ksyms;
typedef int (*ksym_cmp_t)(const void *p1, const void *p2);
int load_kallsyms(void); int load_kallsyms(void);
struct ksym *ksym_search(long key); struct ksym *ksym_search(long key);
long ksym_get_addr(const char *name); long ksym_get_addr(const char *name);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment