Re: [PATCH 2/3] hfs: return ERR_PTR() from hfs_iget()
From: Viacheslav Dubeyko
Date: Tue Dec 01 2026 - 17:18:50 EST
On Tue, 2026-12-01 at 16:06 +0300, Konstantin Adzer wrote:
> 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().
>
> Signed-off-by: Konstantin Adzer <info@xxxxxxxxxxxxxx>
> ---
> fs/hfs/dir.c | 2 --
> fs/hfs/inode.c | 8 +++++---
> fs/hfs/super.c | 4 +++-
> 3 files changed, 8 insertions(+), 6 deletions(-)
>
> diff --git a/fs/hfs/dir.c b/fs/hfs/dir.c
> index f6b97da19788..b6b8945712a9 100644
> --- a/fs/hfs/dir.c
> +++ b/fs/hfs/dir.c
> @@ -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);
> diff --git a/fs/hfs/inode.c b/fs/hfs/inode.c
> index 7e590e1308ea..b836b2f8d544 100644
> --- a/fs/hfs/inode.c
> +++ b/fs/hfs/inode.c
> @@ -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;
> }
> diff --git a/fs/hfs/super.c b/fs/hfs/super.c
> index 7abc0e61a222..809da672fb0f 100644
> --- a/fs/hfs/super.c
> +++ b/fs/hfs/super.c
> @@ -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);
Thanks for the patch. However, this change is already in the HFS tree:
e124d2564bdb ("hfs: return ERR_PTR() from hfs_iget()")
It is in the for-next branch of [2] and was posted here [1].
Thanks,
Slava.
[1]
https://lore.kernel.org/r/tencent_190DA969DF79232C4E2FA681510C3E365108@xxxxxx
[2] git://git.kernel.org/pub/scm/linux/kernel/git/vdubeyko/hfs.git