fs: return ERR_PTR() from iget_locked() and friends
Subsystems (47)
cover fs: return ERR_PTR() from iget_locked() and friends
iget_locked(), iget5_locked(), iget5_locked_rcu() and inode_insert5() return NULL for a failed allocation and also for an inode under creation, which find_inode() and find_inode_fast() report as -ESTALE. Callers read NULL as -ENOMEM. As reported in [1], open_by_handle_at() on ext4 then fails with ENOMEM, and nfsd returns a jukebox/DELAY error, for the handle of a deleted inode whose number is being reused. Following the discussion in [2], this series makes the helpers return ERR_PTR().
Patches 1 and 2 make fuse_iget() and hfs_iget() return ERR_PTR(), so that patch 3 can convert the four helpers and all their callers at once.
Testing:
- The reproducer below, in virtme-ng (x86_64 defconfig, 4 CPUs, ext4 on a loop device, 10 seconds): one process creates and unlinks a file in a loop, the other calls open_by_handle_at() with the handle of an earlier, deleted file of that name.
vfs.all at 84fb6f8a1ba9: ESTALE 2312698 ENOMEM 637252
with this series: ESTALE 3394396 ENOMEM 0
dmesg has no messages from the test in either run.
- allmodconfig x86_64 builds of every directory the series touches, with all three patches and with patches 1-2 only; ARCH=um for hostfs; sparc64 for openpromfs. No new warnings. checkpatch --strict reports no errors.
- Not done: run-time tests of filesystems other than ext4 and of the changed error paths in the callers.
The series was written with Claude Code (claude-opus-5-5). I asked it to find out why open_by_handle_at() returns ENOMEM to our file scanner and to fix the cause in the kernel. It traced the error to iget_locked(), wrote the reproducer, the patches, their changelogs and this letter, and ran the builds and the tests above.
[1] https://lore.kernel.org/[email protected]
[2] https://lore.kernel.org/all/20261201-advent-fahrkarte-zierlich-b5b73df9e312@brauner/
Reproducer, run as root: ./iget-repro <empty directory on ext4> <seconds>
#define _GNU_SOURCE
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>
int main(int argc, char **argv)
{
long estale = 0, enomem = 0, other = 0, opened = 0;
struct file_handle *fh;
int mount_id, mfd, fd;
time_t end;
pid_t pid;
if (argc != 3) {
fprintf(stderr, "usage: %s DIR SECONDS\n", argv[0]);
return 2;
}
if (chdir(argv[1]))
return perror("chdir"), 1;
fh = malloc(sizeof(*fh) + MAX_HANDLE_SZ);
fh->handle_bytes = MAX_HANDLE_SZ;
fd = open("f", O_CREAT | O_EXCL | O_WRONLY, 0600);
if (fd < 0 || name_to_handle_at(AT_FDCWD, "f", fh, &mount_id, 0))
return perror("name_to_handle_at"), 1;
close(fd);
unlink("f");
mfd = open(".", O_RDONLY | O_DIRECTORY);
pid = fork();
if (!pid) {
for (;;) {
fd = open("f", O_CREAT | O_EXCL | O_WRONLY, 0600);
if (fd >= 0)
close(fd);
unlink("f");
}
}
end = time(NULL) + atoi(argv[2]);
while (time(NULL) < end) {
fd = open_by_handle_at(mfd, fh, O_RDONLY);
if (fd >= 0) {
opened++;
close(fd);
} else if (errno == ESTALE) {
estale++;
} else if (errno == ENOMEM) {
enomem++;
} else {
other++;
}
}
kill(pid, SIGKILL);
waitpid(pid, NULL, 0);
printf("ESTALE %ld ENOMEM %ld other %ld opened %ld\n",
estale, enomem, other, opened);
return enomem != 0;
}Konstantin Adzer (3):
fuse: return ERR_PTR() from fuse_iget()
hfs: return ERR_PTR() from hfs_iget()
fs: return ERR_PTR() from iget_locked() and friends
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/dir.c | 13 +-- fs/fuse/inode.c | 16 ++-- fs/fuse/readdir.c | 4 +- fs/gfs2/inode.c | 4 +- fs/hfs/btree.c | 2 +- fs/hfs/dir.c | 2 - fs/hfs/inode.c | 8 +- fs/hfs/super.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 +- 64 files changed, 251 insertions(+), 219 deletions(-)
base-commit: 84fb6f8a1ba91eee3ffe6aa519686fce851a0e42
Signature · 1 line
2.56.1
PATCH 2/3 hfs: return ERR_PTR() from hfs_iget()
hfs_iget() returns NULL both for a catalog record that is neither a file nor a directory and for a failed iget5_locked(). hfs_lookup() turns that into -EACCES and hfs_fill_super() into -EINVAL.
Return ERR_PTR(-EIO) for the unexpected record type, the error hfs_read_inode() returns for a bad record, and ERR_PTR(-ENOMEM) for a failed iget5_locked(), and pass the error on in both callers, so that hfs_iget() can forward the error of iget5_locked() once that returns ERR_PTR().
--- fs/hfs/dir.c | 2 -- fs/hfs/inode.c | 8 +++++--- fs/hfs/super.c | 4 +++- 3 files changed, 8 insertions(+), 6 deletions(-)
fs/hfs/dir.c +0 -2
@@ -35,8 +35,6 @@ static struct dentry *hfs_lookup(struct inode *dir, struct dentry *dentry, inode =ERR_PTR (res); }else { inode =hfs_iget (dir->i_sb, &fd.search_key->cat, &rec); -if (!inode) - inode =ERR_PTR (-EACCES ); }hfs_find_exit (&fd);return d_splice_alias (inode, dentry);
fs/hfs/inode.c +5 -3
@@ -433,7 +433,7 @@ static int hfs_read_inode(struct inode *inode, void *data)* * Given the MDB for a HFS filesystem, a 'key' and an 'entry' in * the catalog B-tree and the 'type' of the desired file return the -* inode for that file/directory or NULL. Note that 'type' indicates +* inode for that file/directory or an ERR_PTR(). Note that 'type' indicates * whether we want the actual file or directory, or the corresponding * metadata (AppleDouble header file or CAP metadata file). */
@@ -451,10 +451,12 @@ struct inode *hfs_iget(struct super_block *sb, struct hfs_cat_key *key, hfs_cat_ cnid =be32_to_cpu (rec->file.FlNum);break ;default : -return NULL ; +return ERR_PTR (-EIO ); } inode =iget5_locked (sb, cnid, hfs_test_inode, hfs_read_inode, &data); -if (inode && (inode_state_read_once (inode) &I_NEW )) +if (!inode) +return ERR_PTR (-ENOMEM ); +if (inode_state_read_once (inode) &I_NEW )unlock_new_inode (inode);return inode; }
fs/hfs/super.c +3 -1
@@ -378,8 +378,10 @@ static int hfs_fill_super(struct super_block *sb, struct fs_context *fc) res = -EINVAL ; root_inode =hfs_iget (sb, &fd.search_key->cat, &rec);hfs_find_exit (&fd); -if (!root_inode) +if (IS_ERR (root_inode)) { + res =PTR_ERR (root_inode); goto bail_no_root; + }if (is_bad_inode (root_inode)) {iput (root_inode);
Signature · 1 line
2.56.1
PATCH 3/3 fs: return ERR_PTR() from iget_locked() and friends
In reply to Konstantin Adzerfind_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.
--- 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(-)
Documentation/filesystems/porting.rst +9 -0
@@ -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.
drivers/dax/super.c +4 -4
@@ -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);
fs/9p/vfs_inode.c +2 -2
@@ -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;/*
fs/9p/vfs_inode_dotl.c +2 -2
@@ -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;/*
fs/affs/inode.c +2 -2
@@ -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;
fs/afs/dynroot.c +7 -7
@@ -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);
fs/afs/inode.c +6 -6
@@ -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);
fs/befs/linuxvfs.c +2 -2
@@ -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;
fs/btrfs/inode.c +6 -6
@@ -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;
fs/ceph/inode.c +2 -2
@@ -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",
fs/coda/cnode.c +2 -2
@@ -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);
fs/cramfs/inode.c +2 -2
@@ -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;
fs/ecryptfs/inode.c +2 -2
@@ -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);
fs/erofs/inode.c +2 -2
@@ -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);
fs/erofs/ishare.c +4 -2
@@ -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;
fs/ext2/inode.c +2 -2
@@ -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;
fs/ext4/inode.c +2 -2
@@ -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 )) {
fs/f2fs/inode.c +2 -2
@@ -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);
fs/fuse/inode.c +2 -2
@@ -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) {
fs/gfs2/inode.c +2 -2
@@ -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);
fs/hfs/btree.c +1 -1
@@ -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 )); {
fs/hfs/inode.c +2 -2
@@ -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;
fs/hfsplus/super.c +2 -2
@@ -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;
fs/hostfs/hostfs_kern.c +2 -2
@@ -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);
fs/hpfs/dir.c +1 -2
@@ -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 ) {
fs/hpfs/inode.c +1 -1
@@ -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);
fs/hpfs/super.c +1 -1
@@ -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);
fs/inode.c +71 -55
212 lines not on this page · raw message
fs/isofs/inode.c +2 -2
@@ -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);
fs/jffs2/fs.c +2 -2
@@ -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;
fs/jfs/inode.c +2 -2
@@ -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;
fs/kernfs/inode.c +4 -4
@@ -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)
fs/kernfs/mount.c +2 -2
@@ -327,9 +327,9 @@ static int kernfs_fill_super(struct super_block *sb, struct kernfs_fs_context *kdown_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 */
fs/minix/inode.c +2 -2
@@ -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;
fs/nfs/inode.c +1 -3
@@ -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);
fs/nilfs2/cpfile.c +2 -2
@@ -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;
fs/nilfs2/dat.c +2 -2
@@ -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;
fs/nilfs2/ifile.c +2 -2
@@ -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;
fs/nilfs2/inode.c +8 -8
@@ -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;
fs/nilfs2/sufile.c +2 -2
@@ -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;
fs/ntfs/inode.c +6 -6
@@ -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 ;
fs/ntfs3/inode.c +2 -2
@@ -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; }
fs/ocfs2/inode.c +1 -2
@@ -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; }
fs/openpromfs/inode.c +1 -4
@@ -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)
fs/orangefs/inode.c +2 -2
@@ -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;
fs/overlayfs/inode.c +6 -4
@@ -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
fs/qnx4/inode.c +2 -2
@@ -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;
fs/qnx6/inode.c +2 -2
@@ -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;
fs/romfs/super.c +2 -2
@@ -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;
fs/smb/client/file.c +3 -2
@@ -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 {
fs/smb/client/inode.c +8 -4
@@ -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);
fs/smb/client/readdir.c +0 -2
@@ -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))
fs/squashfs/inode.c +2 -2
@@ -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;
fs/ubifs/super.c +2 -2
@@ -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);
fs/udf/inode.c +2 -2
@@ -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) {
fs/ufs/inode.c +2 -2
@@ -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;
fs/vboxsf/super.c +2 -2
@@ -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);
fs/zonefs/super.c +4 -4
@@ -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;
include/linux/kernfs.h +1 -1
@@ -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,
kernel/cgroup/cgroup.c +2 -2
@@ -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);
Signature · 1 line
2.56.1
PATCH 1/3 fuse: return ERR_PTR() from fuse_iget()
In reply to Konstantin Adzerfuse_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.
--- fs/fuse/dir.c | 13 +++++++------ fs/fuse/inode.c | 14 +++++++++----- fs/fuse/readdir.c | 4 ++-- 3 files changed, 18 insertions(+), 13 deletions(-)
fs/fuse/dir.c +7 -6
@@ -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);
fs/fuse/inode.c +9 -5
@@ -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)
fs/fuse/readdir.c +2 -2
@@ -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);
Signature · 1 line
2.56.1
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 2 related pre-existing issues it does not introduce: - [High] isofs: missing error code in…
Thank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 2 related pre-existing issues it does not introduce:
- [High] isofs: missing error code in out_toomany path of isofs_read_level3_size() [1]
- [High] ufs: division-by-zero in ufs_iget() [2]
--
commit adb88fb457bfb90375b2b0cdbe62297aa9ce6146
Author: Konstantin Adzer <[email protected]>
fs: return ERR_PTR() from iget_locked() and friends
This commit changes iget_locked(), iget5_locked(), iget5_locked_rcu(), and inode_insert5() to return an ERR_PTR() instead of NULL on failure, and updates their callers across the tree to check IS_ERR().
[ ... ]
Quoted 5 lines
fs/isofs/inode.c +0
-0
fs/isofs/inode.c struct inode *__isofs_iget(struct super_block *sb, · line 1511
Quoted 10 lines
fs/isofs/inode.c +2
-2@@ -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);
[Severity: High]
This problem wasn't introduced by this patch, but can isofs_read_level3_size() return 0 on the out_toomany error path when called from isofs_read_inode() [1]?
fs/isofs/inode.c:isofs_read_level3_size() {
...
i++;
if (i > 100)
goto out_toomany;
} while (more_entries);
out:
kfree(tmpde);
brelse(bh);
return 0;
...
out_toomany:
printk(KERN_INFO "%s: More than 100 file sections ?!?, aborting...\n"
"isofs_read_level3_size: inode=%llu\n",
__func__, inode->i_ino);
goto out;
}When an image has a file with more than 100 sections, out_toomany jumps to out and returns 0, so isofs_read_inode() treats the malformed inode as valid and unlocks it with truncated size.
[ ... ]
Quoted 5 lines
fs/ufs/inode.c +0
-0
fs/ufs/inode.c struct inode *ufs_iget(struct super_block *sb, unsigned long ino) · line 660
Quoted 10 lines
fs/ufs/inode.c +2
-2@@ -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;
[Severity: High]
This problem wasn't introduced by this patch, but can ufs_inotofsba() divide by zero right after this check when mounting a corrupted UFS image [2]?
fs/ufs/inode.c:ufs_iget() {
...
ufsi = UFS_I(inode);
bh = sb_bread(sb, uspi->s_sbbase + ufs_inotofsba(inode->i_ino));
}fs/ufs/ufs_fs.h:
#define ufs_inotocg(x) ((unsigned int)(x) / uspi->s_ipg)
#define ufs_inotocgoff(x) ((unsigned int)(x) % uspi->s_ipg)
#define ufs_inotofsba(x) (((u64)ufs_cgimin(ufs_inotocg(x))) + ufs_inotocgoff(x) / uspi->s_inopf)
ufs_fill_super() populates uspi->s_ipg and uspi->s_inopf from the on-disk superblock without checking that they are non-zero, so loading the root inode in ufs_iget() triggers a divide error if either field is zero.
[1] https://sashiko.dev/#/bug/linux-03286deb-aa65-44af-9d0a-7ac38844847c
[2] https://sashiko.dev/#/bug/linux-6bde18a6-cee5-4787-b073-9e622fcafcd9
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
[email protected]
AI reviewSashiko has finished reviewing this 3-patch series:
Sashiko has finished reviewing this 3-patch series:
- Patches 1 and 2: no issues found.
- Patch 3 ("fs: return ERR_PTR() from iget_locked() and friends"): 2 related pre-existing bugs noted
A detailed review has been sent as a separate reply to patch 3.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]