Commit c935c668 authored by Konstantin Komarov's avatar Konstantin Komarov

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: default avatarAl Viro <viro@zeniv.linux.org.uk>
Signed-off-by: default avatarKonstantin Komarov <almaz.alexandrovich@paragon-software.com>
parent 1997cdc3
...@@ -1216,11 +1216,10 @@ ntfs_create_reparse_buffer(struct ntfs_sb_info *sbi, const char *symname, ...@@ -1216,11 +1216,10 @@ ntfs_create_reparse_buffer(struct ntfs_sb_info *sbi, const char *symname,
* *
* NOTE: if fnd != NULL (ntfs_atomic_open) then @dir is locked * NOTE: if fnd != NULL (ntfs_atomic_open) then @dir is locked
*/ */
struct inode *ntfs_create_inode(struct mnt_idmap *idmap, struct inode *dir, int ntfs_create_inode(struct mnt_idmap *idmap, struct inode *dir,
struct dentry *dentry, struct dentry *dentry, const struct cpu_str *uni,
const struct cpu_str *uni, umode_t mode, umode_t mode, dev_t dev, const char *symname, u32 size,
dev_t dev, const char *symname, u32 size, struct ntfs_fnd *fnd)
struct ntfs_fnd *fnd)
{ {
int err; int err;
struct super_block *sb = dir->i_sb; struct super_block *sb = dir->i_sb;
...@@ -1245,6 +1244,9 @@ struct inode *ntfs_create_inode(struct mnt_idmap *idmap, struct inode *dir, ...@@ -1245,6 +1244,9 @@ struct inode *ntfs_create_inode(struct mnt_idmap *idmap, struct inode *dir,
struct REPARSE_DATA_BUFFER *rp = NULL; struct REPARSE_DATA_BUFFER *rp = NULL;
bool rp_inserted = false; bool rp_inserted = false;
/* New file will be resident or non resident. */
const bool new_file_resident = 1;
if (!fnd) if (!fnd)
ni_lock_dir(dir_ni); ni_lock_dir(dir_ni);
...@@ -1484,7 +1486,7 @@ struct inode *ntfs_create_inode(struct mnt_idmap *idmap, struct inode *dir, ...@@ -1484,7 +1486,7 @@ struct inode *ntfs_create_inode(struct mnt_idmap *idmap, struct inode *dir,
attr->size = cpu_to_le32(SIZEOF_RESIDENT); attr->size = cpu_to_le32(SIZEOF_RESIDENT);
attr->name_off = SIZEOF_RESIDENT_LE; attr->name_off = SIZEOF_RESIDENT_LE;
attr->res.data_off = SIZEOF_RESIDENT_LE; attr->res.data_off = SIZEOF_RESIDENT_LE;
} else if (S_ISREG(mode)) { } else if (!new_file_resident && S_ISREG(mode)) {
/* /*
* Regular file. Create empty non resident data attribute. * Regular file. Create empty non resident data attribute.
*/ */
...@@ -1721,12 +1723,10 @@ struct inode *ntfs_create_inode(struct mnt_idmap *idmap, struct inode *dir, ...@@ -1721,12 +1723,10 @@ struct inode *ntfs_create_inode(struct mnt_idmap *idmap, struct inode *dir,
if (!fnd) if (!fnd)
ni_unlock(dir_ni); ni_unlock(dir_ni);
if (err) if (!err)
return ERR_PTR(err); unlock_new_inode(inode);
unlock_new_inode(inode);
return inode; return err;
} }
int ntfs_link_inode(struct inode *inode, struct dentry *dentry) int ntfs_link_inode(struct inode *inode, struct dentry *dentry)
......
...@@ -107,12 +107,8 @@ static struct dentry *ntfs_lookup(struct inode *dir, struct dentry *dentry, ...@@ -107,12 +107,8 @@ static struct dentry *ntfs_lookup(struct inode *dir, struct dentry *dentry,
static int ntfs_create(struct mnt_idmap *idmap, struct inode *dir, static int ntfs_create(struct mnt_idmap *idmap, struct inode *dir,
struct dentry *dentry, umode_t mode, bool excl) struct dentry *dentry, umode_t mode, bool excl)
{ {
struct inode *inode; return ntfs_create_inode(idmap, dir, dentry, NULL, S_IFREG | mode, 0,
NULL, 0, NULL);
inode = ntfs_create_inode(idmap, dir, dentry, NULL, S_IFREG | mode, 0,
NULL, 0, NULL);
return IS_ERR(inode) ? PTR_ERR(inode) : 0;
} }
/* /*
...@@ -123,12 +119,8 @@ static int ntfs_create(struct mnt_idmap *idmap, struct inode *dir, ...@@ -123,12 +119,8 @@ static int ntfs_create(struct mnt_idmap *idmap, struct inode *dir,
static int ntfs_mknod(struct mnt_idmap *idmap, struct inode *dir, static int ntfs_mknod(struct mnt_idmap *idmap, struct inode *dir,
struct dentry *dentry, umode_t mode, dev_t rdev) struct dentry *dentry, umode_t mode, dev_t rdev)
{ {
struct inode *inode; return ntfs_create_inode(idmap, dir, dentry, NULL, mode, rdev, NULL, 0,
NULL);
inode = ntfs_create_inode(idmap, dir, dentry, NULL, mode, rdev, NULL, 0,
NULL);
return IS_ERR(inode) ? PTR_ERR(inode) : 0;
} }
/* /*
...@@ -200,15 +192,12 @@ static int ntfs_symlink(struct mnt_idmap *idmap, struct inode *dir, ...@@ -200,15 +192,12 @@ static int ntfs_symlink(struct mnt_idmap *idmap, struct inode *dir,
struct dentry *dentry, const char *symname) struct dentry *dentry, const char *symname)
{ {
u32 size = strlen(symname); u32 size = strlen(symname);
struct inode *inode;
if (unlikely(ntfs3_forced_shutdown(dir->i_sb))) if (unlikely(ntfs3_forced_shutdown(dir->i_sb)))
return -EIO; return -EIO;
inode = ntfs_create_inode(idmap, dir, dentry, NULL, S_IFLNK | 0777, 0, return ntfs_create_inode(idmap, dir, dentry, NULL, S_IFLNK | 0777, 0,
symname, size, NULL); symname, size, NULL);
return IS_ERR(inode) ? PTR_ERR(inode) : 0;
} }
/* /*
...@@ -217,12 +206,8 @@ static int ntfs_symlink(struct mnt_idmap *idmap, struct inode *dir, ...@@ -217,12 +206,8 @@ static int ntfs_symlink(struct mnt_idmap *idmap, struct inode *dir,
static int ntfs_mkdir(struct mnt_idmap *idmap, struct inode *dir, static int ntfs_mkdir(struct mnt_idmap *idmap, struct inode *dir,
struct dentry *dentry, umode_t mode) struct dentry *dentry, umode_t mode)
{ {
struct inode *inode; return ntfs_create_inode(idmap, dir, dentry, NULL, S_IFDIR | mode, 0,
NULL, 0, NULL);
inode = ntfs_create_inode(idmap, dir, dentry, NULL, S_IFDIR | mode, 0,
NULL, 0, NULL);
return IS_ERR(inode) ? PTR_ERR(inode) : 0;
} }
/* /*
......
...@@ -714,11 +714,10 @@ int ntfs_sync_inode(struct inode *inode); ...@@ -714,11 +714,10 @@ int ntfs_sync_inode(struct inode *inode);
int ntfs_flush_inodes(struct super_block *sb, struct inode *i1, int ntfs_flush_inodes(struct super_block *sb, struct inode *i1,
struct inode *i2); struct inode *i2);
int inode_write_data(struct inode *inode, const void *data, size_t bytes); int inode_write_data(struct inode *inode, const void *data, size_t bytes);
struct inode *ntfs_create_inode(struct mnt_idmap *idmap, struct inode *dir, int ntfs_create_inode(struct mnt_idmap *idmap, struct inode *dir,
struct dentry *dentry, struct dentry *dentry, const struct cpu_str *uni,
const struct cpu_str *uni, umode_t mode, umode_t mode, dev_t dev, const char *symname, u32 size,
dev_t dev, const char *symname, u32 size, struct ntfs_fnd *fnd);
struct ntfs_fnd *fnd);
int ntfs_link_inode(struct inode *inode, struct dentry *dentry); int ntfs_link_inode(struct inode *inode, struct dentry *dentry);
int ntfs_unlink_inode(struct inode *dir, const struct dentry *dentry); int ntfs_unlink_inode(struct inode *dir, const struct dentry *dentry);
void ntfs_evict_inode(struct inode *inode); void ntfs_evict_inode(struct inode *inode);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment