[PATCH] orangefs: move new_inode call to namei

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Before, orangefs_new_inode could return NULL which was not handled.
Instead allocate the inode before calling orangefs_new_inode where the
failure can be handled.

Fix suggested by Dan Carpenter.

Reported-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx>
Signed-off-by: Martin Brandenburg <martin@xxxxxxxxxxxx>
---
 fs/orangefs/inode.c           | 13 ++++---------
 fs/orangefs/namei.c           | 28 +++++++++++++++++++---------
 fs/orangefs/orangefs-kernel.h |  7 ++-----
 3 files changed, 25 insertions(+), 23 deletions(-)

diff --git a/fs/orangefs/inode.c b/fs/orangefs/inode.c
index 6e4d2af8f5bc..82b05707e376 100644
--- a/fs/orangefs/inode.c
+++ b/fs/orangefs/inode.c
@@ -434,11 +434,10 @@ struct inode *orangefs_iget(struct super_block *sb,
 /*
  * Allocate an inode for a newly created file and insert it into the inode hash.
  */
-struct inode *orangefs_new_inode(struct super_block *sb, struct inode *dir,
-		int mode, dev_t dev, struct orangefs_object_kref *ref)
+int orangefs_new_inode(struct inode *inode, struct super_block *sb,
+    struct inode *dir, int mode, dev_t dev, struct orangefs_object_kref *ref)
 {
 	unsigned long hash = orangefs_handle_hash(ref);
-	struct inode *inode;
 	int error;
 
 	gossip_debug(GOSSIP_INODE_DEBUG,
@@ -449,10 +448,6 @@ struct inode *orangefs_new_inode(struct super_block *sb, struct inode *dir,
 		     MINOR(dev),
 		     mode);
 
-	inode = new_inode(sb);
-	if (!inode)
-		return NULL;
-
 	orangefs_set_inode(inode, ref);
 	inode->i_ino = hash;	/* needed for stat etc */
 
@@ -477,9 +472,9 @@ struct inode *orangefs_new_inode(struct super_block *sb, struct inode *dir,
 		     "Initializing ACL's for inode %pU\n",
 		     get_khandle_from_ino(inode));
 	orangefs_init_acl(inode, dir);
-	return inode;
+	return 0;
 
 out_iput:
 	iput(inode);
-	return ERR_PTR(error);
+	return error;
 }
diff --git a/fs/orangefs/namei.c b/fs/orangefs/namei.c
index 625b0580f9be..6fc28036d38f 100644
--- a/fs/orangefs/namei.c
+++ b/fs/orangefs/namei.c
@@ -60,12 +60,16 @@ static int orangefs_create(struct inode *dir,
 	ref = new_op->downcall.resp.create.refn;
 	op_release(new_op);
 
-	inode = orangefs_new_inode(dir->i_sb, dir, S_IFREG | mode, 0, &ref);
-	if (IS_ERR(inode)) {
+
+	inode = new_inode(dir->i_sb);
+	if (!inode)
+		return -ENOMEM;
+	ret = orangefs_new_inode(inode, dir->i_sb, dir, S_IFREG | mode, 0,
+	    &ref);
+	if (ret) {
 		gossip_err("%s: Failed to allocate inode for file :%pd:\n",
 			   __func__,
 			   dentry);
-		ret = PTR_ERR(inode);
 		goto out;
 	}
 
@@ -271,11 +275,14 @@ static int orangefs_symlink(struct inode *dir,
 	ref = new_op->downcall.resp.sym.refn;
 	op_release(new_op);
 
-	inode = orangefs_new_inode(dir->i_sb, dir, S_IFLNK | mode, 0, &ref);
-	if (IS_ERR(inode)) {
+	inode = new_inode(dir->i_sb);
+	if (!inode)
+		return -ENOMEM;
+	ret = orangefs_new_inode(inode, dir->i_sb, dir, S_IFLNK | mode, 0,
+	    &ref);
+	if (ret) {
 		gossip_err
 		    ("*** Failed to allocate orangefs symlink inode\n");
-		ret = PTR_ERR(inode);
 		goto out;
 	}
 	/*
@@ -348,10 +355,13 @@ static int orangefs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode
 	ref = new_op->downcall.resp.mkdir.refn;
 	op_release(new_op);
 
-	inode = orangefs_new_inode(dir->i_sb, dir, S_IFDIR | mode, 0, &ref);
-	if (IS_ERR(inode)) {
+	inode = new_inode(dir->i_sb);
+	if (!inode)
+		return -ENOMEM;
+	ret = orangefs_new_inode(inode, dir->i_sb, dir, S_IFDIR | mode, 0,
+	    &ref);
+	if (ret) {
 		gossip_err("*** Failed to allocate orangefs dir inode\n");
-		ret = PTR_ERR(inode);
 		goto out;
 	}
 
diff --git a/fs/orangefs/orangefs-kernel.h b/fs/orangefs/orangefs-kernel.h
index 17b24ad6b264..69af130f4317 100644
--- a/fs/orangefs/orangefs-kernel.h
+++ b/fs/orangefs/orangefs-kernel.h
@@ -329,11 +329,8 @@ void fsid_key_table_finalize(void);
 /*
  * defined in inode.c
  */
-struct inode *orangefs_new_inode(struct super_block *sb,
-			      struct inode *dir,
-			      int mode,
-			      dev_t dev,
-			      struct orangefs_object_kref *ref);
+int orangefs_new_inode(struct inode *, struct super_block *, struct inode *,
+    int, dev_t, struct orangefs_object_kref *);
 
 int orangefs_setattr(struct dentry *dentry, struct iattr *iattr);
 
-- 
2.19.1




[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux