diff --git a/fs/fuse/backing.c b/fs/fuse/backing.c index e292c557a850..19e690aaffb1 100644 --- a/fs/fuse/backing.c +++ b/fs/fuse/backing.c @@ -1273,14 +1273,12 @@ int fuse_handle_bpf_prog(struct fuse_entry_bpf *feb, struct inode *parent, } /* Cannot change existing program */ - if (*bpf && new_bpf) { - bpf_prog_put(new_bpf); + if (*bpf) { + if (new_bpf) + bpf_prog_put(new_bpf); return new_bpf == *bpf ? 0 : -EINVAL; } - if (*bpf) - bpf_prog_put(*bpf); - *bpf = new_bpf; return 0; } diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c index 65f35eeb858b..98b2371a8712 100644 --- a/fs/fuse/inode.c +++ b/fs/fuse/inode.c @@ -113,6 +113,10 @@ static void fuse_free_inode(struct inode *inode) kfree(fi->forget); #ifdef CONFIG_FUSE_DAX kfree(fi->dax); +#endif +#ifdef CONFIG_FUSE_BPF + if (fi->bpf) + bpf_prog_put(fi->bpf); #endif kmem_cache_free(fuse_inode_cachep, fi); } @@ -121,12 +125,6 @@ static void fuse_evict_inode(struct inode *inode) { struct fuse_inode *fi = get_fuse_inode(inode); -#ifdef CONFIG_FUSE_BPF - iput(fi->backing_inode); - if (fi->bpf) - bpf_prog_put(fi->bpf); - fi->bpf = NULL; -#endif truncate_inode_pages_final(&inode->i_data); clear_inode(inode); if (inode->i_sb->s_flags & SB_ACTIVE) { @@ -146,6 +144,15 @@ static void fuse_evict_inode(struct inode *inode) } } +#ifdef CONFIG_FUSE_BPF +static void fuse_destroy_inode(struct inode *inode) +{ + struct fuse_inode *fi = get_fuse_inode(inode); + + iput(fi->backing_inode); +} +#endif + static int fuse_reconfigure(struct fs_context *fc) { struct super_block *sb = fc->root->d_sb; @@ -1088,6 +1095,9 @@ static const struct export_operations fuse_export_operations = { static const struct super_operations fuse_super_operations = { .alloc_inode = fuse_alloc_inode, +#ifdef CONFIG_FUSE_BPF + .destroy_inode = fuse_destroy_inode, +#endif .free_inode = fuse_free_inode, .evict_inode = fuse_evict_inode, .write_inode = fuse_write_inode,