Linux Documentation
 help / color / mirror / Atom feed
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 2/3] hfs: return ERR_PTR() from hfs_iget()
Date: Tue, 1 Dec 2026 16:06:10 +0300	[thread overview]
Message-ID: <66c696d294765fa5692ba07a5dcc4e7a2b41887f.1796132090.git.info@massivetech.ru> (raw)
In-Reply-To: <cover.1796132090.git.info@massivetech.ru>

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@massivetech.ru>
---
 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);
-- 
2.56.1


  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 ` Konstantin Adzer [this message]
2026-12-01 13:09 ` [PATCH 3/3] fs: return ERR_PTR() from iget_locked() and friends Konstantin Adzer

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=66c696d294765fa5692ba07a5dcc4e7a2b41887f.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