[PATCH 3/7] ubifs: do not call ubifs_inode() on unchecked pointer

Sascha Hauer s.hauer at pengutronix.de
Tue Mar 30 11:43:47 BST 2021


new_inode() may return NULL, so only derefence the return inode when
it's non NULL. This is merely a cleanup as calling ubifs_inode() on a
NULL pointer doesn't do any harm, only using the result would.
Nevertheless using inode only after it has been checked for validity
looks much cleaner.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 fs/ubifs/dir.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/ubifs/dir.c b/fs/ubifs/dir.c
index d9d8d7794eff..ba4944c87a2c 100644
--- a/fs/ubifs/dir.c
+++ b/fs/ubifs/dir.c
@@ -82,10 +82,10 @@ struct inode *ubifs_new_inode(struct ubifs_info *c, struct inode *dir,
 	bool encrypted = false;
 
 	inode = new_inode(c->vfs_sb);
-	ui = ubifs_inode(inode);
 	if (!inode)
 		return ERR_PTR(-ENOMEM);
 
+	ui = ubifs_inode(inode);
 	/*
 	 * Set 'S_NOCMTIME' to prevent VFS form updating [mc]time of inodes and
 	 * marking them dirty in file write path (see 'file_update_time()').
-- 
2.29.2




More information about the linux-mtd mailing list