summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBaolin Liu <liubaolin@kylinos.cn>2026-09-07 11:00:43 +0800
committerNamjae Jeon <linkinjeon@kernel.org>2026-09-13 11:42:27 +0900
commit8809c3f29555f9d1e66fe015080a8d4979d91eaa (patch)
tree3a90440d90d1ffc5a626016fed5c7f28c5eadc54
parent55f1164dfb521d898275828f453680d4bc085b0f (diff)
downloadlinux-next-8809c3f29555f9d1e66fe015080a8d4979d91eaa.tar.gz
linux-next-8809c3f29555f9d1e66fe015080a8d4979d91eaa.zip
ntfs: fix error handling in ntfs_extent_inode_open and propagate errors
ntfs_extent_inode_open() has two issues: 1. When map_mft_record() fails or a stale extent reference is found, it returns the non-NULL 'ni' pointer instead of an error, causing the caller to treat the failure as success. 2. For allocation failures, it returns NULL, losing information about what actually went wrong (-ENOMEM). Fix both by converting the function to return ERR_PTR() on error, and update the single caller (ntfs_inode_attach_all_extents) to check with IS_ERR() and propagate the actual error code with PTR_ERR(). Fixes: af0db57d4293 ("ntfs: update inode operations") Signed-off-by: Baolin Liu <liubaolin@kylinos.cn> Reviewed-by: Hyunchul Lee <hyc.lee@gmail.com> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
-rw-r--r--fs/ntfs/inode.c28
1 files changed, 14 insertions, 14 deletions
diff --git a/fs/ntfs/inode.c b/fs/ntfs/inode.c
index cc0e3271a85d..4375ad477809 100644
--- a/fs/ntfs/inode.c
+++ b/fs/ntfs/inode.c
@@ -2915,8 +2915,7 @@ err_out:
* abort if deprotection or checks fail.
*
* Finally attach the ntfs inode to its base inode @base_ni and return a
- * pointer to the ntfs_inode structure on success or NULL on error, with errno
- * set to the error code.
+ * pointer to the ntfs_inode structure on success or ERR_PTR() on error.
*
* Note, extent inodes are never closed directly. They are automatically
* disposed off by the closing of the base inode.
@@ -2932,7 +2931,7 @@ static struct ntfs_inode *ntfs_extent_inode_open(struct ntfs_inode *base_ni,
struct super_block *sb;
if (!base_ni)
- return NULL;
+ return ERR_PTR(-EINVAL);
sb = base_ni->vol->sb;
ntfs_debug("Opening extent inode %llu (base mft record %llu).\n",
@@ -2951,7 +2950,7 @@ static struct ntfs_inode *ntfs_extent_inode_open(struct ntfs_inode *base_ni,
if (IS_ERR(ni_mrec)) {
ntfs_error(sb, "failed to map mft record for %llu",
ni->mft_no);
- goto out;
+ return ERR_CAST(ni_mrec);
}
/* Verify the sequence number if given. */
seq_no = MSEQNO_LE(mref);
@@ -2960,7 +2959,7 @@ static struct ntfs_inode *ntfs_extent_inode_open(struct ntfs_inode *base_ni,
ntfs_error(sb, "Found stale extent mft reference mft=%llu",
ni->mft_no);
unmap_mft_record(ni);
- goto out;
+ return ERR_PTR(-EIO);
}
unmap_mft_record(ni);
goto out;
@@ -2969,7 +2968,7 @@ static struct ntfs_inode *ntfs_extent_inode_open(struct ntfs_inode *base_ni,
/* Wasn't there, we need to load the extent inode. */
ni = ntfs_new_extent_inode(base_ni->vol->sb, mft_no);
if (!ni)
- goto out;
+ return ERR_PTR(-ENOMEM);
ni->seq_no = (u16)MSEQNO_LE(mref);
ni->nr_extents = -1;
@@ -2979,8 +2978,10 @@ static struct ntfs_inode *ntfs_extent_inode_open(struct ntfs_inode *base_ni,
i = (base_ni->nr_extents + 4) * sizeof(struct ntfs_inode *);
extent_nis = kvzalloc(i, GFP_NOFS);
- if (!extent_nis)
- goto err_out;
+ if (!extent_nis) {
+ ntfs_destroy_ext_inode(ni);
+ return ERR_PTR(-ENOMEM);
+ }
if (base_ni->nr_extents) {
memcpy(extent_nis, base_ni->ext.extent_ntfs_inos,
i - 4 * sizeof(struct ntfs_inode *));
@@ -2993,10 +2994,6 @@ static struct ntfs_inode *ntfs_extent_inode_open(struct ntfs_inode *base_ni,
out:
ntfs_debug("\n");
return ni;
-err_out:
- ntfs_destroy_ext_inode(ni);
- ni = NULL;
- goto out;
}
/*
@@ -3034,9 +3031,12 @@ int ntfs_inode_attach_all_extents(struct ntfs_inode *ni)
while ((u8 *)ale < ni->attr_list + ni->attr_list_size) {
if (ni->mft_no != MREF_LE(ale->mft_reference) &&
prev_attached != MREF_LE(ale->mft_reference)) {
- if (!ntfs_extent_inode_open(ni, ale->mft_reference)) {
+ struct ntfs_inode *ext_ni;
+
+ ext_ni = ntfs_extent_inode_open(ni, ale->mft_reference);
+ if (IS_ERR(ext_ni)) {
ntfs_debug("Couldn't attach extent inode.\n");
- return -1;
+ return PTR_ERR(ext_ni);
}
prev_attached = MREF_LE(ale->mft_reference);
}