void bpf_link_init(struct bpf_link *link, const struct bpf_link_ops *ops,
struct bpf_prog *prog);
-void bpf_link_defunct(struct bpf_link *link);
void bpf_link_inc(struct bpf_link *link);
void bpf_link_put(struct bpf_link *link);
int bpf_link_new_fd(struct bpf_link *link);
link->prog = prog;
}
-void bpf_link_defunct(struct bpf_link *link)
+/* Clean up bpf_link and corresponding anon_inode file and FD. After
+ * anon_inode is created, bpf_link can't be just kfree()'d due to deferred
+ * anon_inode's release() call. This helper manages marking bpf_link as
+ * defunct, releases anon_inode file and puts reserved FD.
+ */
+static void bpf_link_cleanup(struct bpf_link *link, struct file *link_file,
+ int link_fd)
{
link->prog = NULL;
+ fput(link_file);
+ put_unused_fd(link_fd);
}
void bpf_link_inc(struct bpf_link *link)
err = bpf_trampoline_link_prog(prog);
if (err) {
- bpf_link_defunct(&link->link);
- fput(link_file);
- put_unused_fd(link_fd);
+ bpf_link_cleanup(&link->link, link_file, link_fd);
goto out_put_prog;
}
err = bpf_probe_register(link->btp, prog);
if (err) {
- bpf_link_defunct(&link->link);
- fput(link_file);
- put_unused_fd(link_fd);
+ bpf_link_cleanup(&link->link, link_file, link_fd);
goto out_put_btp;
}