linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] orangefs: move new_inode call to namei
@ 2018-10-10  2:21 Martin Brandenburg
  2018-10-13  3:24 ` Al Viro
  0 siblings, 1 reply; 2+ messages in thread
From: Martin Brandenburg @ 2018-10-10  2:21 UTC (permalink / raw)
  To: hubcap, devel, linux-fsdevel; +Cc: Martin Brandenburg

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@oracle.com>
Signed-off-by: Martin Brandenburg <martin@omnibond.com>
---
 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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] orangefs: move new_inode call to namei
  2018-10-10  2:21 [PATCH] orangefs: move new_inode call to namei Martin Brandenburg
@ 2018-10-13  3:24 ` Al Viro
  0 siblings, 0 replies; 2+ messages in thread
From: Al Viro @ 2018-10-13  3:24 UTC (permalink / raw)
  To: Martin Brandenburg; +Cc: hubcap, devel, linux-fsdevel

On Wed, Oct 10, 2018 at 02:21:31AM +0000, Martin Brandenburg wrote:
> 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.

Umm...  Perhaps it would be easier to simply return ERR_PTR(-ENOMEM) in
the same situation?

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-10-13 11:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-10  2:21 [PATCH] orangefs: move new_inode call to namei Martin Brandenburg
2018-10-13  3:24 ` Al Viro

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).