From c5202ffebfb0348945d1287752f9f9411cc73eea Mon Sep 17 00:00:00 2001 From: Paul Lawrence Date: Wed, 26 Apr 2023 14:11:58 -0700 Subject: [PATCH] ANDROID: fuse-bpf: Simplify and fix setting bpf program Fix case when an existing bpf prog is being removed Tidy up code Bug: 279363668 Test: Boots, can copy file to /sdcardfs/Android/data, fuse_test passes Change-Id: If0e682f43cbeb62764a7a2be543b90cb974b0aa0 Signed-off-by: Paul Lawrence --- fs/fuse/backing.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/fs/fuse/backing.c b/fs/fuse/backing.c index f544286dbdaa..e292c557a850 100644 --- a/fs/fuse/backing.c +++ b/fs/fuse/backing.c @@ -1235,39 +1235,36 @@ int fuse_handle_backing(struct fuse_entry_bpf *feb, struct inode **backing_inode int fuse_handle_bpf_prog(struct fuse_entry_bpf *feb, struct inode *parent, struct bpf_prog **bpf) { - struct bpf_prog *new_bpf; - - /* Parent isn't presented, but we want to keep - * Don't touch bpf program at all in this case - */ - if (feb->out.bpf_action == FUSE_ACTION_KEEP && !parent) - return 0; + struct bpf_prog *new_bpf = NULL; switch (feb->out.bpf_action) { case FUSE_ACTION_KEEP: { - struct fuse_inode *pi = get_fuse_inode(parent); + /* Parent isn't presented, but we want to keep + * Don't touch bpf program at all in this case + */ + if (!parent) + return 0; - new_bpf = pi->bpf; + new_bpf = get_fuse_inode(parent)->bpf; if (new_bpf) bpf_prog_inc(new_bpf); break; } case FUSE_ACTION_REMOVE: - new_bpf = NULL; break; case FUSE_ACTION_REPLACE: { struct file *bpf_file = feb->bpf_file; - struct bpf_prog *bpf_prog = ERR_PTR(-EINVAL); - - if (bpf_file && !IS_ERR(bpf_file)) - bpf_prog = fuse_get_bpf_prog(bpf_file); - if (IS_ERR(bpf_prog)) - return PTR_ERR(bpf_prog); + if (!bpf_file) + return -EINVAL; + if (IS_ERR(bpf_file)) + return PTR_ERR(bpf_file); - new_bpf = bpf_prog; + new_bpf = fuse_get_bpf_prog(bpf_file); + if (IS_ERR(new_bpf)) + return PTR_ERR(new_bpf); break; } @@ -1276,11 +1273,14 @@ int fuse_handle_bpf_prog(struct fuse_entry_bpf *feb, struct inode *parent, } /* Cannot change existing program */ - if (*bpf) { + if (*bpf && new_bpf) { bpf_prog_put(new_bpf); return new_bpf == *bpf ? 0 : -EINVAL; } + if (*bpf) + bpf_prog_put(*bpf); + *bpf = new_bpf; return 0; }