Add struct bpf_struct_ops_tramp_link for struct_ops link, to follow
the code of all the other users of bpf_tramp_link object.

Signed-off-by: Jiri Olsa <[email protected]>
---
 include/linux/bpf.h            |  4 ++++
 kernel/bpf/bpf_struct_ops.c    | 17 +++++++++--------
 net/bpf/bpf_dummy_struct_ops.c | 14 +++++++-------
 3 files changed, 20 insertions(+), 15 deletions(-)

diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index cd9b96434904..512d75094be0 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -1878,6 +1878,10 @@ struct bpf_shim_tramp_link {
        struct bpf_trampoline *trampoline;
 };
 
+struct bpf_struct_ops_tramp_link {
+       struct bpf_tramp_link link;
+};
+
 struct bpf_tracing_link {
        struct bpf_tramp_link link;
        struct bpf_trampoline *trampoline;
diff --git a/kernel/bpf/bpf_struct_ops.c b/kernel/bpf/bpf_struct_ops.c
index c43346cb3d76..ecca0a6be6af 100644
--- a/kernel/bpf/bpf_struct_ops.c
+++ b/kernel/bpf/bpf_struct_ops.c
@@ -585,9 +585,10 @@ static void bpf_struct_ops_link_release(struct bpf_link 
*link)
 
 static void bpf_struct_ops_link_dealloc(struct bpf_link *link)
 {
-       struct bpf_tramp_link *tlink = container_of(link, struct 
bpf_tramp_link, link);
+       struct bpf_struct_ops_tramp_link *st_link =
+               container_of(link, struct bpf_struct_ops_tramp_link, link.link);
 
-       kfree(tlink);
+       kfree(st_link);
 }
 
 const struct bpf_link_ops bpf_struct_ops_link_lops = {
@@ -747,7 +748,7 @@ static long bpf_struct_ops_map_update_elem(struct bpf_map 
*map, void *key,
        for_each_member(i, t, member) {
                const struct btf_type *mtype, *ptype;
                struct bpf_prog *prog;
-               struct bpf_tramp_link *link;
+               struct bpf_struct_ops_tramp_link *st_link;
                struct bpf_ksym *ksym;
                u32 moff;
 
@@ -815,15 +816,15 @@ static long bpf_struct_ops_map_update_elem(struct bpf_map 
*map, void *key,
                /* Poison pointer on error instead of return for backward 
compatibility */
                bpf_prog_assoc_struct_ops(prog, &st_map->map);
 
-               link = kzalloc(sizeof(*link), GFP_USER);
-               if (!link) {
+               st_link = kzalloc(sizeof(*st_link), GFP_USER);
+               if (!st_link) {
                        bpf_prog_put(prog);
                        err = -ENOMEM;
                        goto reset_unlock;
                }
-               bpf_link_init(&link->link, BPF_LINK_TYPE_STRUCT_OPS,
+               bpf_link_init(&st_link->link.link, BPF_LINK_TYPE_STRUCT_OPS,
                              &bpf_struct_ops_link_lops, prog, 
prog->expected_attach_type);
-               *plink++ = &link->link;
+               *plink++ = &st_link->link.link;
 
                ksym = kzalloc(sizeof(*ksym), GFP_USER);
                if (!ksym) {
@@ -833,7 +834,7 @@ static long bpf_struct_ops_map_update_elem(struct bpf_map 
*map, void *key,
                *pksym++ = ksym;
 
                trampoline_start = image_off;
-               err = bpf_struct_ops_prepare_trampoline(tlinks, link,
+               err = bpf_struct_ops_prepare_trampoline(tlinks, &st_link->link,
                                                &st_ops->func_models[i],
                                                *(void **)(st_ops->cfi_stubs + 
moff),
                                                &image, &image_off,
diff --git a/net/bpf/bpf_dummy_struct_ops.c b/net/bpf/bpf_dummy_struct_ops.c
index 812457819b5a..4029931a4fce 100644
--- a/net/bpf/bpf_dummy_struct_ops.c
+++ b/net/bpf/bpf_dummy_struct_ops.c
@@ -130,10 +130,10 @@ int bpf_struct_ops_test_run(struct bpf_prog *prog, const 
union bpf_attr *kattr,
                            union bpf_attr __user *uattr)
 {
        const struct bpf_struct_ops *st_ops = &bpf_bpf_dummy_ops;
+       struct bpf_struct_ops_tramp_link *st_link = NULL;
        const struct btf_type *func_proto;
        struct bpf_dummy_ops_test_args *args;
        struct bpf_tramp_links *tlinks = NULL;
-       struct bpf_tramp_link *link = NULL;
        void *image = NULL;
        unsigned int op_idx;
        u32 image_off = 0;
@@ -164,18 +164,18 @@ int bpf_struct_ops_test_run(struct bpf_prog *prog, const 
union bpf_attr *kattr,
                goto out;
        }
 
-       link = kzalloc(sizeof(*link), GFP_USER);
-       if (!link) {
+       st_link = kzalloc(sizeof(*st_link), GFP_USER);
+       if (!st_link) {
                err = -ENOMEM;
                goto out;
        }
        /* prog doesn't take the ownership of the reference from caller */
        bpf_prog_inc(prog);
-       bpf_link_init(&link->link, BPF_LINK_TYPE_STRUCT_OPS, 
&bpf_struct_ops_link_lops, prog,
+       bpf_link_init(&st_link->link.link, BPF_LINK_TYPE_STRUCT_OPS, 
&bpf_struct_ops_link_lops, prog,
                      prog->expected_attach_type);
 
        op_idx = prog->expected_attach_type;
-       err = bpf_struct_ops_prepare_trampoline(tlinks, link,
+       err = bpf_struct_ops_prepare_trampoline(tlinks, &st_link->link,
                                                &st_ops->func_models[op_idx],
                                                &dummy_ops_test_ret_function,
                                                &image, &image_off,
@@ -196,8 +196,8 @@ int bpf_struct_ops_test_run(struct bpf_prog *prog, const 
union bpf_attr *kattr,
 out:
        kfree(args);
        bpf_struct_ops_image_free(image);
-       if (link)
-               bpf_link_put(&link->link);
+       if (st_link)
+               bpf_link_put(&st_link->link.link);
        kfree(tlinks);
        return err;
 }
-- 
2.52.0


Reply via email to