Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit c935c66

Browse files
fs/ntfs3: Redesign ntfs_create_inode to return error code instead of inode
As Al Viro correctly pointed out, there is no need to return the whole structure to check the error. https://lore.kernel.org/ntfs3/20240322023515.GK538574@ZenIV/ Acked-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
1 parent 1997cdc commit c935c66

File tree

3 files changed

+23
-39
lines changed

3 files changed

+23
-39
lines changed

fs/ntfs3/inode.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,11 +1216,10 @@ ntfs_create_reparse_buffer(struct ntfs_sb_info *sbi, const char *symname,
12161216
*
12171217
* NOTE: if fnd != NULL (ntfs_atomic_open) then @dir is locked
12181218
*/
1219-
struct inode *ntfs_create_inode(struct mnt_idmap *idmap, struct inode *dir,
1220-
struct dentry *dentry,
1221-
const struct cpu_str *uni, umode_t mode,
1222-
dev_t dev, const char *symname, u32 size,
1223-
struct ntfs_fnd *fnd)
1219+
int ntfs_create_inode(struct mnt_idmap *idmap, struct inode *dir,
1220+
struct dentry *dentry, const struct cpu_str *uni,
1221+
umode_t mode, dev_t dev, const char *symname, u32 size,
1222+
struct ntfs_fnd *fnd)
12241223
{
12251224
int err;
12261225
struct super_block *sb = dir->i_sb;
@@ -1245,6 +1244,9 @@ struct inode *ntfs_create_inode(struct mnt_idmap *idmap, struct inode *dir,
12451244
struct REPARSE_DATA_BUFFER *rp = NULL;
12461245
bool rp_inserted = false;
12471246

1247+
/* New file will be resident or non resident. */
1248+
const bool new_file_resident = 1;
1249+
12481250
if (!fnd)
12491251
ni_lock_dir(dir_ni);
12501252

@@ -1484,7 +1486,7 @@ struct inode *ntfs_create_inode(struct mnt_idmap *idmap, struct inode *dir,
14841486
attr->size = cpu_to_le32(SIZEOF_RESIDENT);
14851487
attr->name_off = SIZEOF_RESIDENT_LE;
14861488
attr->res.data_off = SIZEOF_RESIDENT_LE;
1487-
} else if (S_ISREG(mode)) {
1489+
} else if (!new_file_resident && S_ISREG(mode)) {
14881490
/*
14891491
* Regular file. Create empty non resident data attribute.
14901492
*/
@@ -1721,12 +1723,10 @@ struct inode *ntfs_create_inode(struct mnt_idmap *idmap, struct inode *dir,
17211723
if (!fnd)
17221724
ni_unlock(dir_ni);
17231725

1724-
if (err)
1725-
return ERR_PTR(err);
1726-
1727-
unlock_new_inode(inode);
1726+
if (!err)
1727+
unlock_new_inode(inode);
17281728

1729-
return inode;
1729+
return err;
17301730
}
17311731

17321732
int ntfs_link_inode(struct inode *inode, struct dentry *dentry)

fs/ntfs3/namei.c

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,8 @@ static struct dentry *ntfs_lookup(struct inode *dir, struct dentry *dentry,
107107
static int ntfs_create(struct mnt_idmap *idmap, struct inode *dir,
108108
struct dentry *dentry, umode_t mode, bool excl)
109109
{
110-
struct inode *inode;
111-
112-
inode = ntfs_create_inode(idmap, dir, dentry, NULL, S_IFREG | mode, 0,
113-
NULL, 0, NULL);
114-
115-
return IS_ERR(inode) ? PTR_ERR(inode) : 0;
110+
return ntfs_create_inode(idmap, dir, dentry, NULL, S_IFREG | mode, 0,
111+
NULL, 0, NULL);
116112
}
117113

118114
/*
@@ -123,12 +119,8 @@ static int ntfs_create(struct mnt_idmap *idmap, struct inode *dir,
123119
static int ntfs_mknod(struct mnt_idmap *idmap, struct inode *dir,
124120
struct dentry *dentry, umode_t mode, dev_t rdev)
125121
{
126-
struct inode *inode;
127-
128-
inode = ntfs_create_inode(idmap, dir, dentry, NULL, mode, rdev, NULL, 0,
129-
NULL);
130-
131-
return IS_ERR(inode) ? PTR_ERR(inode) : 0;
122+
return ntfs_create_inode(idmap, dir, dentry, NULL, mode, rdev, NULL, 0,
123+
NULL);
132124
}
133125

134126
/*
@@ -200,15 +192,12 @@ static int ntfs_symlink(struct mnt_idmap *idmap, struct inode *dir,
200192
struct dentry *dentry, const char *symname)
201193
{
202194
u32 size = strlen(symname);
203-
struct inode *inode;
204195

205196
if (unlikely(ntfs3_forced_shutdown(dir->i_sb)))
206197
return -EIO;
207198

208-
inode = ntfs_create_inode(idmap, dir, dentry, NULL, S_IFLNK | 0777, 0,
209-
symname, size, NULL);
210-
211-
return IS_ERR(inode) ? PTR_ERR(inode) : 0;
199+
return ntfs_create_inode(idmap, dir, dentry, NULL, S_IFLNK | 0777, 0,
200+
symname, size, NULL);
212201
}
213202

214203
/*
@@ -217,12 +206,8 @@ static int ntfs_symlink(struct mnt_idmap *idmap, struct inode *dir,
217206
static int ntfs_mkdir(struct mnt_idmap *idmap, struct inode *dir,
218207
struct dentry *dentry, umode_t mode)
219208
{
220-
struct inode *inode;
221-
222-
inode = ntfs_create_inode(idmap, dir, dentry, NULL, S_IFDIR | mode, 0,
223-
NULL, 0, NULL);
224-
225-
return IS_ERR(inode) ? PTR_ERR(inode) : 0;
209+
return ntfs_create_inode(idmap, dir, dentry, NULL, S_IFDIR | mode, 0,
210+
NULL, 0, NULL);
226211
}
227212

228213
/*

fs/ntfs3/ntfs_fs.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -714,11 +714,10 @@ int ntfs_sync_inode(struct inode *inode);
714714
int ntfs_flush_inodes(struct super_block *sb, struct inode *i1,
715715
struct inode *i2);
716716
int inode_write_data(struct inode *inode, const void *data, size_t bytes);
717-
struct inode *ntfs_create_inode(struct mnt_idmap *idmap, struct inode *dir,
718-
struct dentry *dentry,
719-
const struct cpu_str *uni, umode_t mode,
720-
dev_t dev, const char *symname, u32 size,
721-
struct ntfs_fnd *fnd);
717+
int ntfs_create_inode(struct mnt_idmap *idmap, struct inode *dir,
718+
struct dentry *dentry, const struct cpu_str *uni,
719+
umode_t mode, dev_t dev, const char *symname, u32 size,
720+
struct ntfs_fnd *fnd);
722721
int ntfs_link_inode(struct inode *inode, struct dentry *dentry);
723722
int ntfs_unlink_inode(struct inode *dir, const struct dentry *dentry);
724723
void ntfs_evict_inode(struct inode *inode);

0 commit comments

Comments
 (0)