[PATCH 1/3] fuse: return ERR_PTR() from fuse_iget()

From: Konstantin Adzer

Date: Tue Dec 01 2026 - 08:36:49 EST


fuse_iget() returns NULL on any failure, and its callers turn that into
-ENOMEM. Return ERR_PTR(-ENOMEM) instead and pass the error on in the
callers, so that fuse_iget() can forward the error of iget5_locked()
once that returns ERR_PTR().

No functional change.

Signed-off-by: Konstantin Adzer <info@xxxxxxxxxxxxxx>
---
fs/fuse/dir.c | 13 +++++++------
fs/fuse/inode.c | 14 +++++++++-----
fs/fuse/readdir.c | 4 ++--
3 files changed, 18 insertions(+), 13 deletions(-)

diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
index a04d93d5fc44..e6bf99b76993 100644
--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.c
@@ -599,8 +599,9 @@ int fuse_lookup_name(struct super_block *sb, u64 nodeid, const struct qstr *name
*inode = fuse_iget(sb, outarg->nodeid, outarg->generation,
&outarg->attr, ATTR_TIMEOUT(outarg),
attr_version, evict_ctr);
- err = -ENOMEM;
- if (!*inode) {
+ if (IS_ERR(*inode)) {
+ err = PTR_ERR(*inode);
+ *inode = NULL;
fuse_chan_queue_forget(fm->fc->chan, forget, outarg->nodeid, 1);
goto out;
}
@@ -903,11 +904,11 @@ static int fuse_create_open(const struct mnt_idmap *idmap, struct inode *dir,
ff->open_flags = outopenp->open_flags;
inode = fuse_iget(dir->i_sb, outentry.nodeid, outentry.generation,
&outentry.attr, ATTR_TIMEOUT(&outentry), 0, 0);
- if (!inode) {
+ if (IS_ERR(inode)) {
flags &= ~(O_CREAT | O_EXCL | O_TRUNC);
fuse_sync_release(NULL, ff, flags);
fuse_chan_queue_forget(fm->fc->chan, forget, outentry.nodeid, 1);
- err = -ENOMEM;
+ err = PTR_ERR(inode);
goto out_err;
}
kfree(forget);
@@ -1030,9 +1031,9 @@ static struct dentry *create_new_entry(const struct mnt_idmap *idmap, struct fus

inode = fuse_iget(dir->i_sb, outarg.nodeid, outarg.generation,
&outarg.attr, ATTR_TIMEOUT(&outarg), 0, 0);
- if (!inode) {
+ if (IS_ERR(inode)) {
fuse_chan_queue_forget(fm->fc->chan, forget, outarg.nodeid, 1);
- return ERR_PTR(-ENOMEM);
+ return ERR_CAST(inode);
}
fuse_dentry_set_epoch(entry, epoch);
kfree(forget);
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index 399e5b28c111..23a4bbf5dfa0 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -498,7 +498,7 @@ struct inode *fuse_iget(struct super_block *sb, u64 nodeid,

inode = new_inode(sb);
if (!inode)
- return NULL;
+ return ERR_PTR(-ENOMEM);

fuse_init_inode(inode, attr, fc);
fi = get_fuse_inode(inode);
@@ -506,7 +506,7 @@ struct inode *fuse_iget(struct super_block *sb, u64 nodeid,
fi->submount_lookup = fuse_alloc_submount_lookup();
if (!fi->submount_lookup) {
iput(inode);
- return NULL;
+ return ERR_PTR(-ENOMEM);
}
/* Sets nlookup = 1 on fi->submount_lookup->nlookup */
fuse_init_submount_lookup(fi->submount_lookup, nodeid);
@@ -517,7 +517,7 @@ struct inode *fuse_iget(struct super_block *sb, u64 nodeid,
retry:
inode = iget5_locked(sb, nodeid, fuse_inode_eq, fuse_inode_set, &nodeid);
if (!inode)
- return NULL;
+ return ERR_PTR(-ENOMEM);

is_new_inode = inode_state_read_once(inode) & I_NEW;
if (is_new_inode) {
@@ -1716,8 +1716,8 @@ static int fuse_fill_super_submount(struct super_block *sb,
fuse_fill_attr_from_inode(&root_attr, parent_fi);
root = fuse_iget(sb, parent_fi->nodeid, 0, &root_attr, 0, 0,
fuse_get_evict_ctr(fm->fc));
- if (!root)
- return -ENOMEM;
+ if (IS_ERR(root))
+ return PTR_ERR(root);
/*
* This inode is just a duplicate, so it is not looked up and
* its nlookup should not be incremented. fuse_iget() does
@@ -1858,6 +1858,10 @@ int fuse_fill_super_common(struct super_block *sb, struct fuse_fs_context *ctx)

err = -ENOMEM;
root = fuse_get_root_inode(sb, ctx->rootmode);
+ if (IS_ERR(root)) {
+ err = PTR_ERR(root);
+ goto err_free_vdax;
+ }
set_default_d_op(sb, &fuse_dentry_operations);
root_dentry = d_make_root(root);
if (!root_dentry)
diff --git a/fs/fuse/readdir.c b/fs/fuse/readdir.c
index c1e2a8fd834e..880b489ec42c 100644
--- a/fs/fuse/readdir.c
+++ b/fs/fuse/readdir.c
@@ -239,10 +239,10 @@ static int fuse_direntplus_link(struct file *file,
inode = fuse_iget(dir->i_sb, o->nodeid, o->generation,
&o->attr, ATTR_TIMEOUT(o),
attr_version, evict_ctr);
- if (!inode) {
+ if (IS_ERR(inode)) {
d_lookup_done(dentry);
dput(dentry);
- return -ENOMEM;
+ return PTR_ERR(inode);
}

fuse_dentry_set_epoch(dentry, epoch);
--
2.56.1