From: Konstantin Adzer <info@massivetech.ru>
To: Alexander Viro <viro@zeniv.linux.org.uk>,
Christian Brauner <brauner@kernel.org>
Cc: Jonathan Corbet <corbet@lwn.net>,
Shuah Khan <skhan@linuxfoundation.org>,
Randy Dunlap <rdunlap@infradead.org>,
Dan Williams <djbw@kernel.org>,
Vishal Verma <vishal.l.verma@intel.com>,
Dave Jiang <dave.jiang@intel.com>,
Alison Schofield <alison.schofield@intel.com>,
Eric Van Hensbergen <ericvh@kernel.org>,
Latchesar Ionkov <lucho@ionkov.net>,
Dominique Martinet <asmadeus@codewreck.org>,
Christian Schoenebeck <linux_oss@crudebyte.com>,
David Sterba <dsterba@suse.com>,
David Howells <dhowells@redhat.com>,
Marc Dionne <marc.dionne@auristor.com>,
Luis de Bethencourt <luisbg@kernel.org>,
Salah Triki <salah.triki@gmail.com>,
Chris Mason <mason@kernel.org>, Ilya Dryomov <idryomov@gmail.com>,
Alex Markuze <amarkuze@redhat.com>, Xiubo Li <xiubo.li@clyso.com>,
Viacheslav Dubeyko <slava@dubeyko.com>,
Jan Harkes <jaharkes@cs.cmu.edu>,
coda@cs.cmu.edu, Nicolas Pitre <nico@fluxnic.net>,
Tyler Hicks <code@tyhicks.com>, Gao Xiang <xiang@kernel.org>,
Chao Yu <chao@kernel.org>, Yue Hu <zbestahu@gmail.com>,
Jingbo Xu <jefflexu@163.com>,
Sandeep Dhavale <dhavale@google.com>,
Hongbo Li <hongbohbli@tencent.com>,
Chunhai Guo <guochunhai@vivo.com>, Jan Kara <jack@suse.cz>,
"Theodore Ts'o" <tytso@mit.edu>,
Andreas Dilger <adilger.kernel@dilger.ca>,
Baokun Li <libaokun@linux.alibaba.com>,
Ojaswin Mujoo <ojaswin@linux.ibm.com>,
"Ritesh Harjani (IBM)" <ritesh.list@gmail.com>,
Zhang Yi <yi.zhang@huawei.com>, Jaegeuk Kim <jaegeuk@kernel.org>,
Miklos Szeredi <miklos@szeredi.hu>,
Andreas Gruenbacher <agruenba@redhat.com>,
John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>,
Yangtao Li <frank.li@vivo.com>,
Richard Weinberger <richard@nod.at>,
Anton Ivanov <anton.ivanov@cambridgegreys.com>,
Johannes Berg <johannes@sipsolutions.net>,
Mikulas Patocka <mikulas@artax.karlin.mff.cuni.cz>,
David Woodhouse <dwmw2@infradead.org>,
Dave Kleikamp <shaggy@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Tejun Heo <tj@kernel.org>, Trond Myklebust <trondmy@kernel.org>,
Anna Schumaker <anna@kernel.org>,
Ryusuke Konishi <konishi.ryusuke@gmail.com>,
Namjae Jeon <linkinjeon@kernel.org>,
Hyunchul Lee <hyc.lee@gmail.com>,
Konstantin Komarov <almaz.alexandrovich@paragon-software.com>,
Mark Fasheh <mark@fasheh.com>, Joel Becker <jlbec@evilplan.org>,
Joseph Qi <joseph.qi@linux.alibaba.com>,
Heming Zhao <heming.zhao@suse.com>,
Mike Marshall <hubcap@omnibond.com>,
Martin Brandenburg <martin@omnibond.com>,
Amir Goldstein <amir73il@gmail.com>,
Anders Larsen <al@alarsen.net>,
Paulo Alcantara <pc@manguebit.org>,
Ronnie Sahlberg <ronniesahlberg@gmail.com>,
Shyam Prasad N <sprasad@microsoft.com>,
Tom Talpey <tom@talpey.com>, Bharath SM <bharathsm@microsoft.com>,
Phillip Lougher <phillip@squashfs.org.uk>,
Zhihao Cheng <chengzhihao1@huawei.com>,
Jori Koolstra <jkoolstra@xs4all.nl>,
Damien Le Moal <dlemoal@kernel.org>,
Naohiro Aota <naohiro.aota@wdc.com>,
Johannes Thumshirn <jth@kernel.org>,
Johannes Weiner <hannes@cmpxchg.org>,
"Michal Koutný" <mkoutny@suse.com>,
linux-doc@vger.kernel.org, nvdimm@lists.linux.dev,
linux-cxl@vger.kernel.org, v9fs@lists.linux.dev,
linux-fsdevel@vger.kernel.org, linux-afs@lists.infradead.org,
linux-kernel@vger.kernel.org, linux-btrfs@vger.kernel.org,
ceph-devel@vger.kernel.org, codalist@coda.cs.cmu.edu,
ecryptfs@vger.kernel.org, linux-erofs@lists.ozlabs.org,
linux-ext4@vger.kernel.org,
linux-f2fs-devel@lists.sourceforge.net,
fuse-devel@lists.linux.dev, gfs2@lists.linux.dev,
linux-um@lists.infradead.org, linux-mtd@lists.infradead.org,
jfs-discussion@lists.sourceforge.net,
driver-core@lists.linux.dev, linux-nfs@vger.kernel.org,
linux-nilfs@vger.kernel.org, ntfs@lists.linux.dev,
ntfs3@lists.linux.dev, ocfs2-devel@lists.linux.dev,
devel@lists.orangefs.org, linux-unionfs@vger.kernel.org,
linux-cifs@vger.kernel.org, samba-technical@lists.samba.org,
cgroups@vger.kernel.org
Subject: [PATCH 3/3] fs: return ERR_PTR() from iget_locked() and friends
Date: Tue, 1 Dec 2026 16:09:57 +0300 [thread overview]
Message-ID: <367d7105e3efbc364ff4feb2facd723ad5ab0cc3.1796132090.git.info@massivetech.ru> (raw)
In-Reply-To: <cover.1796132090.git.info@massivetech.ru>
find_inode() and find_inode_fast() return ERR_PTR(-ESTALE) for an inode
that is being created (I_CREATING), but iget_locked(), iget5_locked(),
iget5_locked_rcu() and inode_insert5() turn that into NULL, as they do
with a failed allocation and with an error from the set() callback.
Callers can only read NULL as -ENOMEM.
open_by_handle_at() on ext4 hits this when the handle points to a
deleted inode whose number is being reused by a file under creation:
ext4_fh_to_dentry()
ext4_nfs_get_inode()
__ext4_iget(..., EXT4_IGET_HANDLE)
iget_locked() -> NULL, find_inode_fast() saw I_CREATING
__ext4_iget() -> ERR_PTR(-ENOMEM)
The caller gets ENOMEM instead of ESTALE although memory is not short,
and nfsd turns it into a jukebox/DELAY error, so an NFS client retries
instead of getting a stale file handle.
Make the four helpers return ERR_PTR(): -ENOMEM if no inode could be
allocated, -ESTALE for an inode under creation, and the error returned
by set(). insert_inode_locked4() still returns -EBUSY when it runs into
an inode under creation. Convert all callers to IS_ERR() and pass the
error on where they returned -ENOMEM so far. Wrappers that handed NULL
to their own callers (btrfs_iget_locked(), cifs_iget(), dax_dev_get(),
kernfs_get_inode(), nilfs_iget_locked(), ovl_iget5()) return the
ERR_PTR() as well.
Besides -ESTALE, callers now see:
- the -EIO or -ENOMEM of the set() callbacks of hfs, hostfs and ntfs
instead of -ENOMEM;
- in ecryptfs, the error instead of -EACCES.
overlayfs keeps -EEXIST for a new inode that collides with an inode
under creation.
Fixes: c2b6d621c4ff ("new primitive: discard_new_inode()")
Closes: https://lore.kernel.org/179612584364.3457081.15142720814992093613@massivetech.ru
Signed-off-by: Konstantin Adzer <info@massivetech.ru>
---
Documentation/filesystems/porting.rst | 9 ++
drivers/dax/super.c | 8 +-
fs/9p/vfs_inode.c | 4 +-
fs/9p/vfs_inode_dotl.c | 4 +-
fs/affs/inode.c | 4 +-
fs/afs/dynroot.c | 14 +--
fs/afs/inode.c | 12 +--
fs/befs/linuxvfs.c | 4 +-
fs/btrfs/inode.c | 12 +--
fs/ceph/inode.c | 4 +-
fs/coda/cnode.c | 4 +-
fs/cramfs/inode.c | 4 +-
fs/ecryptfs/inode.c | 4 +-
fs/erofs/inode.c | 4 +-
fs/erofs/ishare.c | 6 +-
fs/ext2/inode.c | 4 +-
fs/ext4/inode.c | 4 +-
fs/f2fs/inode.c | 4 +-
fs/fuse/inode.c | 4 +-
fs/gfs2/inode.c | 4 +-
fs/hfs/btree.c | 2 +-
fs/hfs/inode.c | 4 +-
fs/hfsplus/super.c | 4 +-
fs/hostfs/hostfs_kern.c | 4 +-
fs/hpfs/dir.c | 3 +-
fs/hpfs/inode.c | 2 +-
fs/hpfs/super.c | 2 +-
fs/inode.c | 126 +++++++++++++++-----------
fs/isofs/inode.c | 4 +-
fs/jffs2/fs.c | 4 +-
fs/jfs/inode.c | 4 +-
fs/kernfs/inode.c | 8 +-
fs/kernfs/mount.c | 4 +-
fs/minix/inode.c | 4 +-
fs/nfs/inode.c | 4 +-
fs/nilfs2/cpfile.c | 4 +-
fs/nilfs2/dat.c | 4 +-
fs/nilfs2/ifile.c | 4 +-
fs/nilfs2/inode.c | 16 ++--
fs/nilfs2/sufile.c | 4 +-
fs/ntfs/inode.c | 12 +--
fs/ntfs3/inode.c | 4 +-
fs/ocfs2/inode.c | 3 +-
fs/openpromfs/inode.c | 5 +-
fs/orangefs/inode.c | 4 +-
fs/overlayfs/inode.c | 10 +-
fs/qnx4/inode.c | 4 +-
fs/qnx6/inode.c | 4 +-
fs/romfs/super.c | 4 +-
fs/smb/client/file.c | 5 +-
fs/smb/client/inode.c | 12 ++-
fs/smb/client/readdir.c | 2 -
fs/squashfs/inode.c | 4 +-
fs/ubifs/super.c | 4 +-
fs/udf/inode.c | 4 +-
fs/ufs/inode.c | 4 +-
fs/vboxsf/super.c | 4 +-
fs/zonefs/super.c | 8 +-
include/linux/kernfs.h | 2 +-
kernel/cgroup/cgroup.c | 4 +-
60 files changed, 228 insertions(+), 203 deletions(-)
diff --git a/Documentation/filesystems/porting.rst b/Documentation/filesystems/porting.rst
index 7d89f741f8b2..b13b11eb172c 100644
--- a/Documentation/filesystems/porting.rst
+++ b/Documentation/filesystems/porting.rst
@@ -1535,3 +1535,12 @@ the block device is still flushed, so the filesystem decides what its
writeback still writes. Without a journal refusing only the inodes while
the data and the bitmaps go out loses data. A remount to read-only must not
mark the filesystem clean in that state.
+
+---
+
+**mandatory**
+
+iget_locked(), iget5_locked(), iget5_locked_rcu() and inode_insert5() return
+ERR_PTR() instead of NULL on failure: -ENOMEM if no inode could be allocated,
+-ESTALE if the inode is being created (I_CREATING), or the error returned by
+the set() callback. set() must return 0 or a negative errno.
diff --git a/drivers/dax/super.c b/drivers/dax/super.c
index c35a7a27583a..59db8ad6e076 100644
--- a/drivers/dax/super.c
+++ b/drivers/dax/super.c
@@ -573,8 +573,8 @@ static struct dax_device *dax_dev_get(dev_t devt)
inode = iget5_locked(dax_superblock, hash_32(devt + DAXFS_MAGIC, 31),
dax_test, dax_set, &devt);
- if (!inode)
- return NULL;
+ if (IS_ERR(inode))
+ return ERR_CAST(inode);
dax_dev = to_dax_dev(inode);
if (inode_state_read_once(inode) & I_NEW) {
@@ -612,7 +612,7 @@ struct dax_device *alloc_dax(void *private, const struct dax_operations *ops)
devt = MKDEV(MAJOR(dax_devt), minor);
dax_dev = dax_dev_get(devt);
- if (!dax_dev)
+ if (IS_ERR(dax_dev))
goto err_dev;
dax_dev->ops = ops;
@@ -621,7 +621,7 @@ struct dax_device *alloc_dax(void *private, const struct dax_operations *ops)
err_dev:
ida_free(&dax_minor_ida, minor);
- return ERR_PTR(-ENOMEM);
+ return dax_dev;
}
EXPORT_SYMBOL_GPL(alloc_dax);
diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
index 73776416902c..4b3fd24c4b39 100644
--- a/fs/9p/vfs_inode.c
+++ b/fs/9p/vfs_inode.c
@@ -422,8 +422,8 @@ static struct inode *v9fs_qid_iget(struct super_block *sb,
test = v9fs_test_inode;
inode = iget5_locked(sb, QID2INO(qid), test, v9fs_set_inode, st);
- if (!inode)
- return ERR_PTR(-ENOMEM);
+ if (IS_ERR(inode))
+ return inode;
if (!(inode_state_read_once(inode) & I_NEW))
return inode;
/*
diff --git a/fs/9p/vfs_inode_dotl.c b/fs/9p/vfs_inode_dotl.c
index b224a0893177..4bf691e71e14 100644
--- a/fs/9p/vfs_inode_dotl.c
+++ b/fs/9p/vfs_inode_dotl.c
@@ -110,8 +110,8 @@ static struct inode *v9fs_qid_iget_dotl(struct super_block *sb,
test = v9fs_test_inode_dotl;
inode = iget5_locked(sb, QID2INO(qid), test, v9fs_set_inode_dotl, st);
- if (!inode)
- return ERR_PTR(-ENOMEM);
+ if (IS_ERR(inode))
+ return inode;
if (!(inode_state_read_once(inode) & I_NEW))
return inode;
/*
diff --git a/fs/affs/inode.c b/fs/affs/inode.c
index c7de9c793ab8..892469bb2389 100644
--- a/fs/affs/inode.c
+++ b/fs/affs/inode.c
@@ -27,8 +27,8 @@ struct inode *affs_iget(struct super_block *sb, unsigned long ino)
u16 id;
inode = iget_locked(sb, ino);
- if (!inode)
- return ERR_PTR(-ENOMEM);
+ if (IS_ERR(inode))
+ return inode;
if (!(inode_state_read_once(inode) & I_NEW))
return inode;
diff --git a/fs/afs/dynroot.c b/fs/afs/dynroot.c
index 6e3c8c691ba9..5cac5a2f9345 100644
--- a/fs/afs/dynroot.c
+++ b/fs/afs/dynroot.c
@@ -54,9 +54,9 @@ static struct inode *afs_iget_pseudo_dir(struct super_block *sb, ino_t ino)
inode = iget5_locked(sb, fid.vnode,
afs_iget5_pseudo_test, afs_iget5_pseudo_set, &fid);
- if (!inode) {
- _leave(" = -ENOMEM");
- return ERR_PTR(-ENOMEM);
+ if (IS_ERR(inode)) {
+ _leave(" = %ld", PTR_ERR(inode));
+ return inode;
}
_debug("GOT INODE %p { ino=%llu, vl=%llx, vn=%llx, u=%x }",
@@ -254,8 +254,8 @@ static struct dentry *afs_lookup_atcell(struct inode *dir, struct dentry *dentry
inode = iget5_locked(dir->i_sb, fid.vnode,
afs_iget5_pseudo_test, afs_iget5_pseudo_set, &fid);
- if (!inode)
- return ERR_PTR(-ENOMEM);
+ if (IS_ERR(inode))
+ return ERR_CAST(inode);
vnode = AFS_FS_I(inode);
@@ -378,8 +378,8 @@ struct inode *afs_dynroot_iget_root(struct super_block *sb)
inode = iget5_locked(sb, fid.vnode,
afs_iget5_pseudo_test, afs_iget5_pseudo_set, &fid);
- if (!inode)
- return ERR_PTR(-ENOMEM);
+ if (IS_ERR(inode))
+ return inode;
vnode = AFS_FS_I(inode);
diff --git a/fs/afs/inode.c b/fs/afs/inode.c
index af95640da03f..d2d4e4ffd706 100644
--- a/fs/afs/inode.c
+++ b/fs/afs/inode.c
@@ -490,9 +490,9 @@ struct inode *afs_iget(struct afs_operation *op, struct afs_vnode_param *vp)
_enter(",{%llx:%llu.%u},,", vp->fid.vid, vp->fid.vnode, vp->fid.unique);
inode = iget5_locked(sb, vp->fid.vnode, afs_iget5_test, afs_iget5_set, vp);
- if (!inode) {
- _leave(" = -ENOMEM");
- return ERR_PTR(-ENOMEM);
+ if (IS_ERR(inode)) {
+ _leave(" = %ld", PTR_ERR(inode));
+ return inode;
}
vnode = AFS_FS_I(inode);
@@ -554,9 +554,9 @@ struct inode *afs_root_iget(struct super_block *sb, struct key *key)
_enter(",{%llx},,", as->volume->vid);
inode = iget5_locked(sb, 1, NULL, afs_iget5_set_root, NULL);
- if (!inode) {
- _leave(" = -ENOMEM");
- return ERR_PTR(-ENOMEM);
+ if (IS_ERR(inode)) {
+ _leave(" = %ld", PTR_ERR(inode));
+ return inode;
}
_debug("GOT ROOT INODE %p { vl=%llx }", inode, as->volume->vid);
diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
index f715dd71a38c..3233e5e1c284 100644
--- a/fs/befs/linuxvfs.c
+++ b/fs/befs/linuxvfs.c
@@ -307,8 +307,8 @@ static struct inode *befs_iget(struct super_block *sb, unsigned long ino)
befs_debug(sb, "---> %s inode = %lu", __func__, ino);
inode = iget_locked(sb, ino);
- if (!inode)
- return ERR_PTR(-ENOMEM);
+ if (IS_ERR(inode))
+ return inode;
if (!(inode_state_read_once(inode) & I_NEW))
return inode;
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 415c5145fcbe..0cb4d831963c 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -5892,8 +5892,8 @@ static struct btrfs_inode *btrfs_iget_locked(u64 ino, struct btrfs_root *root)
inode = iget5_locked_rcu(root->fs_info->sb, hashval, btrfs_find_actor,
btrfs_init_locked_inode,
(void *)&args);
- if (!inode)
- return NULL;
+ if (IS_ERR(inode))
+ return ERR_CAST(inode);
return BTRFS_I(inode);
}
@@ -5908,8 +5908,8 @@ struct btrfs_inode *btrfs_iget_path(u64 ino, struct btrfs_root *root,
int ret;
inode = btrfs_iget_locked(ino, root);
- if (!inode)
- return ERR_PTR(-ENOMEM);
+ if (IS_ERR(inode))
+ return inode;
if (!(inode_state_read_once(&inode->vfs_inode) & I_NEW))
return inode;
@@ -5932,8 +5932,8 @@ struct btrfs_inode *btrfs_iget(u64 ino, struct btrfs_root *root)
int ret;
inode = btrfs_iget_locked(ino, root);
- if (!inode)
- return ERR_PTR(-ENOMEM);
+ if (IS_ERR(inode))
+ return inode;
if (!(inode_state_read_once(&inode->vfs_inode) & I_NEW))
return inode;
diff --git a/fs/ceph/inode.c b/fs/ceph/inode.c
index 9bd117ce4c7c..14c07cb0df44 100644
--- a/fs/ceph/inode.c
+++ b/fs/ceph/inode.c
@@ -203,9 +203,9 @@ struct inode *ceph_get_inode(struct super_block *sb, struct ceph_vino vino,
ceph_ino_compare, ceph_set_ino_cb, &vino);
}
- if (!inode) {
+ if (IS_ERR(inode)) {
doutc(cl, "no inode found for %llx.%llx\n", vino.ino, vino.snap);
- return ERR_PTR(-ENOMEM);
+ return inode;
}
doutc(cl, "on %llx=%llx.%llx got %p new %d\n",
diff --git a/fs/coda/cnode.c b/fs/coda/cnode.c
index 70bb0579b40c..d092c783d8dd 100644
--- a/fs/coda/cnode.c
+++ b/fs/coda/cnode.c
@@ -67,8 +67,8 @@ struct inode * coda_iget(struct super_block * sb, struct CodaFid * fid,
retry:
inode = iget5_locked(sb, hash, coda_test_inode, coda_set_inode, fid);
- if (!inode)
- return ERR_PTR(-ENOMEM);
+ if (IS_ERR(inode))
+ return inode;
if (inode_state_read_once(inode) & I_NEW) {
cii = ITOC(inode);
diff --git a/fs/cramfs/inode.c b/fs/cramfs/inode.c
index b55eb3bd29c1..b706b891023a 100644
--- a/fs/cramfs/inode.c
+++ b/fs/cramfs/inode.c
@@ -94,8 +94,8 @@ static struct inode *get_cramfs_inode(struct super_block *sb,
static struct timespec64 zerotime;
inode = iget_locked(sb, cramino(cramfs_inode, offset));
- if (!inode)
- return ERR_PTR(-ENOMEM);
+ if (IS_ERR(inode))
+ return inode;
if (!(inode_state_read_once(inode) & I_NEW))
return inode;
diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
index 35afb94143b8..18e38838eaf7 100644
--- a/fs/ecryptfs/inode.c
+++ b/fs/ecryptfs/inode.c
@@ -99,9 +99,9 @@ static struct inode *__ecryptfs_get_inode(struct inode *lower_inode,
inode = iget5_locked(sb, (unsigned long)lower_inode,
ecryptfs_inode_test, ecryptfs_inode_set,
lower_inode);
- if (!inode) {
+ if (IS_ERR(inode)) {
iput(lower_inode);
- return ERR_PTR(-EACCES);
+ return inode;
}
if (!(inode_state_read_once(inode) & I_NEW))
iput(lower_inode);
diff --git a/fs/erofs/inode.c b/fs/erofs/inode.c
index 26ea3790ff21..a81b314651c1 100644
--- a/fs/erofs/inode.c
+++ b/fs/erofs/inode.c
@@ -296,8 +296,8 @@ struct inode *erofs_iget(struct super_block *sb, erofs_nid_t nid)
inode = iget5_locked(sb, erofs_squash_ino(sb, nid), erofs_iget5_eq,
erofs_iget5_set, &nid);
- if (!inode)
- return ERR_PTR(-ENOMEM);
+ if (IS_ERR(inode))
+ return inode;
if (inode_state_read_once(inode) & I_NEW) {
int err = erofs_fill_inode(inode);
diff --git a/fs/erofs/ishare.c b/fs/erofs/ishare.c
index ea146fa8a27c..373dcc682ac8 100644
--- a/fs/erofs/ishare.c
+++ b/fs/erofs/ishare.c
@@ -58,7 +58,7 @@ bool erofs_ishare_fill_inode(struct inode *inode)
si = iget5_locked(erofs_ishare_mnt->mnt_sb,
xxh32(fp.opaque, fp.size, 0),
erofs_ishare_iget5_eq, erofs_ishare_iget5_set, &fp);
- if (si && (inode_state_read_once(si) & I_NEW)) {
+ if (!IS_ERR(si) && (inode_state_read_once(si) & I_NEW)) {
si->i_fop = &backing_fops;
si->i_mapping->a_ops = aops;
si->i_mode = 0444 | S_IFREG;
@@ -68,7 +68,9 @@ bool erofs_ishare_fill_inode(struct inode *inode)
unlock_new_inode(si);
} else {
kfree(fp.opaque);
- if (!si || aops != si->i_mapping->a_ops ||
+ if (IS_ERR(si))
+ return false;
+ if (aops != si->i_mapping->a_ops ||
si->i_blkbits != inode->i_blkbits) {
iput(si);
return false;
diff --git a/fs/ext2/inode.c b/fs/ext2/inode.c
index 24efe68b6cb8..8fac6513fae0 100644
--- a/fs/ext2/inode.c
+++ b/fs/ext2/inode.c
@@ -1359,8 +1359,8 @@ struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
gid_t i_gid;
inode = iget_locked(sb, ino);
- if (!inode)
- return ERR_PTR(-ENOMEM);
+ if (IS_ERR(inode))
+ return inode;
if (!(inode_state_read_once(inode) & I_NEW))
return inode;
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index e3129353d4ed..aa2298c7fb17 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -6226,8 +6226,8 @@ struct inode *__ext4_iget(struct super_block *sb, unsigned long ino,
}
} else {
inode = iget_locked(sb, ino);
- if (!inode)
- return ERR_PTR(-ENOMEM);
+ if (IS_ERR(inode))
+ return inode;
}
if (!(inode_state_read_once(inode) & I_NEW)) {
diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c
index 9164a2b5d9f0..9b6aaf1ec7aa 100644
--- a/fs/f2fs/inode.c
+++ b/fs/f2fs/inode.c
@@ -581,8 +581,8 @@ struct inode *f2fs_iget(struct super_block *sb, unsigned long ino)
int ret = 0;
inode = iget_locked(sb, ino);
- if (!inode)
- return ERR_PTR(-ENOMEM);
+ if (IS_ERR(inode))
+ return inode;
if (!(inode_state_read_once(inode) & I_NEW)) {
trace_f2fs_iget(inode);
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index 23a4bbf5dfa0..99d3985cdbbe 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -516,8 +516,8 @@ 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 ERR_PTR(-ENOMEM);
+ if (IS_ERR(inode))
+ return inode;
is_new_inode = inode_state_read_once(inode) & I_NEW;
if (is_new_inode) {
diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
index 75fb1a0c9142..fefc6b914e7e 100644
--- a/fs/gfs2/inode.c
+++ b/fs/gfs2/inode.c
@@ -136,8 +136,8 @@ struct inode *gfs2_inode_lookup(struct super_block *sb, unsigned int type,
gfs2_holder_mark_uninitialized(&i_gh);
inode = iget5_locked(sb, no_addr, iget_test, iget_set, &no_addr);
- if (!inode)
- return ERR_PTR(-ENOMEM);
+ if (IS_ERR(inode))
+ return inode;
ip = GFS2_I(inode);
diff --git a/fs/hfs/btree.c b/fs/hfs/btree.c
index 4f0ddc76e8c5..012f29f2e92a 100644
--- a/fs/hfs/btree.c
+++ b/fs/hfs/btree.c
@@ -156,7 +156,7 @@ struct hfs_btree *hfs_btree_open(struct super_block *sb, u32 id, btree_keycmp ke
tree->keycmp = keycmp;
tree->inode = iget_locked(sb, id);
- if (!tree->inode)
+ if (IS_ERR(tree->inode))
goto free_tree;
BUG_ON(!(inode_state_read_once(tree->inode) & I_NEW));
{
diff --git a/fs/hfs/inode.c b/fs/hfs/inode.c
index b836b2f8d544..152d5f566adf 100644
--- a/fs/hfs/inode.c
+++ b/fs/hfs/inode.c
@@ -454,8 +454,8 @@ struct inode *hfs_iget(struct super_block *sb, struct hfs_cat_key *key, hfs_cat_
return ERR_PTR(-EIO);
}
inode = iget5_locked(sb, cnid, hfs_test_inode, hfs_read_inode, &data);
- if (!inode)
- return ERR_PTR(-ENOMEM);
+ if (IS_ERR(inode))
+ return inode;
if (inode_state_read_once(inode) & I_NEW)
unlock_new_inode(inode);
return inode;
diff --git a/fs/hfsplus/super.c b/fs/hfsplus/super.c
index 532f23502df3..ba13a3e6a4ce 100644
--- a/fs/hfsplus/super.c
+++ b/fs/hfsplus/super.c
@@ -69,8 +69,8 @@ struct inode *hfsplus_iget(struct super_block *sb, unsigned long ino)
int err;
inode = iget_locked(sb, ino);
- if (!inode)
- return ERR_PTR(-ENOMEM);
+ if (IS_ERR(inode))
+ return inode;
if (!(inode_state_read_once(inode) & I_NEW))
return inode;
diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
index 613146e76dec..8e9eef568916 100644
--- a/fs/hostfs/hostfs_kern.c
+++ b/fs/hostfs/hostfs_kern.c
@@ -578,8 +578,8 @@ static struct inode *hostfs_iget(struct super_block *sb, char *name)
inode = iget5_locked(sb, st.ino, hostfs_inode_test, hostfs_inode_set,
&st);
- if (!inode)
- return ERR_PTR(-ENOMEM);
+ if (IS_ERR(inode))
+ return inode;
if (inode_state_read_once(inode) & I_NEW) {
unlock_new_inode(inode);
diff --git a/fs/hpfs/dir.c b/fs/hpfs/dir.c
index a82c06635b89..add849cdc429 100644
--- a/fs/hpfs/dir.c
+++ b/fs/hpfs/dir.c
@@ -242,9 +242,8 @@ struct dentry *hpfs_lookup(struct inode *dir, struct dentry *dentry, unsigned in
*/
result = iget_locked(dir->i_sb, ino);
- if (!result) {
+ if (IS_ERR(result)) {
hpfs_error(dir->i_sb, "hpfs_lookup: can't get inode");
- result = ERR_PTR(-ENOMEM);
goto bail1;
}
if (inode_state_read_once(result) & I_NEW) {
diff --git a/fs/hpfs/inode.c b/fs/hpfs/inode.c
index 396773d0b669..9dac9cae5eb8 100644
--- a/fs/hpfs/inode.c
+++ b/fs/hpfs/inode.c
@@ -194,7 +194,7 @@ void hpfs_write_inode(struct inode *i)
return;
}
parent = iget_locked(i->i_sb, hpfs_inode->i_parent_dir);
- if (parent) {
+ if (!IS_ERR(parent)) {
hpfs_inode->i_dirty = 0;
if (inode_state_read_once(parent) & I_NEW) {
hpfs_init_inode(parent);
diff --git a/fs/hpfs/super.c b/fs/hpfs/super.c
index a9e26ae2e375..97a851e046d2 100644
--- a/fs/hpfs/super.c
+++ b/fs/hpfs/super.c
@@ -653,7 +653,7 @@ static int hpfs_fill_super(struct super_block *s, struct fs_context *fc)
brelse(bh0);
root = iget_locked(s, sbi->sb_root);
- if (!root)
+ if (IS_ERR(root))
goto bail0;
hpfs_init_inode(root);
hpfs_read_inode(root);
diff --git a/fs/inode.c b/fs/inode.c
index bf9403c32188..b3b903cdeb56 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -1313,7 +1313,10 @@ EXPORT_SYMBOL(unlock_two_nondirectories);
* to fill it in before unlocking it via unlock_new_inode().
*
* Note that both @test and @set are called with the inode_hash_lock held, so
- * they can't sleep.
+ * they can't sleep. @set returns 0 or a negative errno.
+ *
+ * Return: the inode, or ERR_PTR(-ESTALE) if a matching inode is being
+ * created, or the ERR_PTR() of the error returned by @set.
*/
struct inode *inode_insert5(struct inode *inode, u64 hashval,
int (*test)(struct inode *, void *),
@@ -1322,6 +1325,7 @@ struct inode *inode_insert5(struct inode *inode, u64 hashval,
struct hlist_head *head = inode_hashtable + hash(inode->i_sb, hashval);
struct inode *old;
bool isnew;
+ int err;
might_sleep();
@@ -1335,7 +1339,7 @@ struct inode *inode_insert5(struct inode *inode, u64 hashval,
*/
spin_unlock(&inode_hash_lock);
if (IS_ERR(old))
- return NULL;
+ return old;
if (unlikely(isnew))
wait_on_new_inode(old);
if (unlikely(inode_unhashed(old))) {
@@ -1345,9 +1349,12 @@ struct inode *inode_insert5(struct inode *inode, u64 hashval,
return old;
}
- if (set && unlikely(set(inode, data))) {
- spin_unlock(&inode_hash_lock);
- return NULL;
+ if (set) {
+ err = set(inode, data);
+ if (unlikely(err)) {
+ spin_unlock(&inode_hash_lock);
+ return ERR_PTR(err);
+ }
}
/*
@@ -1390,7 +1397,10 @@ EXPORT_SYMBOL(inode_insert5);
* gets to fill it in before unlocking it via unlock_new_inode().
*
* Note that both @test and @set are called with the inode_hash_lock held, so
- * they can't sleep.
+ * they can't sleep. @set returns 0 or a negative errno.
+ *
+ * Return: the inode, or ERR_PTR(-ENOMEM) if no inode could be allocated,
+ * or an error from inode_insert5().
*/
struct inode *iget5_locked(struct super_block *sb, u64 hashval,
int (*test)(struct inode *, void *),
@@ -1401,11 +1411,11 @@ struct inode *iget5_locked(struct super_block *sb, u64 hashval,
if (!inode) {
struct inode *new = alloc_inode(sb);
- if (new) {
- inode = inode_insert5(new, hashval, test, set, data);
- if (unlikely(inode != new))
- destroy_inode(new);
- }
+ if (!new)
+ return ERR_PTR(-ENOMEM);
+ inode = inode_insert5(new, hashval, test, set, data);
+ if (unlikely(inode != new))
+ destroy_inode(new);
}
return inode;
}
@@ -1421,6 +1431,10 @@ EXPORT_SYMBOL(iget5_locked);
*
* This is equivalent to iget5_locked, except the @test callback must
* tolerate the inode not being stable, including being mid-teardown.
+ *
+ * Return: the inode, or ERR_PTR(-ENOMEM) if no inode could be allocated,
+ * or ERR_PTR(-ESTALE) if a matching inode is being created, or an error
+ * from inode_insert5().
*/
struct inode *iget5_locked_rcu(struct super_block *sb, u64 hashval,
int (*test)(struct inode *, void *),
@@ -1436,7 +1450,7 @@ struct inode *iget5_locked_rcu(struct super_block *sb, u64 hashval,
inode = find_inode(sb, head, test, data, false, &isnew);
if (inode) {
if (IS_ERR(inode))
- return NULL;
+ return inode;
if (unlikely(isnew))
wait_on_new_inode(inode);
if (unlikely(inode_unhashed(inode))) {
@@ -1447,11 +1461,11 @@ struct inode *iget5_locked_rcu(struct super_block *sb, u64 hashval,
}
new = alloc_inode(sb);
- if (new) {
- inode = inode_insert5(new, hashval, test, set, data);
- if (unlikely(inode != new))
- destroy_inode(new);
- }
+ if (!new)
+ return ERR_PTR(-ENOMEM);
+ inode = inode_insert5(new, hashval, test, set, data);
+ if (unlikely(inode != new))
+ destroy_inode(new);
return inode;
}
EXPORT_SYMBOL_GPL(iget5_locked_rcu);
@@ -1468,11 +1482,14 @@ EXPORT_SYMBOL_GPL(iget5_locked_rcu);
* If the inode is not in cache, allocate a new inode and return it locked,
* hashed, and with the I_NEW flag set. The file system gets to fill it in
* before unlocking it via unlock_new_inode().
+ *
+ * Return: the inode, or ERR_PTR(-ENOMEM) if no inode could be allocated,
+ * or ERR_PTR(-ESTALE) if the inode is being created.
*/
struct inode *iget_locked(struct super_block *sb, u64 ino)
{
struct hlist_head *head = inode_hashtable + hash(sb, ino);
- struct inode *inode;
+ struct inode *inode, *old;
bool isnew;
might_sleep();
@@ -1481,7 +1498,7 @@ struct inode *iget_locked(struct super_block *sb, u64 ino)
inode = find_inode_fast(sb, head, ino, false, &isnew);
if (inode) {
if (IS_ERR(inode))
- return NULL;
+ return inode;
if (unlikely(isnew))
wait_on_new_inode(inode);
if (unlikely(inode_unhashed(inode))) {
@@ -1492,45 +1509,43 @@ struct inode *iget_locked(struct super_block *sb, u64 ino)
}
inode = alloc_inode(sb);
- if (inode) {
- struct inode *old;
-
- spin_lock(&inode_hash_lock);
- /* We released the lock, so.. */
- old = find_inode_fast(sb, head, ino, true, &isnew);
- if (!old) {
- inode->i_ino = ino;
- spin_lock(&inode->i_lock);
- inode_state_assign(inode, I_NEW);
- hlist_add_head_rcu(&inode->i_hash, head);
- spin_unlock(&inode->i_lock);
- spin_unlock(&inode_hash_lock);
- inode_sb_list_add(inode);
+ if (!inode)
+ return ERR_PTR(-ENOMEM);
- /* Return the locked inode with I_NEW set, the
- * caller is responsible for filling in the contents
- */
- return inode;
- }
+ spin_lock(&inode_hash_lock);
+ /* We released the lock, so.. */
+ old = find_inode_fast(sb, head, ino, true, &isnew);
+ if (!old) {
+ inode->i_ino = ino;
+ spin_lock(&inode->i_lock);
+ inode_state_assign(inode, I_NEW);
+ hlist_add_head_rcu(&inode->i_hash, head);
+ spin_unlock(&inode->i_lock);
+ spin_unlock(&inode_hash_lock);
+ inode_sb_list_add(inode);
- /*
- * Uhhuh, somebody else created the same inode under
- * us. Use the old inode instead of the one we just
- * allocated.
+ /* Return the locked inode with I_NEW set, the
+ * caller is responsible for filling in the contents
*/
- spin_unlock(&inode_hash_lock);
- destroy_inode(inode);
- if (IS_ERR(old))
- return NULL;
- inode = old;
- if (unlikely(isnew))
- wait_on_new_inode(inode);
- if (unlikely(inode_unhashed(inode))) {
- iput(inode);
- goto again;
- }
+ return inode;
}
- return inode;
+
+ /*
+ * Uhhuh, somebody else created the same inode under
+ * us. Use the old inode instead of the one we just
+ * allocated.
+ */
+ spin_unlock(&inode_hash_lock);
+ destroy_inode(inode);
+ if (IS_ERR(old))
+ return old;
+ if (unlikely(isnew))
+ wait_on_new_inode(old);
+ if (unlikely(inode_unhashed(old))) {
+ iput(old);
+ goto again;
+ }
+ return old;
}
EXPORT_SYMBOL(iget_locked);
@@ -1965,7 +1980,8 @@ int insert_inode_locked4(struct inode *inode, u64 hashval,
old = inode_insert5(inode, hashval, test, NULL, data);
if (old != inode) {
- iput(old);
+ if (!IS_ERR(old))
+ iput(old);
return -EBUSY;
}
return 0;
diff --git a/fs/isofs/inode.c b/fs/isofs/inode.c
index 4824e42995cc..47212eed8269 100644
--- a/fs/isofs/inode.c
+++ b/fs/isofs/inode.c
@@ -1504,8 +1504,8 @@ struct inode *__isofs_iget(struct super_block *sb,
inode = iget5_locked(sb, hashval, &isofs_iget5_test,
&isofs_iget5_set, &data);
- if (!inode)
- return ERR_PTR(-ENOMEM);
+ if (IS_ERR(inode))
+ return inode;
if (inode_state_read_once(inode) & I_NEW) {
ret = isofs_read_inode(inode, relocated);
diff --git a/fs/jffs2/fs.c b/fs/jffs2/fs.c
index 05cf860307c7..20f6b86a3cc6 100644
--- a/fs/jffs2/fs.c
+++ b/fs/jffs2/fs.c
@@ -263,8 +263,8 @@ struct inode *jffs2_iget(struct super_block *sb, unsigned long ino)
jffs2_dbg(1, "%s(): ino == %lu\n", __func__, ino);
inode = iget_locked(sb, ino);
- if (!inode)
- return ERR_PTR(-ENOMEM);
+ if (IS_ERR(inode))
+ return inode;
if (!(inode_state_read_once(inode) & I_NEW))
return inode;
diff --git a/fs/jfs/inode.c b/fs/jfs/inode.c
index 2f9d6d311de9..6ba8a8ce194e 100644
--- a/fs/jfs/inode.c
+++ b/fs/jfs/inode.c
@@ -27,8 +27,8 @@ struct inode *jfs_iget(struct super_block *sb, unsigned long ino)
int ret;
inode = iget_locked(sb, ino);
- if (!inode)
- return ERR_PTR(-ENOMEM);
+ if (IS_ERR(inode))
+ return inode;
if (!(inode_state_read_once(inode) & I_NEW))
return inode;
diff --git a/fs/kernfs/inode.c b/fs/kernfs/inode.c
index 580095e0fad9..30d1bf473930 100644
--- a/fs/kernfs/inode.c
+++ b/fs/kernfs/inode.c
@@ -331,14 +331,14 @@ static void kernfs_init_inode(struct kernfs_node *kn, struct inode *inode)
* sets up their inodes itself, with kernfs_rwsem held.
*
* Return:
- * Pointer to allocated inode on success, %NULL on failure.
+ * Pointer to allocated inode on success, ERR_PTR() on failure.
*/
struct inode *kernfs_get_inode(struct super_block *sb, struct kernfs_node *kn)
{
struct inode *inode;
inode = iget_locked(sb, kernfs_ino(kn));
- if (inode && (inode_state_read_once(inode) & I_NEW))
+ if (!IS_ERR(inode) && (inode_state_read_once(inode) & I_NEW))
kernfs_init_inode(kn, inode);
return inode;
@@ -362,8 +362,8 @@ static int kernfs_inode_test(struct inode *inode, void *data)
* allocation can block in reclaim and hold up other users of the lock.
*
* Returns the inode now attached to @kn, which is @inode unless one was
- * already hashed for it (e.g. by a file handle decode), or NULL if @kn
- * is no longer active.
+ * already hashed for it (e.g. by a file handle decode), NULL if @kn
+ * is no longer active, or the ERR_PTR() returned by inode_insert5().
*/
struct inode *kernfs_get_inode_locked(struct inode *inode,
struct kernfs_node *kn)
diff --git a/fs/kernfs/mount.c b/fs/kernfs/mount.c
index 9691ad4218e1..f2e485606d31 100644
--- a/fs/kernfs/mount.c
+++ b/fs/kernfs/mount.c
@@ -327,9 +327,9 @@ static int kernfs_fill_super(struct super_block *sb, struct kernfs_fs_context *k
down_read(&kf_root->kernfs_rwsem);
inode = kernfs_get_inode_locked(new, info->root->kn);
up_read(&kf_root->kernfs_rwsem);
- if (!inode) {
+ if (IS_ERR_OR_NULL(inode)) {
pr_debug("kernfs: could not get root inode\n");
- return -ENOMEM;
+ return inode ? PTR_ERR(inode) : -ENOMEM;
}
/* instantiate and link root dentry */
diff --git a/fs/minix/inode.c b/fs/minix/inode.c
index 9fb938ec5868..ce4707df57f7 100644
--- a/fs/minix/inode.c
+++ b/fs/minix/inode.c
@@ -617,8 +617,8 @@ struct inode *minix_iget(struct super_block *sb, unsigned long ino)
struct inode *inode;
inode = iget_locked(sb, ino);
- if (!inode)
- return ERR_PTR(-ENOMEM);
+ if (IS_ERR(inode))
+ return inode;
if (!(inode_state_read_once(inode) & I_NEW))
return inode;
diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
index 5a682f74d7d1..de6c70c47c64 100644
--- a/fs/nfs/inode.c
+++ b/fs/nfs/inode.c
@@ -455,10 +455,8 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr)
hash = fattr->fileid;
inode = iget5_locked(sb, hash, nfs_find_actor, nfs_init_locked, &desc);
- if (inode == NULL) {
- inode = ERR_PTR(-ENOMEM);
+ if (IS_ERR(inode))
goto out_no_inode;
- }
if (inode_state_read_once(inode) & I_NEW) {
struct nfs_inode *nfsi = NFS_I(inode);
diff --git a/fs/nilfs2/cpfile.c b/fs/nilfs2/cpfile.c
index d3349fa58abe..a2484fbfdb68 100644
--- a/fs/nilfs2/cpfile.c
+++ b/fs/nilfs2/cpfile.c
@@ -1158,8 +1158,8 @@ int nilfs_cpfile_read(struct super_block *sb, size_t cpsize,
}
cpfile = nilfs_iget_locked(sb, NULL, NILFS_CPFILE_INO);
- if (unlikely(!cpfile))
- return -ENOMEM;
+ if (IS_ERR(cpfile))
+ return PTR_ERR(cpfile);
if (!(inode_state_read_once(cpfile) & I_NEW))
goto out;
diff --git a/fs/nilfs2/dat.c b/fs/nilfs2/dat.c
index 888dc1831c86..366a8a608266 100644
--- a/fs/nilfs2/dat.c
+++ b/fs/nilfs2/dat.c
@@ -504,8 +504,8 @@ int nilfs_dat_read(struct super_block *sb, size_t entry_size,
}
dat = nilfs_iget_locked(sb, NULL, NILFS_DAT_INO);
- if (unlikely(!dat))
- return -ENOMEM;
+ if (IS_ERR(dat))
+ return PTR_ERR(dat);
if (!(inode_state_read_once(dat) & I_NEW))
goto out;
diff --git a/fs/nilfs2/ifile.c b/fs/nilfs2/ifile.c
index c99e1e6356ae..b25b74e2ee40 100644
--- a/fs/nilfs2/ifile.c
+++ b/fs/nilfs2/ifile.c
@@ -185,8 +185,8 @@ int nilfs_ifile_read(struct super_block *sb, struct nilfs_root *root,
int err;
ifile = nilfs_iget_locked(sb, root, NILFS_IFILE_INO);
- if (unlikely(!ifile))
- return -ENOMEM;
+ if (IS_ERR(ifile))
+ return PTR_ERR(ifile);
if (!(inode_state_read_once(ifile) & I_NEW))
goto out;
diff --git a/fs/nilfs2/inode.c b/fs/nilfs2/inode.c
index 1e336af4a471..9522f4e1404c 100644
--- a/fs/nilfs2/inode.c
+++ b/fs/nilfs2/inode.c
@@ -538,8 +538,8 @@ struct inode *nilfs_iget(struct super_block *sb, struct nilfs_root *root,
int err;
inode = nilfs_iget_locked(sb, root, ino);
- if (unlikely(!inode))
- return ERR_PTR(-ENOMEM);
+ if (IS_ERR(inode))
+ return inode;
if (!(inode_state_read_once(inode) & I_NEW)) {
if (!inode->i_nlink) {
@@ -567,8 +567,8 @@ struct inode *nilfs_iget_for_gc(struct super_block *sb, u64 ino, __u64 cno)
int err;
inode = iget5_locked(sb, ino, nilfs_iget_test, nilfs_iget_set, &args);
- if (unlikely(!inode))
- return ERR_PTR(-ENOMEM);
+ if (IS_ERR(inode))
+ return inode;
if (!(inode_state_read_once(inode) & I_NEW))
return inode;
@@ -607,8 +607,8 @@ int nilfs_attach_btree_node_cache(struct inode *inode)
btnc_inode = iget5_locked(inode->i_sb, inode->i_ino, nilfs_iget_test,
nilfs_iget_set, &args);
- if (unlikely(!btnc_inode))
- return -ENOMEM;
+ if (IS_ERR(btnc_inode))
+ return PTR_ERR(btnc_inode);
if (inode_state_read_once(btnc_inode) & I_NEW) {
nilfs_init_btnc_inode(btnc_inode);
unlock_new_inode(btnc_inode);
@@ -662,8 +662,8 @@ struct inode *nilfs_iget_for_shadow(struct inode *inode)
s_inode = iget5_locked(inode->i_sb, inode->i_ino, nilfs_iget_test,
nilfs_iget_set, &args);
- if (unlikely(!s_inode))
- return ERR_PTR(-ENOMEM);
+ if (IS_ERR(s_inode))
+ return s_inode;
if (!(inode_state_read_once(s_inode) & I_NEW))
return inode;
diff --git a/fs/nilfs2/sufile.c b/fs/nilfs2/sufile.c
index fec5af70c6dd..6bf6b20522f2 100644
--- a/fs/nilfs2/sufile.c
+++ b/fs/nilfs2/sufile.c
@@ -1232,8 +1232,8 @@ int nilfs_sufile_read(struct super_block *sb, size_t susize,
}
sufile = nilfs_iget_locked(sb, NULL, NILFS_SUFILE_INO);
- if (unlikely(!sufile))
- return -ENOMEM;
+ if (IS_ERR(sufile))
+ return PTR_ERR(sufile);
if (!(inode_state_read_once(sufile) & I_NEW))
goto out;
diff --git a/fs/ntfs/inode.c b/fs/ntfs/inode.c
index 48ec7a0c98b9..ae145ae8456c 100644
--- a/fs/ntfs/inode.c
+++ b/fs/ntfs/inode.c
@@ -200,8 +200,8 @@ struct inode *ntfs_iget(struct super_block *sb, u64 mft_no)
vi = iget5_locked(sb, mft_no, ntfs_test_inode,
ntfs_init_locked_inode, &na);
- if (unlikely(!vi))
- return ERR_PTR(-ENOMEM);
+ if (IS_ERR(vi))
+ return vi;
err = 0;
@@ -264,8 +264,8 @@ struct inode *ntfs_attr_iget(struct inode *base_vi, __le32 type,
vi = iget5_locked(base_vi->i_sb, na.mft_no, ntfs_test_inode,
ntfs_init_locked_inode, &na);
- if (unlikely(!vi))
- return ERR_PTR(-ENOMEM);
+ if (IS_ERR(vi))
+ return vi;
err = 0;
/* If this is a freshly allocated inode, need to read it now. */
@@ -320,8 +320,8 @@ struct inode *ntfs_index_iget(struct inode *base_vi, __le16 *name,
vi = iget5_locked(base_vi->i_sb, na.mft_no, ntfs_test_inode,
ntfs_init_locked_inode, &na);
- if (unlikely(!vi))
- return ERR_PTR(-ENOMEM);
+ if (IS_ERR(vi))
+ return vi;
err = 0;
diff --git a/fs/ntfs3/inode.c b/fs/ntfs3/inode.c
index 45f894d182dd..832744c27ba4 100644
--- a/fs/ntfs3/inode.c
+++ b/fs/ntfs3/inode.c
@@ -708,8 +708,8 @@ struct inode *ntfs_iget5_flags(struct super_block *sb,
}
inode = iget5_locked(sb, ino, ntfs_test_inode, ntfs_set_inode, &ig5);
- if (unlikely(!inode)) {
- err = -ENOMEM;
+ if (IS_ERR(inode)) {
+ err = PTR_ERR(inode);
goto out;
}
diff --git a/fs/ocfs2/inode.c b/fs/ocfs2/inode.c
index e225a96d3753..eb3dbb6eb7f1 100644
--- a/fs/ocfs2/inode.c
+++ b/fs/ocfs2/inode.c
@@ -181,8 +181,7 @@ struct inode *ocfs2_iget(struct ocfs2_super *osb, u64 blkno, unsigned flags,
/* inode was *not* in the inode cache. 2.6.x requires
* us to do our own read_inode call and unlock it
* afterwards. */
- if (inode == NULL) {
- inode = ERR_PTR(-ENOMEM);
+ if (IS_ERR(inode)) {
mlog_errno(PTR_ERR(inode));
goto bail;
}
diff --git a/fs/openpromfs/inode.c b/fs/openpromfs/inode.c
index 6cd02d456bac..308635a0e62d 100644
--- a/fs/openpromfs/inode.c
+++ b/fs/openpromfs/inode.c
@@ -350,10 +350,7 @@ static void openprom_free_inode(struct inode *inode)
static struct inode *openprom_iget(struct super_block *sb, ino_t ino)
{
- struct inode *inode = iget_locked(sb, ino);
- if (!inode)
- inode = ERR_PTR(-ENOMEM);
- return inode;
+ return iget_locked(sb, ino);
}
static int openpromfs_reconfigure(struct fs_context *fc)
diff --git a/fs/orangefs/inode.c b/fs/orangefs/inode.c
index b1fed1c81a4d..111a314d6258 100644
--- a/fs/orangefs/inode.c
+++ b/fs/orangefs/inode.c
@@ -1082,8 +1082,8 @@ struct inode *orangefs_iget(struct super_block *sb,
orangefs_set_inode,
ref);
- if (!inode)
- return ERR_PTR(-ENOMEM);
+ if (IS_ERR(inode))
+ return inode;
if (!(inode_state_read_once(inode) & I_NEW))
return inode;
diff --git a/fs/overlayfs/inode.c b/fs/overlayfs/inode.c
index f1c6df39d0ae..0b87c5a50e55 100644
--- a/fs/overlayfs/inode.c
+++ b/fs/overlayfs/inode.c
@@ -1163,8 +1163,8 @@ struct inode *ovl_get_trap_inode(struct super_block *sb, struct dentry *dir)
trap = iget5_locked(sb, (unsigned long) key, ovl_inode_test,
ovl_inode_set, key);
- if (!trap)
- return ERR_PTR(-ENOMEM);
+ if (IS_ERR(trap))
+ return trap;
if (!(inode_state_read_once(trap) & I_NEW)) {
/* Conflicting layer roots? */
@@ -1239,7 +1239,7 @@ struct inode *ovl_get_inode(struct super_block *sb,
int fsid = bylower ? lowerpath->layer->fsid : 0;
bool is_dir;
unsigned long ino = 0;
- int err = oip->newinode ? -EEXIST : -ENOMEM;
+ int err;
if (!realinode)
realinode = d_inode(lowerdentry);
@@ -1255,8 +1255,10 @@ struct inode *ovl_get_inode(struct super_block *sb,
unsigned int nlink = is_dir ? 1 : realinode->i_nlink;
inode = ovl_iget5(sb, oip->newinode, key);
- if (!inode)
+ if (IS_ERR(inode)) {
+ err = oip->newinode ? -EEXIST : PTR_ERR(inode);
goto out_err;
+ }
if (!(inode_state_read_once(inode) & I_NEW)) {
/*
* Verify that the underlying files stored in the inode
diff --git a/fs/qnx4/inode.c b/fs/qnx4/inode.c
index 42fcd500fad2..a527cfd3e0f5 100644
--- a/fs/qnx4/inode.c
+++ b/fs/qnx4/inode.c
@@ -289,8 +289,8 @@ struct inode *qnx4_iget(struct super_block *sb, unsigned long ino)
struct inode *inode;
inode = iget_locked(sb, ino);
- if (!inode)
- return ERR_PTR(-ENOMEM);
+ if (IS_ERR(inode))
+ return inode;
if (!(inode_state_read_once(inode) & I_NEW))
return inode;
diff --git a/fs/qnx6/inode.c b/fs/qnx6/inode.c
index 7df3eed5142d..ee350b158d92 100644
--- a/fs/qnx6/inode.c
+++ b/fs/qnx6/inode.c
@@ -519,8 +519,8 @@ struct inode *qnx6_iget(struct super_block *sb, unsigned ino)
u32 n, offs;
inode = iget_locked(sb, ino);
- if (!inode)
- return ERR_PTR(-ENOMEM);
+ if (IS_ERR(inode))
+ return inode;
if (!(inode_state_read_once(inode) & I_NEW))
return inode;
diff --git a/fs/romfs/super.c b/fs/romfs/super.c
index 7f783d6173e8..45bf252d16bb 100644
--- a/fs/romfs/super.c
+++ b/fs/romfs/super.c
@@ -307,8 +307,8 @@ static struct inode *romfs_iget(struct super_block *sb, unsigned long pos)
/* get an inode for this image position */
i = iget_locked(sb, pos);
- if (!i)
- return ERR_PTR(-ENOMEM);
+ if (IS_ERR(i))
+ return i;
if (!(inode_state_read_once(i) & I_NEW))
return i;
diff --git a/fs/smb/client/file.c b/fs/smb/client/file.c
index d272320436b3..ab35a214583a 100644
--- a/fs/smb/client/file.c
+++ b/fs/smb/client/file.c
@@ -979,8 +979,9 @@ int cifs_posix_open(const char *full_path, struct inode **pinode,
if (*pinode == NULL) {
cifs_fill_uniqueid(sb, &fattr);
*pinode = cifs_iget(sb, &fattr);
- if (!*pinode) {
- rc = -ENOMEM;
+ if (IS_ERR(*pinode)) {
+ rc = PTR_ERR(*pinode);
+ *pinode = NULL;
goto posix_open_ret;
}
} else {
diff --git a/fs/smb/client/inode.c b/fs/smb/client/inode.c
index 31f9a9ea5ec8..8a42160ef7ba 100644
--- a/fs/smb/client/inode.c
+++ b/fs/smb/client/inode.c
@@ -393,8 +393,10 @@ static int update_inode_info(struct super_block *sb,
if (!*inode) {
*inode = cifs_iget(sb, fattr);
- if (!*inode)
- rc = -ENOMEM;
+ if (IS_ERR(*inode)) {
+ rc = PTR_ERR(*inode);
+ *inode = NULL;
+ }
return rc;
}
/* We already have inode, update it.
@@ -1652,7 +1654,7 @@ cifs_iget(struct super_block *sb, struct cifs_fattr *fattr)
hash = cifs_uniqueid_to_ino_t(fattr->cf_uniqueid);
inode = iget5_locked(sb, hash, cifs_find_inode, cifs_init_inode, fattr);
- if (inode) {
+ if (!IS_ERR(inode)) {
/* was there a potentially problematic inode collision? */
if (fattr->cf_flags & CIFS_FATTR_INO_COLLISION) {
fattr->cf_flags &= ~CIFS_FATTR_INO_COLLISION;
@@ -1729,6 +1731,8 @@ struct inode *cifs_root_iget(struct super_block *sb)
cifs_autodisable_serverino(cifs_sb, "Cannot retrieve attributes for junction point", rc);
}
inode = cifs_iget(sb, &fattr);
+ if (IS_ERR(inode))
+ goto out;
}
if (!inode) {
@@ -2273,7 +2277,7 @@ cifs_posix_mkdir(struct inode *inode, struct dentry *dentry, umode_t mode,
cifs_unix_basic_to_fattr(&fattr, info, cifs_sb);
cifs_fill_uniqueid(inode->i_sb, &fattr);
newinode = cifs_iget(inode->i_sb, &fattr);
- if (!newinode)
+ if (IS_ERR(newinode))
goto posix_mkdir_get_info;
d_instantiate(dentry, newinode);
diff --git a/fs/smb/client/readdir.c b/fs/smb/client/readdir.c
index 85ed65241ece..cbcfe387dbd8 100644
--- a/fs/smb/client/readdir.c
+++ b/fs/smb/client/readdir.c
@@ -159,8 +159,6 @@ cifs_prime_dcache(struct dentry *parent, struct qstr *name,
goto retry;
} else {
inode = cifs_iget(sb, fattr);
- if (!inode)
- inode = ERR_PTR(-ENOMEM);
alias = d_splice_alias(inode, dentry);
d_lookup_done(dentry);
if (alias && !IS_ERR(alias))
diff --git a/fs/squashfs/inode.c b/fs/squashfs/inode.c
index 82b687414e65..b415975ac97b 100644
--- a/fs/squashfs/inode.c
+++ b/fs/squashfs/inode.c
@@ -84,8 +84,8 @@ struct inode *squashfs_iget(struct super_block *sb, long long ino,
TRACE("Entered squashfs_iget\n");
- if (!inode)
- return ERR_PTR(-ENOMEM);
+ if (IS_ERR(inode))
+ return inode;
if (!(inode_state_read_once(inode) & I_NEW))
return inode;
diff --git a/fs/ubifs/super.c b/fs/ubifs/super.c
index a441bd2ddf83..174ce9ee501d 100644
--- a/fs/ubifs/super.c
+++ b/fs/ubifs/super.c
@@ -112,8 +112,8 @@ struct inode *ubifs_iget(struct super_block *sb, unsigned long inum)
dbg_gen("inode %lu", inum);
inode = iget_locked(sb, inum);
- if (!inode)
- return ERR_PTR(-ENOMEM);
+ if (IS_ERR(inode))
+ return inode;
if (!(inode_state_read_once(inode) & I_NEW))
return inode;
ui = ubifs_inode(inode);
diff --git a/fs/udf/inode.c b/fs/udf/inode.c
index 29900065673c..f51a939ea2b6 100644
--- a/fs/udf/inode.c
+++ b/fs/udf/inode.c
@@ -2015,8 +2015,8 @@ struct inode *__udf_iget(struct super_block *sb, struct kernel_lb_addr *ino,
struct inode *inode = iget_locked(sb, block);
int err;
- if (!inode)
- return ERR_PTR(-ENOMEM);
+ if (IS_ERR(inode))
+ return inode;
if (!(inode_state_read_once(inode) & I_NEW)) {
if (UDF_I(inode)->i_hidden != hidden_inode) {
diff --git a/fs/ufs/inode.c b/fs/ufs/inode.c
index fec701330d67..9d00e75c8fab 100644
--- a/fs/ufs/inode.c
+++ b/fs/ufs/inode.c
@@ -653,8 +653,8 @@ struct inode *ufs_iget(struct super_block *sb, unsigned long ino)
}
inode = iget_locked(sb, ino);
- if (!inode)
- return ERR_PTR(-ENOMEM);
+ if (IS_ERR(inode))
+ return inode;
if (!(inode_state_read_once(inode) & I_NEW))
return inode;
diff --git a/fs/vboxsf/super.c b/fs/vboxsf/super.c
index 190b76f04d4f..edd5e8e2584b 100644
--- a/fs/vboxsf/super.c
+++ b/fs/vboxsf/super.c
@@ -200,8 +200,8 @@ static int vboxsf_fill_super(struct super_block *sb, struct fs_context *fc)
set_default_d_op(sb, &vboxsf_dentry_ops);
iroot = iget_locked(sb, 0);
- if (!iroot) {
- err = -ENOMEM;
+ if (IS_ERR(iroot)) {
+ err = PTR_ERR(iroot);
goto fail_unmap;
}
vboxsf_init_inode(sbi, iroot, &sbi->root_info, false);
diff --git a/fs/zonefs/super.c b/fs/zonefs/super.c
index d843e6148227..92b0a3c29cbe 100644
--- a/fs/zonefs/super.c
+++ b/fs/zonefs/super.c
@@ -657,8 +657,8 @@ static struct inode *zonefs_get_file_inode(struct inode *dir,
z = &zgroup->g_zones[fno];
ino = z->z_sector >> sbi->s_zone_sectors_shift;
inode = iget_locked(sb, ino);
- if (!inode)
- return ERR_PTR(-ENOMEM);
+ if (IS_ERR(inode))
+ return inode;
if (!(inode_state_read_once(inode) & I_NEW)) {
WARN_ON_ONCE(inode->i_private != z);
return inode;
@@ -696,8 +696,8 @@ static struct inode *zonefs_get_zgroup_inode(struct super_block *sb,
ino_t ino = bdev_nr_zones(sb->s_bdev) + ztype + 1;
inode = iget_locked(sb, ino);
- if (!inode)
- return ERR_PTR(-ENOMEM);
+ if (IS_ERR(inode))
+ return inode;
if (!(inode_state_read_once(inode) & I_NEW))
return inode;
diff --git a/include/linux/kernfs.h b/include/linux/kernfs.h
index 803294a67e47..582a19e2c995 100644
--- a/include/linux/kernfs.h
+++ b/include/linux/kernfs.h
@@ -529,7 +529,7 @@ static inline struct kernfs_root *kernfs_root_from_sb(struct super_block *sb)
static inline struct inode *
kernfs_get_inode(struct super_block *sb, struct kernfs_node *kn)
-{ return NULL; }
+{ return ERR_PTR(-ENODEV); }
static inline struct kernfs_root *
kernfs_create_root(struct kernfs_syscall_ops *scops, unsigned int flags,
diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index 32479c0f77af..3774aebf2fa6 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -5434,8 +5434,8 @@ static int cgroup_may_write(const struct cgroup *cgrp, struct super_block *sb)
lockdep_assert_held(&cgroup_mutex);
inode = kernfs_get_inode(sb, cgrp->procs_file.kn);
- if (!inode)
- return -ENOMEM;
+ if (IS_ERR(inode))
+ return PTR_ERR(inode);
ret = inode_permission(&nop_mnt_idmap, inode, MAY_WRITE);
iput(inode);
--
2.56.1
prev parent reply other threads:[~2026-12-01 13:35 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 13:34 [PATCH 0/3] fs: return ERR_PTR() from iget_locked() and friends Konstantin Adzer
2026-12-01 13:06 ` [PATCH 1/3] fuse: return ERR_PTR() from fuse_iget() Konstantin Adzer
2026-12-01 13:06 ` [PATCH 2/3] hfs: return ERR_PTR() from hfs_iget() Konstantin Adzer
2026-12-01 13:09 ` Konstantin Adzer [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=367d7105e3efbc364ff4feb2facd723ad5ab0cc3.1796132090.git.info@massivetech.ru \
--to=info@massivetech.ru \
--cc=adilger.kernel@dilger.ca \
--cc=agruenba@redhat.com \
--cc=al@alarsen.net \
--cc=alison.schofield@intel.com \
--cc=almaz.alexandrovich@paragon-software.com \
--cc=amarkuze@redhat.com \
--cc=amir73il@gmail.com \
--cc=anna@kernel.org \
--cc=anton.ivanov@cambridgegreys.com \
--cc=asmadeus@codewreck.org \
--cc=bharathsm@microsoft.com \
--cc=brauner@kernel.org \
--cc=ceph-devel@vger.kernel.org \
--cc=cgroups@vger.kernel.org \
--cc=chao@kernel.org \
--cc=chengzhihao1@huawei.com \
--cc=coda@cs.cmu.edu \
--cc=codalist@coda.cs.cmu.edu \
--cc=code@tyhicks.com \
--cc=corbet@lwn.net \
--cc=dave.jiang@intel.com \
--cc=devel@lists.orangefs.org \
--cc=dhavale@google.com \
--cc=dhowells@redhat.com \
--cc=djbw@kernel.org \
--cc=dlemoal@kernel.org \
--cc=driver-core@lists.linux.dev \
--cc=dsterba@suse.com \
--cc=dwmw2@infradead.org \
--cc=ecryptfs@vger.kernel.org \
--cc=ericvh@kernel.org \
--cc=frank.li@vivo.com \
--cc=fuse-devel@lists.linux.dev \
--cc=gfs2@lists.linux.dev \
--cc=glaubitz@physik.fu-berlin.de \
--cc=gregkh@linuxfoundation.org \
--cc=guochunhai@vivo.com \
--cc=hannes@cmpxchg.org \
--cc=heming.zhao@suse.com \
--cc=hongbohbli@tencent.com \
--cc=hubcap@omnibond.com \
--cc=hyc.lee@gmail.com \
--cc=idryomov@gmail.com \
--cc=jack@suse.cz \
--cc=jaegeuk@kernel.org \
--cc=jaharkes@cs.cmu.edu \
--cc=jefflexu@163.com \
--cc=jfs-discussion@lists.sourceforge.net \
--cc=jkoolstra@xs4all.nl \
--cc=jlbec@evilplan.org \
--cc=johannes@sipsolutions.net \
--cc=joseph.qi@linux.alibaba.com \
--cc=jth@kernel.org \
--cc=konishi.ryusuke@gmail.com \
--cc=libaokun@linux.alibaba.com \
--cc=linkinjeon@kernel.org \
--cc=linux-afs@lists.infradead.org \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-cifs@vger.kernel.org \
--cc=linux-cxl@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-erofs@lists.ozlabs.org \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=linux-nfs@vger.kernel.org \
--cc=linux-nilfs@vger.kernel.org \
--cc=linux-um@lists.infradead.org \
--cc=linux-unionfs@vger.kernel.org \
--cc=linux_oss@crudebyte.com \
--cc=lucho@ionkov.net \
--cc=luisbg@kernel.org \
--cc=marc.dionne@auristor.com \
--cc=mark@fasheh.com \
--cc=martin@omnibond.com \
--cc=mason@kernel.org \
--cc=miklos@szeredi.hu \
--cc=mikulas@artax.karlin.mff.cuni.cz \
--cc=mkoutny@suse.com \
--cc=naohiro.aota@wdc.com \
--cc=nico@fluxnic.net \
--cc=ntfs3@lists.linux.dev \
--cc=ntfs@lists.linux.dev \
--cc=nvdimm@lists.linux.dev \
--cc=ocfs2-devel@lists.linux.dev \
--cc=ojaswin@linux.ibm.com \
--cc=pc@manguebit.org \
--cc=phillip@squashfs.org.uk \
--cc=rdunlap@infradead.org \
--cc=richard@nod.at \
--cc=ritesh.list@gmail.com \
--cc=ronniesahlberg@gmail.com \
--cc=salah.triki@gmail.com \
--cc=samba-technical@lists.samba.org \
--cc=shaggy@kernel.org \
--cc=skhan@linuxfoundation.org \
--cc=slava@dubeyko.com \
--cc=sprasad@microsoft.com \
--cc=tj@kernel.org \
--cc=tom@talpey.com \
--cc=trondmy@kernel.org \
--cc=tytso@mit.edu \
--cc=v9fs@lists.linux.dev \
--cc=viro@zeniv.linux.org.uk \
--cc=vishal.l.verma@intel.com \
--cc=xiang@kernel.org \
--cc=xiubo.li@clyso.com \
--cc=yi.zhang@huawei.com \
--cc=zbestahu@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox